<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
+ <script src="lib/ionic/js/angular/ngCookies/cookies.js"></script>
<script src="lib/ui-bootstrap-tpls-0.11.0.js"></script>
+
<!-- rangy : Better detection for textAngular-->
<script src="lib/rangy-1.2.3/rangy-core.js"></script>
<script src="lib/rangy-1.2.3/rangy-selectionsaverestore.js"></script>
<script src="lib/rangy-1.2.3/rangy-cssclassapplier.js"></script>
+
<!-- Rich text editor-->
<script src="lib/textAngular-1.2.2/dist/textAngular-sanitize.min.js"></script>
<script src="lib/textAngular-1.2.2/dist/textAngular.min.js"></script>
+
<!-- html2canvas : create screenshot from DOM element -->
<script src="lib/html2canvas.js"></script>
+
<!-- http-auth-interceptor to automatically detect login required -->
<script src="lib/http-auth-interceptor.js"></script>
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
-angular.module('starter', ['ionic','http-auth-interceptor','starter.controllers'])
+angular.module('starter', ['ionic','http-auth-interceptor','starter.controllers','ngCookies'])
.config(function($httpProvider) {
//Enable cross domain calls
$httpProvider.defaults.useXDomain = true;
$httpProvider.defaults.withCredentials = true;
+ $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
+ $httpProvider.defaults.xsrfCookieName = 'csrftoken';
//Remove the header used to identify ajax call that would prevent CORS from working
delete $httpProvider.defaults.headers.common['X-Requested-With'];
return service;
})
-.factory('AuthenticationService', function($rootScope, $http, authService,remoteService) {
+.factory('AuthenticationService', function($rootScope, $http, authService,remoteService,$cookieStore,$timeout) {
var service = {
login: function(user) {
$http.post('https://'+remoteService.getRemote()+'/auth/login',"username="+encodeURI(user.username)+"&password="+encodeURI(user.password),{headers:{'Content-Type':'application/x-www-form-urlencoded'}})
.success(function (data, status, headers, config) {
// $http.defaults.headers.common.Cookie = data.Set-Cookie; // Step 1
console.log('http://'+remoteService.getRemote()+'/auth/login',"username="+encodeURI(user.username)+"&password="+encodeURI(user.password));
- // Need to inform the http-auth-interceptor that
+ console.log(headers('Set-Cookie'));
+ $timeout(function(){console.log($cookieStore.get('session') )});
+ $timeout(function(){console.log($cookieStore.get('sessionid') )});
+ $timeout(function(){console.log($cookieStore.get('csrftoken') )});
+ // Need to inform the http-auth-interceptor that
// the user has logged in successfully. To do this, we pass in a function that
// will configure the request headers with the authorization token so
// previously failed requests(aka with status == 401) will be resent with the
})
-.factory('DossierSyncService', function($http, $state ,remoteService,authenticationService,databaseService) {
- var currentID;
-
- //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
- var 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;
+.factory('ErrorFormService', function() {
+ var errorCompleteness=[];
+ var service={};
+
+ service.setError=function(errorArray){
+ errorCompleteness=errorArray;
+ };
+
+ service.setError=function(){
+ return errorCompleteness;
};
+
+ return service;
+})
+.factory('DossierSyncService', function($http, $state ,$q,remoteService,AuthenticationService,databaseService) {
+ var currentID;
+
var service = {
- getFile:function(dossierID){
- $http.get("http://"+remoteService.getRemote()+"/"+dossierID).then(function(resp) {
+ getFile:function(dossierID,templateID){
+ var deferred=$q.defer();
+ $http.get("https://"+remoteService.getRemote()+"/template/"+templateID+"/"+dossierID).then(function(resp) {
console.log('Success', resp);
+ deferred.resolve(resp);
// For JSON responses, resp.data contains the result
}, function(err) {
console.error('ERR', err);
// err.status will contain the status code
})
+ return deferred.promise;
},
+ getAllDossierFromTemplate:function(templateID){
+ console.log("hurr");
+ var deferred=$q.defer();
+ $http.get("https://"+remoteService.getRemote()+"/dossier/"+templateID).then(function(resp) {
+ console.log('Success', resp);
+ deferred.resolve(resp);
+ // For JSON responses, resp.data contains the result
+ }, function(err) {
+ console.error('ERR', err);
+ // err.status will contain the status code
+ })
+ return deferred.promise;
+ },
+
saveFile:function(dossierToSave){
var currentDate = new Date();
var dateTime = currentDate.getTime();
}
},
- sendFile:function(templateID,dossierToSend){
- if (checkCompleteness(dossierToSend).bool) {
- $http.post("http://"+remoteService.getRemote()+"/"+templateID,dossierToSend).then(function(resp) {
+ sendFile:function(templateID,dossierToSend,templateJSON){
+ var preparedDossier={};
+
+ console.log("to parse"+templateJSON);
+ var parsed=JSON.parse(templateJSON);
+ preparedDossier.dossier_name="toto";
+ for (var i = 0; i < dossierToSend.length; i++) {
+ preparedDossier[parsed[i].field_name]=dossierToSend[i].value;
+ };
+
+ console.log(preparedDossier);
+
+ $http.post("https://"+remoteService.getRemote()+"/dossier/"+templateID,preparedDossier).then(function(resp) {
console.log('Success', resp);
// For JSON responses, resp.data contains the result
}, function(err) {
// TODO:show a popup saying that there was an error (network, refused, etc
// ...)
})
+ },
+ //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
+ checkCompleteness:function(form){
+ var nbField=form.length;
+ var i;
+ var j;
+ var result={bool:true,where:[]};
+
+ console.log(form);
+ for(i=0;i<nbField;i++){
+ //Common case
+ if(form[i].type!='Radiobox' && form[i].type!='Checkbox'){
+ if(form[i].value==null || form[i].value=="")
+ 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
}
- else{
- //show popup with error error
- }
+ return result;
}
+
+
};
return service;
}
//Get list of template from server
else{
- $http.get("http://"+remoteService.getRemote()+"/template/?alive=true",{withCredentials :"true"}).then(function(resp) {
+ $http.get("https://"+remoteService.getRemote()+"/template/?visible=true",{withCredentials :"true"}).then(function(resp) {
console.log('Success', resp);
fetchedTemplateList=resp.data;
deferred.resolve(resp);
* */
-angular.module('starter.controllers', ['ui.bootstrap','textAngular'])
+angular.module('starter.controllers', ['ui.bootstrap','textAngular','ngCookies'])
.controller('AppCtrl',function($scope,$ionicModal){
$scope.showNext=false;
})
-.controller('BrowseCtrl', function($scope) {
+.controller('BrowseCtrl', function($scope,TemplateSyncService,DossierSyncService,$q) {
$scope.items=[];
+ $scope.template=[];
+
+ var def = TemplateSyncService.fetchTemplateList(false);
+ def.then(function(result){$scope.template=result.data;console.log($scope.template);$scope.getAllDossier();});
+ var allDossierID=[]
+ var allDossierFull=[];
+
+ $scope.getAllDossier=function(){
+ allDossierID=[];
+ allDossierFull=[];
+ console.log("AAAAAAAAAA!");
+ console.log("length"+$scope.template.length);
+
+ for (var i = 0; i < $scope.template.length; i++) {
+ allDossierID.push(DossierSyncService.getAllDossierFromTemplate($scope.template[i].pk));
+ };
+
+ $q.all(allDossierID).then(function(ret){
+ for (var i = 0; i < ret.length; i++) {
+ for (var j = 0; j < ret[i].length; j++) {
+ allDossierFull.push(DossierSyncService.getFile(ret[i][j].pk,i));
+ console.log(ret);
+ };
+ };
+ $q.all(allDossierFull).then(function(ret2){
+ for (var k = 0; k < ret2.length; k++) {
+ allDossierFull[k]=ret2[k];
+ };
+ $scope.showDossier();
+ console.log(ret2);
+ })
+ })
+ };
+
+
+ $scope.showDossier=function(){
+ var col,row=0;
+
+ for (col = 0; col < allDossierFull.length; col++) {
+
+ if(col%4==0){
+ $scope.item.push([]);
+ row++;
+ }
+ $scope.item[row].push(allDossierFull[col]);
+ };
+ };
+
+
+ /*
$scope.items = [[
'The first choice!',
'And another choice for you.',
'but wait! A third!'
],
['hurr','durr','toto','test']];
-
+ */
+
//Convert unix timestamp to date
//return a string of the converted timestamp
function timeConverter(UNIX_timestamp){
};
})
+.controller('ErrorFormCtrl', function($scope,ErrorFormService) {
+ $scope.errors=ErrorFormService.getError();
+})
+
+.controller('SaveCtrl', function($scope,TemplateSyncService,DossierSyncService,remoteService,databaseService,ErrorFormService) {
+
+
+})
-.controller('EditorCtrl', function($scope,$sce,$state,$ionicPopup, $timeout,$ionicModal,$http,inputForm,TemplateSyncService) {
+.controller('EditorCtrl', function($scope,$sce,$state,$ionicPopup, $timeout,$ionicModal,$cookies,$http,inputForm,TemplateSyncService,DossierSyncService,ErrorFormService) {
$scope.currentTemplate=[];
$scope.currentTemplateList=[];
$scope.toParse;
-
+
+
+ // console.log($cookieStore.get('session'));
+ // console.log($cookieStore.get('sessionid'));
+ // console.log($cookieStore.get('csrftoken'));
+ console.log($cookies.sessionid);
+ console.log($cookies.csrftoken);
+ console.log(document.cookie);
+
+ $http.defaults.headers.post['X-CSRFToken']=$cookies['csrftoken'];
+ console.log($cookies['csrftoken']);
+
var def = TemplateSyncService.fetchTemplateList(true);
def.then(function(result){$scope.currentTemplateList=result;$scope.showTemplateChoice();});
//Take a screenshot of the currently displayed dossier
$scope.storeCanvas=function(){
+ var base64;
+
document.querySelector(".view").style.overflow = "visible";
document.querySelector(".has-header.scroll-content.ionic-scroll.has-subheader").style.overflow = "visible";
document.querySelector(".menu-content.pane.disable-user-behavior").style.overflow = "visible";
onrendered: function(canvas) {
var base64 = canvas.toDataURL();
- console.log(base64);
document.querySelector(".view").style.overflow = "hidden";
document.querySelector(".has-header.scroll-content.ionic-scroll.has-subheader").style.overflow = "hidden";
document.querySelector(".menu-content.pane.disable-user-behavior").style.overflow = "hidden";
- }
+
+ }
});
+ return base64;
};
{ type: 'button button-icon icon ion-videocamera',
onTap: function() {
//Cordova/phoneGap camera/video
- $scope.getVideo(refValue)
+ $scope.getVideo(refValue);
return;
}
},
};
$scope.currentTemplate=tmp;
- console.log($scope.currentTemplate);
+ console.log($scope.currentTemplate);
+ };
+
+ $scope.showError=function(refValue){
+ var myPopup = $ionicPopup.show({
+ title: 'Champs non complétés',
+ templateURL:'template/errorForm.html',
+ scope: $scope,
+ buttons: [
+ { type: 'button button-icon icon ion-folder',
+ onTap: function() {
+ //Cordova/phoneGap Files explorer
+ //MIME-type image
+ $scope.getPictureFromDevice(refValue);
+ return ;
+ }
+ },
+ { type: 'button button-icon icon ion-camera',
+ onTap: function() {
+ //Cordova/phoneGap camera
+ $scope.getPicture(refValue);
+ return ;
+ }
+ },
+ ]
+ });
+ };
+
+ $scope.saveAndsend=function(){
+ //save to localDB
+ var result=DossierSyncService.checkCompleteness($scope.currentTemplate);
+ var thumbnail=$scope.storeCanvas();
+ console.log(thumbnail);
+ if(result.bool){
+ DossierSyncService.sendFile(TemplateSyncService.getChoice().pk,$scope.currentTemplate,$scope.toParse);
+ }
+ else{
+ ErrorFormService.setError(result.where);
+ $scope.showError();
+ }
+
+ };
})
--- /dev/null
+{
+ "bitwise": true,
+ "immed": true,
+ "newcap": true,
+ "noarg": true,
+ "noempty": true,
+ "nonew": true,
+ "trailing": true,
+ "maxlen": 100,
+ "boss": true,
+ "eqnull": true,
+ "expr": true,
+ "globalstrict": true,
+ "laxbreak": true,
+ "loopfunc": true,
+ "sub": true,
+ "undef": true,
+ "browser": true,
+ "globals": {
+ "angular": false
+ }
+}
\ No newline at end of file
--- /dev/null
+'use strict';
+
+/**
+ * @ngdoc module
+ * @name ngCookies
+ * @description
+ *
+ * # ngCookies
+ *
+ * The `ngCookies` module provides a convenient wrapper for reading and writing browser cookies.
+ *
+ *
+ * <div doc-module-components="ngCookies"></div>
+ *
+ * See {@link ngCookies.$cookies `$cookies`} and
+ * {@link ngCookies.$cookieStore `$cookieStore`} for usage.
+ */
+
+
+angular.module('ngCookies', ['ng']).
+ /**
+ * @ngdoc service
+ * @name $cookies
+ *
+ * @description
+ * Provides read/write access to browser's cookies.
+ *
+ * Only a simple Object is exposed and by adding or removing properties to/from this object, new
+ * cookies are created/deleted at the end of current $eval.
+ * The object's properties can only be strings.
+ *
+ * Requires the {@link ngCookies `ngCookies`} module to be installed.
+ *
+ * @example
+ *
+ * ```js
+ * function ExampleController($cookies) {
+ * // Retrieving a cookie
+ * var favoriteCookie = $cookies.myFavorite;
+ * // Setting a cookie
+ * $cookies.myFavorite = 'oatmeal';
+ * }
+ * ```
+ */
+ factory('$cookies', ['$rootScope', '$browser', function ($rootScope, $browser) {
+ var cookies = {},
+ lastCookies = {},
+ lastBrowserCookies,
+ runEval = false,
+ copy = angular.copy,
+ isUndefined = angular.isUndefined;
+
+ //creates a poller fn that copies all cookies from the $browser to service & inits the service
+ $browser.addPollFn(function() {
+ var currentCookies = $browser.cookies();
+ if (lastBrowserCookies != currentCookies) { //relies on browser.cookies() impl
+ lastBrowserCookies = currentCookies;
+ copy(currentCookies, lastCookies);
+ copy(currentCookies, cookies);
+ if (runEval) $rootScope.$apply();
+ }
+ })();
+
+ runEval = true;
+
+ //at the end of each eval, push cookies
+ //TODO: this should happen before the "delayed" watches fire, because if some cookies are not
+ // strings or browser refuses to store some cookies, we update the model in the push fn.
+ $rootScope.$watch(push);
+
+ return cookies;
+
+
+ /**
+ * Pushes all the cookies from the service to the browser and verifies if all cookies were
+ * stored.
+ */
+ function push() {
+ var name,
+ value,
+ browserCookies,
+ updated;
+
+ //delete any cookies deleted in $cookies
+ for (name in lastCookies) {
+ if (isUndefined(cookies[name])) {
+ $browser.cookies(name, undefined);
+ }
+ }
+
+ //update all cookies updated in $cookies
+ for(name in cookies) {
+ value = cookies[name];
+ if (!angular.isString(value)) {
+ value = '' + value;
+ cookies[name] = value;
+ }
+ if (value !== lastCookies[name]) {
+ $browser.cookies(name, value);
+ updated = true;
+ }
+ }
+
+ //verify what was actually stored
+ if (updated){
+ updated = false;
+ browserCookies = $browser.cookies();
+
+ for (name in cookies) {
+ if (cookies[name] !== browserCookies[name]) {
+ //delete or reset all cookies that the browser dropped from $cookies
+ if (isUndefined(browserCookies[name])) {
+ delete cookies[name];
+ } else {
+ cookies[name] = browserCookies[name];
+ }
+ updated = true;
+ }
+ }
+ }
+ }
+ }]).
+
+
+ /**
+ * @ngdoc service
+ * @name $cookieStore
+ * @requires $cookies
+ *
+ * @description
+ * Provides a key-value (string-object) storage, that is backed by session cookies.
+ * Objects put or retrieved from this storage are automatically serialized or
+ * deserialized by angular's toJson/fromJson.
+ *
+ * Requires the {@link ngCookies `ngCookies`} module to be installed.
+ *
+ * @example
+ *
+ * ```js
+ * function ExampleController($cookies) {
+ * // Put cookie
+ * $cookieStore.put('myFavorite','oatmeal');
+ * // Get cookie
+ * var favoriteCookie = $cookieStore.get('myFavorite');
+ * // Removing a cookie
+ * $cookieStore.remove('myFavorite');
+ * }
+ * ```
+ */
+ factory('$cookieStore', ['$cookies', function($cookies) {
+
+ return {
+ /**
+ * @ngdoc method
+ * @name $cookieStore#get
+ *
+ * @description
+ * Returns the value of given cookie key
+ *
+ * @param {string} key Id to use for lookup.
+ * @returns {Object} Deserialized cookie value.
+ */
+ get: function(key) {
+ var value = $cookies[key];
+ return value ? angular.fromJson(value) : value;
+ },
+
+ /**
+ * @ngdoc method
+ * @name $cookieStore#put
+ *
+ * @description
+ * Sets a value for given cookie key
+ *
+ * @param {string} key Id for the `value`.
+ * @param {Object} value Value to be stored.
+ */
+ put: function(key, value) {
+ $cookies[key] = angular.toJson(value);
+ },
+
+ /**
+ * @ngdoc method
+ * @name $cookieStore#remove
+ *
+ * @description
+ * Remove given cookie
+ *
+ * @param {string} key Id of the key-value pair to delete.
+ */
+ remove: function(key) {
+ delete $cookies[key];
+ }
+ };
+
+ }]);
-<ion-view>
+<ion-view ng-controller="EditorCtrl">
<ion-header-bar class="bar-subheader has-header">
<div class="nsk-margin-auto">
<text-angular-toolbar name="toolbar" class="nsk-margin-auto"></text-angular-toolbar>
</div>
+ <button class="button" ng-controller="SaveCtrl" ng-click="saveAndsend()">Save</button>
</ion-header-bar>
<ion-content has-header="true" class="has-header">
- <div id="currentFile" class="has-header nsk-thin-centered nsk-box-border nsk-box-shadow" ng-controller="EditorCtrl">
+ <div id="currentFile" class="has-header nsk-thin-centered nsk-box-border nsk-box-shadow">
<button style="width:100%;" type="button" class="btn btn-default"
ng-click="storeCanvas()">Create canvas</button>
--- /dev/null
+<ion-list ng-controller="ErrorFormCtrl">
+ <ion-item ng-repeat="item in errors">
+ <p>item</p>
+ </ion-item>
+</ion-list>