};
- //Check if a template is completely filled
- //Checkbox due to their metaphore are not checked at all
- //Return an object where a boolean is set accordinly to completeness plus an
- //array of the missing field identified by their name
- $scope.checkCompleteness=function(form){
- var nbField=form.length;
- var i;
- var j;
- var result={bool:true,where:[]};
-
- for(i=0;i<nbField;i++){
- //Common case
- if(form[i].type!='Radiobox' && form[i].type!='Checkbox'){
- if(form[i].values==null)
- result.bool=false;
- result.where.push(form[i].name);
- }
- //Special case radiobox
- else if(form[i].type=='RadioBox'){
- var nbChoice=form[i].values.length;
- var valid=false;
- for (var j = 0; j < nbChoice; j++) {
- if(form[i].values[j].checked==true){
- valid=true;
- break;
- }
- }
- if(!valid)
- result.bool=false;
- result.where.push(form[i].name);
- }
- //Checkbox are left unchecked
- }
- return result;
- }
-
$scope.osmURL=function(coord){
var gps1=(coord.split(",")[1]-0.1);
var gps2=(coord.split(",")[0]-0.1 );
$scope.data={ htmlcontent1:'<h2>Try me!</h2><p>textAngular is a super cool WYSIWYG Text Editor directive for AngularJS</p><p><b>Features:</b></p><ol><li>Automatic Seamless Two-Way-Binding</li><li style="color: blue;">Super Easy <b>Theming</b> Options</li><li>Simple Editor Instance Creation</li><li>Safely Parses Html for Custom Toolbar Icons</li><li>Doesn't Use an iFrame</li><li>Works with Firefox, Chrome, and IE8+</li></ol><p><b>Code at GitHub:</b> <a href="https://github.com/fraywing/textAngular">Here</a> </p>',htmlcontent2:'test'}
})
-.controller('TemplateSyncCtrl', function($scope, $http, $state ,remoteService,AuthenticationService) {
- //The full template list, loaded at start-up from the BD and updated by the
- //server.
- //When closing the app, the localDB is updated by this list, ensuring
- //pseudo-persistency when network problem occurs
- $scope.currentTemplateList=[];
-
- //Hold the full (json-added) template list response from the server
- $scope.fetchedFullTemplateList=[];
-
- //Hold ther short template list response from the server
- $scope.fetchedTemplateList;
-
- //Only hold the a template JSON
- $scope.fetchTEmplateJSON;
-
- //Update the specific template in the localDB
- $scope.updateTemplate=function(pk,updatedJSON){
- $scope.localDB.transaction(function(tx) {
- tx.executeSql("UPDATE INTO template SET templateJSON=? where idTemplate=?", [updatedJSON,pk]);
- })
- };
-
- //Add a new template in the localDB
- $scope.createTemplate=function(pk,templateName,templateJSON){
- $scope.localDB.transaction(function(tx) {
- tx.executeSql("INSERT INTO template (idTemplate,templateJSON,templateName) VALUES (?,?,?)", [pk,templateJSON,templateName]);
- })
- };
-
- //Load templates form the localDB into the $scope.currentTemplateList
- $scope.loadTplListFromDB=function(){
- //Clear the previous list
- $scope.currentTemplateList=[];
-
- //Load the template list from the localDB
- $scope.localDB.transaction(function(tx) {
- tx.executeSql("SELECT * FROM template", [],
- function(transaction, result) {
- if (result != null && result.rows != null) {
- for (var i = 0; i < result.rows.length; i++) {
- var row = result.rows.item(i);
- var tpl={name: row.templateName,pk:row.idTemplate,json:row.templateJSON}
- $scope.currentTemplateList.push(tpl);
- }
- }
- },errorHandler)
- })
- };
-
- //Update the localDB from the $scope.currentTemplateList
- //Try to limit write on the localBD by checking the state of the current row
- //TODO: May be better performance-wise to just drop the whole table instead
- $scope.updateTplListToDB=function(){
- var i;
- var j;
- var currentListLength=$scope.currentTemplateList.length;
- var DBListlength;
- var tplListDB=[];
-
- //Load the template list from the localDB
- $scope.localDB.transaction(function(tx) {
- tx.executeSql("SELECT * FROM template", [],
- function(transaction, result) {
- if (result != null && result.rows != null) {
- DBListLength=result.rows.lenght;
- for (var i = 0; i < DBListlength; i++) {
- var row = result.rows.item(i);
- var tpl={name: row.templateName,pk:row.idTemplate,json:row.templateJSON}
- tplListDB.push(tpl);
- }
- }
- },errorHandler)
- });
-
- //Compare the current template list with the one store in the database and
- //update or create rows accordingly
- for(i=0;i<listLength;i++){
- for(j=0;j<currentTplListLenght;j++){
-
- if($scope.currentTemplateList[index].pk=tplListDB[j].pk){
- updateTemplate(pk);
- }
- else{
- createTemplate(pk);
- }
- }
- }
- };
-
- //refreshed the main list using data fetched from the server
- $scope.refreshTplList=function(){
- //Clear the previous list
- $scope.currentTemplateList=[];
-
- var i;
- var listLength=templateAlive.length;
-
- for(i=0;i<listLength;i++){
- $scopeCurrentList.push($scope.fetchedFullTemplateList[i]);
- }
- };
-
- //API call to get alive template list
- $scope.fetchTemplateList=function(full){
- //Get list of full template from server
- if(full){
- $http.get("https://"+remoteService.getRemote()+"/template/?alive=true&json=true",{withCredentials :"true"}).then(function(resp) {
- console.log('Success', resp);
- $scope.fetchedFullTemplateList=resp.data;
- });
- }
- //Get list of template from server
- else{
- $http.get("http://"+remoteService.getRemote()+"/template/?alive=true",{withCredentials :"true"}).then(function(resp) {
- console.log('Success', resp);
- $scope.fetchedTemplateList=resp.data;
- });
- }
- };
-
- //API : Fetch a specific template
- $scope.fetchTemplate=function(templateID){
- $http.get("http://"+remoteService.getRemote()+"/template/"+templateID,{withCredentials :"true"}).then(function(resp) {
- console.log('Success', resp);
- $scope.fetchedTemplateJSON=resp.data;
- }
- ,function(err) {
- console.error('ERR', err);
- })
- };
-
-})
.controller('LoginCtrl', function($scope, $http, $state ,AuthenticationService,remoteService,$ionicSideMenuDelegate) {
$scope.message = "";
})
-.controller('DossierSyncCtrl', function($scope, $http, $state ,remoteService,authenticationService) {
-
- $scope.getFile=function(dossierID){
- $http.get("http://"+remoteService.getRemote()+"/"+dossierID).then(function(resp) {
- console.log('Success', resp);
- // For JSON responses, resp.data contains the result
- }, function(err) {
- console.error('ERR', err);
- // err.status will contain the status code
- })
- };
-
- $scope.saveFile=function(){
- var currentDate = new Date();
- var dateTime = currentDate.getTime();
-
- if($scope.isNew){
- $scope.localDB.transaction(function(tx) {
- tx.executeSql("INSERT INTO dossier (dossierJSON, timestamp) VALUES (?,?)", [$scope.currentTemplate,dateTime]);
- })
- }
- else{
- $scope.localDB.transaction(function(tx) {
- tx.executeSql("UPDATE dossier SET dossierJSON=?, timestamp=? WHERE idDossier=?", [$scope.currentTemplate,dateTime,$scope.currentID]);
- })
- }
- };
-
- $scope.sendFile=function(templateID){
- if ($scope.checkCompleteness($scope.currentTemplate).bool) {
- $http.post("http://"+remoteService.getRemote()+"/"+templateID,$scope.currentTemplate).then(function(resp) {
- console.log('Success', resp);
- // For JSON responses, resp.data contains the result
- }, function(err) {
- console.error('ERR', err);
- // err.status will contain the status code
- // TODO:show a popup saying that there was an error (network, refused, etc
- // ...)
- })
- }
- else{
- //show popup with error error
- }
- };
-
-
-})