· 5 years ago · May 11, 2020, 01:22 PM
1angular.module('form', ['user', 'ngRoute', 'apiform', 'color.picker'])
2 .factory('FormService', function (UserService, $rootScope, ApiFormService) {
3 var user = {};
4 if ($rootScope.userContext) {
5 user = UserService.getUser();
6 }
7 var userForms = [];
8
9 var sessionFormVersionsIndex = null;
10 var sessionFormVersions = [];
11
12 return {
13
14 // FORM
15
16 /**
17 * Get user saved forms
18 * @param {string} idWebsite
19 * @return {JSON}
20 */
21 getPreviewUrl: function (idForm) {
22 return ApiFormService.getPreviewUrl(idForm);
23 },
24
25 getUserForms: function (idWebsite) {
26 userForms = [];
27
28 //API request to get user forms
29 var forms = ApiFormService.getUserForms();
30
31 angular.forEach(forms, function (form, index) {
32 var json = JSON.parse(form.json);
33 json.status = form.status;
34 json.version = form.version;
35 json.inputDataMapping = user.inputDataMapping;
36 if (user.override) {
37 json.status = 'inactive';
38 }
39 if (!json.hasOwnProperty('headerTitle')) {
40 json['headerTitle'] = '';
41 }
42
43 if (!json.hasOwnProperty('blockRightClient')) {
44 json['blockRightClient'] = '';
45 }
46
47 if (!json.hasOwnProperty('orderStarsText')) {
48 json['orderStarsText'] = $rootScope.orderStarText;
49 }
50
51 if (!json.hasOwnProperty('productToggleLabel')) {
52 json['productToggleLabel'] = '';
53 }
54
55 if (!json.hasOwnProperty('productStarsText')) {
56 json['productStarsText'] = $rootScope.productStarText;
57 }
58
59 if (!json.hasOwnProperty('onlyProduct')) {
60 json['onlyProduct'] = false;
61 }
62
63 if (!json.hasOwnProperty('productToggleLabel')) {
64 json['productToggleLabel'] = '';
65 }
66
67 userForms.push(json);
68 });
69
70
71 return userForms;
72 },
73
74 /**
75 * Create a model of a new form
76 * @return {JSON}
77 */
78 createForm: function () {
79
80 return {
81 'id': 'new',
82 'name': '',
83 'version': 1,
84 'status': 'draft',
85 'enableProductsReview': true,
86 'enableUpload':
87 {
88 'order': true,
89 'product': true
90 },
91 'noFbShare': false,
92 'orderStarsText': $rootScope.orderStarText,
93 'productStarsText': $rootScope.productStarText,
94 'productToggleLabel': '',
95 'logoNetReviews': '',
96 'headerTitle': '',
97 'blockRightClient': '',
98 'onlyProduct': '0',
99 'productNotTested': false,
100 'backgroundImage': '',
101 'averageRateOrder': false,
102 'averageRateProduct': false,
103 'blockExplicationTitle': $rootScope.blockExplicationTitle,
104 'blockExplicationText': $rootScope.blockExplicationText,
105 'blockRightAvis': $rootScope.blockRightAvis,
106 'blockRightBoth': $rootScope.blockRightBoth,
107 'blockRightOnlyProduct': $rootScope.blockRightOnlyProduct,
108 'blockRightOnlyWeb': $rootScope.blockRightOnlyWeb,
109 'blockRightEnd': $rootScope.blockRightEnd,
110 'blockRightfoortitle': $rootScope.blockRightfoortitle,
111 'blockRightAvisTitle': '',
112 'blockAvisInfo': false,
113 'blockinfoAvisVerifies': false,
114 'blockevaluationsite': false,
115 'blockWhere': true,
116 'hidelogo': false,
117 'blocksethelpmessageproduit': false,
118 'relance': null,
119 'sethelpmessageproduit': '',
120 'hasCondition': false,
121 'denomination': user.denomination,
122 'fieldsAverage': {
123 'order': {},
124 'product': {},
125 },
126 'sections': [
127 {
128 'id': 'section1',
129 'label': $rootScope.labelOrderSection,
130 'order': 1,
131 'type': 'order',
132 'enableProductsReview': true,
133 'rights': [
134 'edit'
135 ],
136 'groups': [
137 {
138 'id': 'group1',
139 'type': 'order',
140 'order': 1,
141 'required': true,
142 'sectionId': 'section1',
143 'rights': [
144 'edit'
145 ],
146 'fields': [
147 {
148 'order': 1,
149 'id': 'RATE',
150 'label': $rootScope.labelOrderRate + ' ' + user.website + ' ?',
151 'eav': '#RATE=I1',
152 'button': 'star',
153 'buttonSize': '35',
154 'maxRate': '5',
155 'type': 'rate',
156 'rights': [
157 'edit'
158 ],
159 'groupId': 'group1',
160 'sectionId': 'section1'
161 },
162 {
163 'order': 2,
164 'id': 'REVIEW',
165 'label': $rootScope.labelOrderReview,
166 'eav': '#REVIEW=S',
167 'minChar': 3,
168 'maxChar': 2500,
169 'placeholder': $rootScope.placeholderOrderReview,
170 'type': 'textarea',
171 'rights': [
172 'edit',
173 'delete'
174 ],
175 'groupId': 'group1',
176 'sectionId': 'section1'
177 }
178 ]
179 },
180 ]
181 },
182 {
183 'id': 'sectionProduct',
184 'idCss': 'sectionProduct',
185 'label': $rootScope.labelProductSection,
186 'order': 2,
187 'type': 'product',
188 'classCss': '',
189 'styleCss': '',
190 'nbMaxProduct': 4,
191 'rights': [
192 'edit',
193 'delete'
194 ],
195 'groups': [
196 {
197 'id': 'groupProduct',
198 'idCss': 'groupProduct',
199 'type': 'product',
200 'order': 1,
201 'required': true,
202 'sectionId': 'section1',
203 'classCss': '',
204 'styleCss': '',
205 'rights': [
206 'edit'
207 ],
208 'fields': [
209 {
210 'order': 1,
211 'id': 'productRate',
212 'idCss': 'productRate',
213 'label': labelProductRate,
214 'eav': '!#RATE=I1',
215 'button': 'star',
216 'buttonSize': '35',
217 'maxRate': '5',
218 'type': 'rate',
219 'rights': [
220 'edit'
221 ],
222 'groupId': 'groupProduct',
223 'sectionId': 'sectionProduct',
224 'multilabelling': [
225 {'label':"ecris moi correctement %s",
226 'term':"term0",
227 'replaceString':{
228 'label':[
229 {'type':"product",
230 'label':"Name shop",
231 'id':"?#name_shop=G",
232 'order':1
233 }
234 ],
235 'placeholder':[]
236 }
237 }
238
239 ]
240 },
241 {
242 'order': 2,
243 'id': 'PRODUCTREVIEW',
244 'idCss': 'productReview',
245 'label': $rootScope.labelProductReview,
246 'eav': '!#REVIEW=S',
247 'minChar': 3,
248 'maxChar': 2500,
249 'placeholder': $rootScope.placeholderProductReview,
250 'type': 'textarea',
251 'rights': [
252 'edit',
253 'delete'
254 ],
255 'groupId': 'groupProduct',
256 'sectionId': 'sectionProduct',
257 'multilabelling': [
258 {'label':"dis moi correctement %s",
259 'term':"term1",
260 'replaceString':{
261 'label':[
262 {'type':"product",
263 'label':"CYRILTEST",
264 'id':"?!#CYRILTEST=I1",
265 'order':1
266 }
267 ],
268 'placeholder':[]
269 }
270 },
271 {'label':"multilabel de merde i did it ^^ %s",
272 'term':"term2",
273 'replaceString':{
274 'label':[
275 {'type':"product",
276 'label':"Canal",
277 'id':"?#canal=G",
278 'order':1
279 }
280 ],
281 'placeholder':[]
282 }
283 }
284
285
286 ]
287 }
288 ]
289 }
290 ]
291 },
292 ],
293 'orderMapping': [],
294 'productMapping': [],
295 'terms': [],
296 'behaviours': [],
297 'labels': [
298 {
299 'label': 'Note de la commande',
300 'eav': '#RATE=I1',
301 'destination': 'order'
302 },
303 {
304 'label': 'Commentaire de la commande',
305 'eav': '#REVIEW=S',
306 'destination': 'order'
307 },
308 {
309 'label': 'Note du produit',
310 'eav': '!#RATE=I1',
311 'destination': 'product'
312 }, {
313 'label': 'Commentaire du produit',
314 'eav': '!#REVIEW=S',
315 'destination': 'product'
316 }
317 ],
318 'inputDataMapping': user.inputDataMapping
319
320
321 };
322
323 },
324
325 /**
326 * Generate a form default style
327 * @return {JSON}
328 */
329 generateDefaultStyle: function () {
330 return {
331 'background': null,
332 'header': {
333 'color': null
334 },
335 'cgv': {
336 'color': null,
337 'link': {
338 'color': null
339 }
340 },
341 'submit': {
342 'background': null,
343 'color': null
344 },
345 'sections': {
346 'background': null,
347 'color': null,
348 'title': {
349 'number': {
350 'color': null,
351 'background': null
352 },
353 'color': null,
354 'background': null
355 }
356 },
357 'stars': {
358 'full': {
359 'color': null
360 },
361 'empty': {
362 'color': null
363 },
364 'tooltip': {
365 'color': null
366 },
367 },
368 'right': {
369 'title': {
370 'color': null
371 },
372 'color': null,
373 'background': null
374 }
375 };
376 },
377
378
379 /**
380 * Get a form by it id
381 * @param {string} id
382 * @return {JSON}
383 */
384 getFormById: function (id) {
385 var result = false;
386 sessionFormVersions = [];
387 angular.forEach(userForms, function (form, key) {
388 if (form.id == id) {
389 result = form;
390 }
391 });
392 sessionFormVersions.push(result);
393 return result;
394 },
395
396 /**
397 * Delete the form founded by it id
398 * @param {string} id [description]
399 * @return void
400 */
401 deleteFormById: function (id) {
402 angular.forEach(userForms, function (form, key) {
403 if (form.id == id) {
404 //console.log(ApiFormService.deleteForm(form));
405 ApiFormService.deleteForm(form);
406 userForms.splice(key, 1);
407 }
408 });
409 },
410
411 //SECTION
412 /**
413 * Create a model of a new section
414 * @return {JSON}
415 */
416 createSection: function () {
417 return {
418 'id': 'section',
419 'label': 'Section',
420 'order': 1,
421 'type': 'order',
422 'rights': [
423 'edit',
424 'delete'
425 ],
426 'groups': []
427 };
428 },
429
430 /**
431 * Create a model of a new product section
432 * @return {JSON}
433 */
434 createProductSection: function () {
435 return {
436 'id': 'sectionProduct',
437 'idCss': 'sectionProduct',
438 'label': $rootScope.labelProductSection,
439 'order': 0,
440 'type': 'product',
441 'classCss': '',
442 'styleCss': '',
443 'nbMaxProduct': 4,
444 'rights': [
445 'edit',
446 'delete'
447 ],
448 'groups': [
449 {
450 'id': 'groupProduct',
451 'idCss': 'groupProduct',
452 'type': 'product',
453 'order': 1,
454 'required': true,
455 'sectionId': 'section1',
456 'classCss': '',
457 'styleCss': '',
458 'rights': [
459 'edit'
460 ],
461 'fields': [
462 {
463 'order': 1,
464 'id': 'productRate',
465 'idCss': 'productRate',
466 'label': $rootScope.labelProductRate,
467 'eav': '!#RATE=I1',
468 'button': 'star',
469 'buttonSize': '35',
470 'maxRate': '5',
471 'type': 'rate',
472 'rights': [
473 'edit'
474 ],
475 'groupId': 'groupProduct',
476 'sectionId': 'sectionProduct'
477 },
478 {
479 'order': 2,
480 'id': 'productReview',
481 'idCss': 'productReview',
482 'label': $rootScope.labelProductReview,
483 'eav': '!#REVIEW=S',
484 'minChar': 3,
485 'maxChar': 2500,
486 'placeholder': $rootScope.placeholderProductReview,
487 'type': 'textarea',
488 'rights': [
489 'edit',
490 'delete'
491 ],
492 'groupId': 'groupProduct',
493 'sectionId': 'sectionProduct'
494 }
495 ]
496 }
497 ]
498 };
499 },
500
501 //GROUP
502 /**
503 * Create a model of a new group
504 * @return {JSON}
505 */
506 createGroup: function () {
507 return {
508 'id': 'group',
509 'type': 'order',
510 'order': 1,
511 'required': true,
512 'sectionId': '',
513 'rights': [
514 'edit',
515 'delete',
516 'required'
517 ],
518 'fields': []
519 };
520 },
521
522 //FIELD
523 /**
524 * Create a model of a new field
525 * @return {JSON}
526 */
527 createField: function () {
528 return {
529 'order': 0,
530 'id': 'field',
531 'idCss': '',
532 'label': '',
533 'type': '',
534 'maxChoices': '0',
535 'minChoices': '0',
536 'sectionId': '',
537 'groupId': '',
538 'rights': [
539 'edit',
540 'edit_id',
541 'delete'
542 ]
543 };
544 },
545
546 /**
547 * Create a model of a new form
548 * @param {JSON}
549 */
550 addForms: function (form) {
551 var id = ApiFormService.createForm();
552 form.id = id;
553 userForms.push(form);
554 ApiFormService.updateForm(form);
555
556 return id;
557 },
558
559 /**
560 * Add conditions to a form
561 *@param {idForm}
562 *@param {conditions} array of conditions to add
563 */
564 addConditionsToForm: function (idForm, conditions) {
565 ApiFormService.addConditionsToForm(idForm, conditions);
566 },
567
568 /**
569 * Update a form
570 * @param {JSON}
571 */
572 setForm: function (formEdited) {
573 //If form was reverted and history has post versions
574 if (sessionFormVersionsIndex !== null && (sessionFormVersionsIndex + 1) < sessionFormVersions.length) {
575 var indexesToDelete = [];
576 sessionFormVersions.splice(sessionFormVersionsIndex + 1);
577 sessionFormVersionsIndex = null;
578 }
579
580 //If nb versions reach 10, delete the first one
581 if (sessionFormVersions.length == 10) {
582 sessionFormVersions.shift();
583 //Re-init indexes
584 sessionFormVersions.filter(function () {
585 return true;
586 });
587 }
588 sessionFormVersions.push(angular.copy(formEdited));
589
590 angular.forEach(userForms, function (form, key) {
591 if (form.id == formEdited.id) {
592 userForms[key] = formEdited;
593 }
594 });
595
596 //Save in database
597 ApiFormService.updateForm(formEdited);
598 },
599
600 getSessionFormVersionsLength: function () {
601 return sessionFormVersions.length;
602 },
603
604 getSessionFormVersionIndex: function () {
605 return sessionFormVersionsIndex;
606 },
607
608
609 getFormVersion: function (index) {
610 sessionFormVersionsIndex = index;
611 angular.forEach(userForms, function (form, index) {
612 if (sessionFormVersions[index].id == form.id) {
613 userForms[index] = angular.copy(sessionFormVersions[index]);
614 }
615 });
616 return angular.copy(sessionFormVersions[index]);
617 },
618 }
619 })
620
621
622 .controller('formCtrl', ['$scope', 'UserService', 'FormService', '$location',
623 function ($scope, UserService, FormService, $location) {
624
625 $scope.init = function (id = null) {
626 if (id == null)
627 var form = FormService.createForm();
628 else
629 var form = FormService.getFormById(id);
630
631 if (form.style == void (0)) {
632 form.style = FormService.generateDefaultStyle()
633 }
634
635
636 $scope.form = form;
637 $scope.formCondition = [];
638 $scope.deleteCondition = 0;
639 if ($scope.user === undefined) {
640 UserService.setUser();
641 $scope.user = UserService.getUser();
642 }
643
644 for (var i = 0; i < $scope.user['conditionedData'].length; i++) {
645 $scope.formCondition.push({});
646 $scope.deleteCondition++;
647 }
648
649
650
651 };
652
653 $scope.createForm = function (condition) {
654 //API request to save the form
655
656 //Check if new form is the only one new
657 if (FormService.getFormById($scope.form.id)) {
658 FormService.deleteFormById($scope.form.id);
659 }
660 if (condition == true && $scope.formCondition.length > 0)
661 $scope.form.hasCondition = true;
662 var formId = FormService.addForms(angular.copy($scope.form));
663
664 // save condition
665 if (condition == true && $scope.formCondition.length > 0) {
666 FormService.addConditionsToForm(formId, $scope.formCondition);
667 }
668
669 $("#addForm").modal('hide');
670 $('body').removeClass('modal-open');
671 $('.modal-backdrop').remove();
672 $location.path('/form/' + formId);
673 };
674
675
676 $scope.createFormFromOther = function (condition) {
677 //we get the last version of the form
678 var formToBe = FormService.getFormById($scope.form.id);
679 var newForm = angular.copy(formToBe);
680 newForm.status = 'draft';
681 newForm.name = $scope.form.otherFormName;
682 newForm.version = 1;
683 if (condition == true && $scope.formCondition.length > 0)
684 newForm.hasCondition = true;
685 else
686 newForm.hasCondition = false;
687 var formId = FormService.addForms(newForm);
688 // save condition
689 if (condition == true && $scope.formCondition.length > 0)
690 FormService.addConditionsToForm(formId, $scope.formCondition);
691
692 $("#addForm").modal('hide');
693 $('body').removeClass('modal-open');
694 $('.modal-backdrop').remove();
695 $location.path('/form/' + formId);
696 };
697
698 $scope.deleteForm = function (id) {
699 FormService.deleteFormById(id);
700 $("#deleteForm").modal('hide');
701 };
702
703
704 $scope.verificationFormCondition = function () {
705 var check = true;
706 $scope.formCondition.forEach(function (row) {
707 if (row.data == undefined) check = false;
708 if (row.type == undefined) check = false;
709 if (row.value == undefined) check = false;
710 });
711 return check;
712 };
713
714 }
715
716 ])
717
718 .controller('formEditCtrl', ['$scope', 'UserService', 'FormService', '$location', '$routeParams', 'ApiFormService', '$window', '$sce',
719 function ($scope, UserService, FormService, $location, $routeParams, ApiFormService, $window, $sce, flash) {
720
721 $scope.form = angular.copy(FormService.getFormById($routeParams.formId));
722
723 if ($scope.form.style == void (0)) {
724 $scope.form.style = FormService.generateDefaultStyle();
725 }
726
727 $scope.previewUrl = $sce.trustAsResourceUrl(FormService.getPreviewUrl($routeParams.formId));
728 $scope.defaultExist = ApiFormService.defaultFormExist();
729 $scope.formCondition = ApiFormService.getConditionsByIdForm($scope.form.id);
730
731 //console.log($scope.formCondition) ;
732
733
734 $scope.setPreviewValues = function () {
735 var request = $scope.getRequestPreview();
736 var url = ApiFormService.getPreviewUrl($routeParams.formId);
737 var urlTab = url.split('=');
738 var idVente = urlTab[1].split('&formId');
739 request.push(idVente[0]);
740 ApiFormService.setPreviewValues(request);
741 $scope.save();
742 }
743
744 $scope.getRequestPreview = function (type) {
745 var request = [];
746 var order = [];
747 var product = [];
748
749 $scope.form.inputDataMapping['order'].forEach(function (eav) {
750 if (eav.previewValue) {
751 var string = encodeURI(eav.eav) + ':_:_:' + encodeURI(eav.previewValue);
752 order.push(string);
753 }
754 });
755
756 request.push(order);
757
758 $scope.form.inputDataMapping['product'].forEach(function (eav) {
759 if (eav.previewValue) {
760 var string = encodeURI(eav.eav) + ':_:_:' + encodeURI(eav.previewValue);
761 product.push(string);
762 }
763 });
764
765 request.push(product);
766
767 return request;
768 }
769
770 $scope.download = {
771 'name': ''
772 };
773
774 $scope.errors = {
775 'form': {},
776 'downloadName': ''
777 };
778
779 $scope.status = {
780 'action': ''
781 };
782
783 $scope.colorPickerOptions = {
784 allowEmpty: true,
785 format: 'hex',
786 hue: true,
787 dynamicHue: true,
788 clear: {
789 show: true,
790 label: 'Clear',
791 class: '',
792 },
793 reset: {
794 show: true,
795 label: 'Reset',
796 class: '',
797 },
798 }
799
800 $scope.cleanEAV = function (eav) {
801 eav = eav.replace('!', '');
802 eav = eav.replace('#', '');
803 eav = eav.replace('?', '');
804 eav = eav.replace(eav.substr(eav.indexOf('=')), '');
805 return eav;
806 }
807
808 $scope.broadcastBehaviorModal = function () {
809 $scope.$broadcast('initBehavior');
810 };
811
812 $scope.broadcastCategoryModal = function () {
813 $scope.$broadcast('initCategory');
814 };
815
816 $scope.editForm = function () {
817 $scope.errors.form = {};
818 if ($scope.form.name.length > 0) {
819 FormService.setForm($scope.form);
820 $("#editForm").modal('hide');
821 } else {
822 $scope.errors.form.name = "Form name is mandatory.";
823 }
824 };
825
826 $scope.editFormColors = function () {
827 FormService.setForm($scope.form);
828 $("#editFormColors").modal('hide');
829 };
830
831 $scope.hasPreviousVersion = false;
832 $scope.$on('addVersion', function () {
833 if (!$scope.hasPreviousVersion) {
834 $scope.hasPreviousVersion = true;
835 }
836 });
837
838 $scope.hasNextVersion = false;
839
840 $scope.copyUrl = function () {
841 const el = document.createElement('textarea');
842 el.value = $scope.previewUrl;
843 document.body.appendChild(el);
844 el.select();
845 document.execCommand('copy');
846 document.body.removeChild(el);
847 }
848
849
850 $scope.getPreviousVersion = function () {
851 var index = FormService.getSessionFormVersionIndex();
852 if (index === null) {
853 index = FormService.getSessionFormVersionsLength() - 1;
854 }
855 $scope.form = FormService.getFormVersion(index - 1);
856
857 if ((index - 1) == 0) {
858 $scope.hasPreviousVersion = false;
859 }
860
861 $scope.hasNextVersion = true;
862 $scope.save();
863 };
864
865 $scope.getNextVersion = function () {
866 var index = FormService.getSessionFormVersionIndex() + 1;
867 $scope.form = FormService.getFormVersion(index);
868
869 if ((index + 1) == FormService.getSessionFormVersionsLength()) {
870 $scope.hasNextVersion = false;
871 }
872
873 $scope.hasPreviousVersion = true;
874 $scope.save();
875 };
876
877 $scope.downloadForm = function () {
878 $scope.errors.downloadName = "";
879 if ($scope.download.name.length == 0) {
880 $scope.errors.downloadName = "Client file name is mandatory.";
881 } else {
882 var result = ApiFormService.getDownloadUrl($scope.form.id, $scope.download.name);
883 $window.open(result.download, '_blank');
884 $("#downloadForm").modal('hide');
885 }
886 };
887
888 $scope.save = function () {
889 FormService.setForm($scope.form);
890 };
891
892 $scope.activateForm = function () {
893 $scope.form.status = "active";
894 $scope.save();
895 $scope.status.action = '';
896 $("#statusForm").modal('hide');
897 };
898
899 $scope.deactivateForm = function () {
900 $scope.form.status = "inactive";
901 $scope.save();
902 $scope.status.action = '';
903 $("#statusForm").modal('hide');
904 };
905
906 $scope.updateBackGroundImage = function () {
907
908 var formId = $scope.form.id;
909
910
911 var fd = new FormData();
912 var files = document.getElementById('bgfile').files[0];
913 fd.append('file', files);
914 var data = ApiFormService.uploadImage(fd, formId);
915 if (data.error == "") {
916 $scope.form.backgroundImage = data.url;
917 $('#errorUploadImage').remove();
918 } else {
919 $('#bgfile').after("<p id='errorUploadImage'><br/>" + data.error + "</p>");
920 }
921 };
922
923 $scope.deleteBackGroundImage = function () {
924
925 $scope.form.backgroundImage = "";
926 // $('#previewBackgroundImage').remove();
927 };
928
929 $scope.duplicateForm = function () {
930 var newForm = angular.copy($scope.form);
931 newForm.status = 'draft';
932 newForm.name = newForm.name + " (copy)";
933 newForm.version = parseInt(newForm.version) + 1;
934 var formId = FormService.addForms(newForm);
935 ApiFormService.duplicateCondition(formId, $scope.form.id);
936 $("#addForm").modal('hide');
937 $('body').removeClass('modal-open');
938 $('.modal-backdrop').remove();
939 $location.path('/form/' + formId);
940 };
941
942 $scope.getAllFieldsAverage = function (type = 'product') {
943
944 if ($scope.fieldsAverage == undefined)
945 $scope.fieldsAverage = [];
946
947 $scope.fieldsAverage[type] = [];
948
949 if (type == 'order') {
950 var idRate = "RATE";
951 var idSection = "section1";
952 var idGroup = "group1";
953
954
955 } else {
956 var idRate = "productRate";
957 var idSection = "sectionProduct";
958 var idGroup = "groupProduct";
959 }
960
961 angular.forEach($scope.form.sections, function (section) {
962 if (section.id == idSection) {
963 angular.forEach(section.groups, function (group) {
964 if (idGroup == group.id) {
965 angular.forEach(group.fields, function (field) {
966 if (field.type == "rate" && field.id != idRate) {
967 $scope.fieldsAverage[type].push(field);
968 }
969 });
970 }
971 });
972 }
973 });
974 }
975
976 $scope.createAverageOrder = function () {
977 //we check if at least two rate fields have been selected and construct the json object
978 if ($scope.checkNoteFieldSelection('order')) {
979 $scope.form.averageRateOrder = true;
980 FormService.setForm($scope.form);
981 $("#averageRateOrder").modal('hide');
982 } else {
983 document.getElementById('errorAverageRateOrder').innerHTML = "<center> <span class='glyphicon glyphicon-warning-sign'></span> You should select at least two rate fields</center>";
984 setTimeout(function () {
985 document.getElementById('errorAverageRateOrder').innerHTML = "";
986 }, 3000);
987 }
988 }
989
990 $scope.createAverageProduct = function () {
991 //we check if at least two rate fields have been selected and construct the json object
992 if ($scope.checkNoteFieldSelection('product')) {
993 $scope.form.averageRateProduct = true;
994 FormService.setForm($scope.form);
995 $("#averageRateProduct").modal('hide');
996 } else {
997 document.getElementById('errorAverageRateProduct').innerHTML = "<center> <span class='glyphicon glyphicon-warning-sign'></span> You should select at least two rate fields</center>";
998 setTimeout(function () {
999 document.getElementById('errorAverageRateProduct').innerHTML = "";
1000 }, 3000);
1001 }
1002 }
1003
1004 $scope.checkNoteFieldSelection = function (type) {
1005 var jsonFieldsAverage = [];
1006 for (element in $scope.form.fieldsAverage[type]) {
1007 if ($scope.form.fieldsAverage[type][element] == true)
1008 jsonFieldsAverage.push(element);
1009 }
1010 if (jsonFieldsAverage.length >= 2) {
1011 $scope.form.fieldsAverage[type] = jsonFieldsAverage;
1012 return true;
1013 } else return false;
1014 }
1015
1016 $scope.destroyAverageOrder = function () {
1017 if (window.confirm('Are sure you want to delete the rate order average?')) {
1018 $scope.form.averageRateOrder = false;
1019 $scope.form.fieldsAverage['order'] = {};
1020 FormService.setForm($scope.form);
1021 $("#averageRateOrder").modal('hide');
1022 }
1023 }
1024
1025 $scope.destroyAverageProduct = function () {
1026 if (window.confirm('Are sure you want to delete the rate product average?')) {
1027 $scope.form.averageRateProduct = false;
1028 $scope.form.fieldsAverage['product'] = {};
1029 FormService.setForm($scope.form);
1030 $("#averageRateProduct").modal('hide');
1031 }
1032 }
1033
1034 $scope.setProductOnlyRight = function () {
1035 section = $scope.form.sections.find(x => x.type == 'product')
1036 if ($scope.form.onlyProduct > 0) {
1037 section.rights = ['edit'];
1038 } else {
1039 section.rights = ['edit', 'delete'];
1040 }
1041 }
1042 }
1043 ])
1044
1045 .controller('formRenderCtrl', ['$scope', 'UserService', 'FormService', '$location', '$compile',
1046 function ($scope, UserService, FormService, $location, $compile) {
1047 /* == MAIN == */
1048 $scope.init = function () {
1049 $scope.productInitTerms=[];
1050 $scope.productInitTerms=$scope.InitTerms();
1051 $scope.newSection = {};
1052 $scope.newGroup = {};
1053 $scope.newField = {};
1054 $scope.newChoice = {};
1055 $scope.selectedVariable = {
1056 label: "",
1057 placeholder: ""
1058 };
1059 $scope.selectedSection = {};
1060 $scope.selectedGroup = {};
1061 $scope.selectedField = {};
1062 $scope.selectedFieldOriginId = "";
1063 //$scope.selectedField.multilabelling=[];
1064 $scope.selectedInputData = {
1065 label: "",
1066 placeholder: ""
1067 };
1068 $scope.formInitCondition = [];
1069
1070 $scope.formInitCondition.replaceString={
1071 label: [],
1072 placeholder: []
1073 };
1074 $scope.deleteInitCondition = 0;
1075 $scope.errors = {
1076 'section': [],
1077 'group': [],
1078 'field': [],
1079 'choice': []
1080 };
1081
1082 $scope.typeFieldList = [
1083 {
1084 'type': 'text',
1085 'label': 'Text field'
1086 },
1087 {
1088 'type': 'textarea',
1089 'label': 'Comment'
1090 },
1091 {
1092 'type': 'rate',
1093 'label': 'Rate'
1094 },
1095 {
1096 'type': 'nps',
1097 'label': 'Net Promoter Score'
1098 },
1099 {
1100 'type': 'radio',
1101 'label': 'Radio button'
1102 },
1103 {
1104 'type': 'multichoice',
1105 'label': 'Multichoice'
1106 },
1107 {
1108 'type': 'list',
1109 'label': 'List of choice'
1110 },
1111 {
1112 'type': 'date',
1113 'label': 'Date'
1114 },
1115 {
1116 'type': 'displayText',
1117 'label': 'Title - Text only'
1118 },
1119 {
1120 'type': 'upload',
1121 'label': 'Picture Upload'
1122 },
1123 {
1124 'type': 'received',
1125 'label': 'Order received'
1126 },
1127 {
1128 'type': 'delivery',
1129 'label': 'Delivery'
1130 }
1131 ];
1132
1133
1134
1135 };
1136
1137 $scope.addMultilabel = function () {
1138 console.log('dynamic data while entering multilabelling pop in');
1139 console.log($scope.formInitCondition);
1140 var newmulltilabel= {
1141 'label': '',
1142 'term': '',
1143 'replaceString': {
1144 'label': [],
1145 'placeholder': []
1146 }
1147
1148 };
1149 $scope.formInitCondition.push(newmulltilabel);
1150 // console.log('liste pop up ');
1151 // console.log($scope.formInitCondition);
1152
1153 };
1154 $scope.countNbSpecialCharsOcc = function ($index) {
1155
1156 if($scope.formInitCondition[$index]['label'] && ($scope.formInitCondition[$index]['label'].match(new RegExp('%s',"g")))){
1157 return ($scope.formInitCondition[$index]['label'].match(new RegExp('%s',"g")).length <= $scope.formInitCondition[$index]['replaceString']['label'].length);
1158 }else{
1159 return true;
1160 }
1161 };
1162
1163
1164
1165 $scope.generateEAV = function (field, isProduct) {
1166
1167 var eav = '#' + field.id.toUpperCase();
1168 if (isProduct) {
1169 eav = "!" + eav;
1170 }
1171 //CATEGORIES
1172
1173
1174 //TYPE
1175 var type = "";
1176 switch (field.type) {
1177 case 'text':
1178 case 'textarea':
1179 type = "S";
1180 break;
1181 case 'nps':
1182 if (field.noteBegin == '0') {
1183 type = "I3";
1184 } else {
1185 type = "I2";
1186 }
1187 break;
1188 case 'radio':
1189 case 'received':
1190 type = "G";
1191 break;
1192 case 'rate':
1193 if (field.maxRate == '5') {
1194 type = "I1";
1195 } else {
1196 type = "I2";
1197 }
1198 break;
1199 case 'list':
1200 case 'delivery':
1201 type = "G";
1202 break;
1203 case 'multichoice':
1204 type = "GM";
1205 break;
1206 case 'date':
1207 type = "D";
1208 break;
1209 }
1210 eav += '=' + type;
1211
1212 return eav;
1213 };
1214
1215 $scope.intval = function (input) {
1216 return parseInt(input);
1217 };
1218
1219 $scope.strval = function (input) {
1220 return String(input);
1221 }
1222
1223 $scope.cleanEAV = function (eav) {
1224 eav = eav.replace('!', '');
1225 eav = eav.replace('#', '');
1226 eav = eav.replace('?', '');
1227 eav = eav.replace(eav.substr(eav.indexOf('=')), '');
1228 return eav;
1229 }
1230
1231 //Get type field css class icon
1232 $scope.typeFieldIcon = function (type) {
1233 var result = "";
1234 switch (type) {
1235 case 'text':
1236 result = "fa fa-keyboard-o fa-2x";
1237 break;
1238 case 'textarea':
1239 result = "fa fa-comment fa-2x";
1240 break;
1241 case 'rate':
1242 result = "fa fa-star fa-2x";
1243 break;
1244 case 'nps':
1245 result = "fa fa-tachometer fa-2x";
1246 break;
1247 case 'radio':
1248 result = "fa fa-dot-circle-o fa-2x";
1249 break;
1250 case 'multichoice':
1251 result = "fa fa-check-square-o fa-2x";
1252 break;
1253 case 'list':
1254 result = "fa fa-list fa-2x";
1255 break;
1256 case 'date':
1257 result = "fa fa-calendar fa-2x";
1258 break;
1259 case 'displayText':
1260 result = "fa fa-text-width fa-2x";
1261 break;
1262 case 'upload':
1263 result = "fa fa-clipboard fa-2x";
1264 break;
1265 case 'received':
1266 result = "fa fa-truck fa-2x";
1267 break;
1268 case 'delivery':
1269 result = "fa fa-shopping-bag fa-2x";
1270 break;
1271 }
1272 return result;
1273 };
1274
1275 $scope.idFormat = function (input) {
1276 var myRegxp = /^([a-zA-Z0-9_-]+)$/;
1277
1278 return myRegxp.test(input);
1279 };
1280
1281 //Get list of number with a max number (begin at 1)
1282 $scope.getNumber = function (num) {
1283 num = parseInt(num);
1284 var array = [];
1285 for (i = 1; i <= num; i++) {
1286 array.push(i);
1287 }
1288
1289 return array;
1290 };
1291
1292 $scope.getRangeNumber = function (min, max) {
1293 min = parseInt(min);
1294 max = parseInt(max);
1295 var array = [];
1296 for (i = min; i <= max; i++) {
1297 array.push(i);
1298 }
1299
1300 return array;
1301 };
1302
1303 $scope.changeOrder = function (side, itemChanged, list) {
1304 var order = 1;
1305 if (side == 'up') {
1306 order = angular.copy(itemChanged.order);
1307 itemChanged.order -= 1;
1308 } else { //down
1309 order = angular.copy(itemChanged.order);
1310 itemChanged.order += 1;
1311 }
1312 angular.forEach(list, function (item, index) {
1313 if (itemChanged.order == item.order && itemChanged.id != item.id) {
1314 list[index].order = order;
1315 }
1316 });
1317
1318 list.sort(function (a, b) {
1319 return a.order - b.order;
1320 });
1321
1322 $scope.save();
1323 };
1324
1325 /* == FORM == */
1326 $scope.save = function () {
1327 FormService.setForm($scope.form);
1328 $scope.$emit('addVersion');
1329 };
1330 $scope.InitTerms = function () {
1331 var termTolist=[];
1332 var arr=['CATEGORY','REF_PRODUIT','SKU','BRAND_NAME'];
1333
1334 for (let i = 0; i < $scope.form.terms.length; i++) {
1335 if ((arr.includes($scope.form.terms[i].data) || $scope.form.terms[i].data.indexOf('!') > -1 )&& $scope.form.terms[i].type=='init') {
1336
1337 termTolist.push(angular.copy($scope.form.terms[i]));
1338 }
1339 }
1340 // console.log('here');
1341 // console.log(termTolist);
1342 return termTolist;
1343 }
1344 //Check if the id is unique in the form
1345 $scope.isUniqueIdCss = function (idCss, idObj) {
1346 var result = true;
1347 if (idCss && idCss.length > 0) {
1348 angular.forEach($scope.form.sections, function (section, indexS) {
1349
1350 if (section.idCss == idCss && section.id != idObj) {
1351 result = false;
1352 }
1353
1354 if (result) {
1355 angular.forEach(section.groups, function (group, indexG) {
1356 if (group.idCss == idCss && group.id != idObj) {
1357 result = false;
1358 }
1359 if (result) {
1360 angular.forEach(group.fields, function (field, indexF) {
1361 if (field.idCss == idCss && field.id != idObj) {
1362 result = false;
1363 }
1364 });
1365 }
1366 });
1367 }
1368 });
1369 }
1370
1371 return result;
1372 };
1373
1374 $scope.isUniqueId = function (id) {
1375 var result = true;
1376 if (id && id.length > 0) {
1377 angular.forEach($scope.form.sections, function (section, indexS) {
1378
1379 if (section.id == id) {
1380 result = false;
1381 }
1382
1383 if (result) {
1384 angular.forEach(section.groups, function (group, indexG) {
1385 if (group.id == id) {
1386 result = false;
1387 }
1388 if (result) {
1389 angular.forEach(group.fields, function (field, indexF) {
1390 if (field.id == id) {
1391 result = false;
1392 }
1393 });
1394 }
1395 });
1396 }
1397 });
1398 }
1399
1400 return result;
1401 };
1402
1403 /* == SECTION == */
1404 $scope.selectSection = function (section) {
1405 $scope.errors.section = [];
1406 $scope.selectedSection = angular.copy(section);
1407 if (!$scope.selectedSection.hasOwnProperty('replaceString')) {
1408 $scope.selectedSection['replaceString'] = {
1409 label: []
1410 };
1411 }
1412 };
1413
1414 $scope.createSection = function (type) {
1415 $scope.errors.section = [];
1416 if (type == 'product') {
1417 $scope.newSection = FormService.createProductSection();
1418 } else {
1419 $scope.newSection = FormService.createSection();
1420 }
1421
1422 var order = $scope.newSection.order = $scope.form.sections.length + 1;
1423
1424 if (type == 'product') {
1425 $scope.newSection.idCss = $scope.newSection.id;
1426 } else {
1427 var number = $scope.newSection.id + order;
1428 var count = 0;
1429 while (!$scope.isUniqueId(number)) {
1430 count++;
1431 number = $scope.newSection.id + String(order + count);
1432 }
1433 $scope.newSection.id = $scope.newSection.idCss = number;
1434 $scope.newSection.label = $scope.newSection.label + " " + String(order + count);
1435 }
1436 $scope.newSection.replaceString = {
1437 label: [],
1438 placeholder: []
1439 };
1440 };
1441
1442 $scope.sectionValidator = function (section) {
1443 var result = true;
1444 var message = "";
1445 if (!$scope.isUniqueIdCss(section.idCss, section.id)) {
1446 result = false;
1447 message = "The css id is not unique.";
1448 $scope.errors.section.idCss = message;
1449 }
1450
1451 if (!$scope.idFormat(section.idCss)) {
1452 result = false;
1453 message = "The css id is not valid.";
1454 $scope.errors.section.idCss = message;
1455 }
1456
1457 if (section.label.length == 0) {
1458 result = false;
1459 message = "Please enter a label.";
1460 $scope.errors.section.label = message;
1461 }
1462
1463 if (section.type == 'product') {
1464 if (section.nbMaxProduct.length == 0 || section.nbMaxProduct <= 0) {
1465 result = false;
1466 message = "The maximum product number to display is mandatory and must be greater than 0.";
1467 $scope.errors.section.nbMaxProduct = message;
1468 }
1469 }
1470
1471 return result;
1472 };
1473
1474 $scope.addSection = function () {
1475 if ($scope.sectionValidator($scope.newSection)) {
1476 $scope.form.sections.push($scope.newSection);
1477
1478 if ($scope.newSection.type == 'product') {
1479 $scope.form.enableProductsReview = true;
1480 }
1481
1482 $("#addSection").modal('hide');
1483 $scope.save();
1484 }
1485 };
1486
1487 $scope.editSection = function () {
1488 if ($scope.sectionValidator($scope.selectedSection)) {
1489 angular.forEach($scope.form.sections, function (section, key) {
1490 if (section.id == $scope.selectedSection.id) {
1491 $scope.form.sections[key] = angular.copy($scope.selectedSection);
1492 }
1493 });
1494
1495 $("#editSection").modal('hide');
1496
1497 $scope.save();
1498 }
1499 };
1500
1501 $scope.addReplaceStringSection = function (attribut, inputDataType, isNew) {
1502 var inputData = $scope.form.inputDataMapping['order'].find(i => i.id == $scope.selectedInputData[attribut]);
1503 if (isNew) {
1504 $scope.newSection.replaceString[attribut].push({
1505 type: 'order',
1506 label: inputData.label,
1507 id: $scope.selectedInputData[attribut],
1508 order: $scope.newSection.replaceString[attribut].length + 1
1509 });
1510 } else {
1511
1512 $scope.selectedSection.replaceString[attribut].push({
1513 type: 'order',
1514 label: inputData.label,
1515 id: $scope.selectedInputData[attribut],
1516 order: $scope.selectedSection.replaceString[attribut].length + 1
1517 });
1518 }
1519 $scope.selectedInputData[attribut] = "";
1520 };
1521
1522 $scope.deleteReplaceStringSection = function (attribut, id, isNew) {
1523 if (isNew) {
1524 $scope.newSection.replaceString[attribut].splice($scope.newSection.replaceString[attribut].findIndex(i => i.id == id), 1);
1525 } else {
1526 $scope.selectedSection.replaceString[attribut].splice($scope.selectedSection.replaceString[attribut].findIndex(i => i.id == id), 1);
1527 }
1528 }
1529
1530 $scope.deleteSection = function () {
1531 var order = angular.copy($scope.selectedSection.order);
1532 var sectionIndex = null;
1533 angular.forEach($scope.form.sections, function (section, indexS) {
1534 if (section.id == $scope.selectedSection.id) {
1535 sectionIndex = indexS;
1536 } else if (section.order > order) {
1537 section.order -= 1;
1538 }
1539 });
1540
1541 if (sectionIndex != null) {
1542 angular.forEach($scope.form.sections[sectionIndex].groups, function (group, indexG) {
1543 angular.forEach(group.fields, function (field, indexF) {
1544 //Delete in mapping
1545 if (field.type == "upload") {
1546 $scope.activateUpload($scope.selectedSection.type);
1547 }
1548 if (field.id != 'RATE' && field.id != 'review' || field.id != 'productRate' && field.id != 'productReview') {
1549 if ($scope.selectedSection.type == 'order') {
1550 angular.forEach($scope.form.orderMapping, function (item, index) {
1551 if (item.id == field.id) {
1552 $scope.form.orderMapping.splice(index, 1);
1553 }
1554 });
1555 } else {
1556 angular.forEach($scope.form.productMapping, function (item, index) {
1557 if (item.id == field.id) {
1558 $scope.form.productMapping.splice(index, 1);
1559 }
1560 });
1561 }
1562 }
1563 });
1564 });
1565 $scope.form.sections.splice(sectionIndex, 1);
1566 if ($scope.selectedSection.type == 'product') {
1567 $scope.form.enableProductsReview = false;
1568 }
1569 }
1570
1571 $("#deleteSection").modal('hide');
1572
1573 $scope.save();
1574 };
1575
1576 /* == GROUPE == */
1577 $scope.selectGroup = function (group) {
1578 $scope.errors.section = [];
1579 $scope.selectedGroup = angular.copy(group);
1580 };
1581
1582 $scope.createGroup = function (id, type) {
1583 $scope.errors.section = [];
1584 $scope.newGroup = FormService.createGroup();
1585 angular.forEach($scope.form.sections, function (section, key) {
1586 if (id == section.id) {
1587 var order = $scope.newGroup.order = section.groups.length + 1;
1588
1589 //get unique default idCss
1590 var number = $scope.newGroup.id + String(order);
1591 var count = 0;
1592 while (!$scope.isUniqueId(number)) {
1593 count++;
1594 number = $scope.newGroup.id + String(parseInt(order + count));
1595 }
1596
1597 $scope.newGroup.id = $scope.newGroup.idCss = number;
1598 $scope.newGroup.sectionId = id;
1599 $scope.newGroup.type = type;
1600 }
1601 });
1602 };
1603 $scope.activateUpload = function (type) {
1604 if (type == 'order') {
1605 $scope.form.enableUpload.order = true;
1606 } else {
1607 $scope.form.enableUpload.product = true;
1608 }
1609 };
1610 $scope.groupValidator = function (group) {
1611 var result = true;
1612 var message = "";
1613 if (!$scope.isUniqueIdCss(group.idCss, group.id)) {
1614 result = false;
1615 message = "The css id is not unique.";
1616 $scope.errors.group.idCss = message;
1617 }
1618
1619 if (!$scope.idFormat(group.idCss)) {
1620 result = false;
1621 message = "The css id is not valid.";
1622 $scope.errors.group.idCss = message;
1623 }
1624
1625 return result;
1626 };
1627
1628 $scope.addGroup = function () {
1629 if ($scope.groupValidator($scope.newGroup)) {
1630 angular.forEach($scope.form.sections, function (section, key) {
1631 if ($scope.newGroup.sectionId == section.id) {
1632 $scope.form.sections[key].groups.push($scope.newGroup);
1633 }
1634 });
1635 $("#addGroup").modal('hide');
1636 $scope.save();
1637 }
1638 };
1639
1640 $scope.editGroup = function () {
1641 if ($scope.groupValidator($scope.selectedGroup)) {
1642 angular.forEach($scope.form.sections, function (section, key) {
1643 if (section.id == $scope.selectedGroup.sectionId) {
1644 angular.forEach($scope.form.sections[key].groups, function (group, keyG) {
1645 if ($scope.selectedGroup.id == group.id) {
1646 $scope.form.sections[key].groups[keyG] = angular.copy($scope.selectedGroup);
1647 }
1648 });
1649 }
1650 });
1651 $("#editGroup").modal('hide');
1652 $scope.save();
1653 }
1654 };
1655
1656 $scope.deleteGroup = function () {
1657 var order = angular.copy($scope.selectedGroup.order);
1658 var sectionIndex = null;
1659 var groupIndex = null;
1660 var type = null;
1661 angular.forEach($scope.form.sections, function (section, indexS) {
1662 if (section.id == $scope.selectedGroup.sectionId) {
1663 type = section.type;
1664 sectionIndex = indexS;
1665 angular.forEach(section.groups, function (group, indexG) {
1666 if ($scope.selectedGroup.id == group.id) {
1667 groupIndex = indexG;
1668 } else if (group.order > order) {
1669 group.order -= 1;
1670 }
1671 });
1672 }
1673 });
1674
1675 if (sectionIndex != null && groupIndex != null) {
1676 angular.forEach($scope.selectedGroup.fields, function (field, indexF) {
1677
1678 if (field.type == "upload") {
1679 $scope.activateUpload(type);
1680 }
1681
1682 //Delete in mapping
1683 if (field.id != 'RATE' && field.id != 'review' || field.id != 'productRate' && field.id != 'productReview') {
1684 if ($scope.form.sections[sectionIndex].type == 'order') {
1685 angular.forEach($scope.form.orderMapping, function (item, index) {
1686 if (item.id == field.id) {
1687 $scope.form.orderMapping.splice(index, 1);
1688 }
1689 });
1690 } else {
1691 angular.forEach($scope.form.productMapping, function (item, index) {
1692 if (item.id == field.id) {
1693 $scope.form.productMapping.splice(index, 1);
1694 }
1695 });
1696 }
1697 }
1698 });
1699 $scope.form.sections[sectionIndex].groups.splice(groupIndex, 1);
1700 }
1701
1702 $("#deleteGroup").modal('hide');
1703
1704 $scope.save();
1705 };
1706
1707 /* == FIELDS == */
1708 $scope.createField = function (idSection, idGroup) {
1709 $scope.errors.field = [];
1710 $scope.newField = FormService.createField();
1711 angular.forEach($scope.form.sections, function (section, keyS) {
1712 if (idSection == section.id) {
1713 angular.forEach(section.groups, function (group, keyG) {
1714 if (idGroup == group.id) {
1715 var order = $scope.newField.order = group.fields.length + 1;
1716
1717 //get unique default idCss
1718 var id = $scope.newField.id + String(order);
1719 var count = 0;
1720 while (!$scope.isUniqueId(id)) {
1721 count++;
1722 id = $scope.newField.id + String(order + count);
1723 }
1724
1725 $scope.newField.id = $scope.newField.idCss = $scope.newField.label = id;
1726 $scope.newField.sectionId = idSection;
1727 $scope.newField.groupId = idGroup;
1728 $scope.newField.replaceString = {
1729 label: [],
1730 placeholder: []
1731 };
1732 }
1733 });
1734 }
1735 });
1736 };
1737
1738 $scope.selectField = function (field) {
1739 $scope.errors.field = [];
1740 $scope.selectedField = angular.copy(field);
1741 if(!$scope.selectedField.hasOwnProperty('replaceString')) {
1742 $scope.selectedField['replaceString'] = {
1743 label: [],
1744 placeholder: []
1745 };
1746 }
1747 $scope.selectedFieldOriginId = angular.copy(field.id);
1748 if ($scope.selectedField.hasOwnProperty('multilabelling')) {
1749 console.log('selected field multilabelling data');
1750 console.log(field['multilabelling']);
1751 angular.forEach(field['multilabelling'], function (multilabel, index) {
1752 $scope.formInitCondition.push(multilabel);
1753 });
1754 console.log('dynamic data while selecting the field');
1755 console.log($scope.formInitCondition);
1756
1757 }
1758 };
1759
1760 $scope.addField = function (field = null) {
1761 //console.log(field);
1762 if (field != null) {
1763 $scope.newField = field;
1764 $scope.newField.id = $scope.selectedField.id;
1765 //$scope.newField.id = id ;
1766 }
1767
1768 $scope.errors.field = [];
1769 var fieldGroup;
1770 if ($scope.fieldValidator($scope.newField, null)) {
1771 angular.forEach($scope.form.sections, function (section, indexS) {
1772 if (section.id == $scope.newField.sectionId) {
1773 angular.forEach(section.groups, function (group, indexG) {
1774 if (group.id == $scope.newField.groupId) {
1775 fieldGroup = group;
1776 if ($scope.newField.type != 'displayText') {
1777 if (['RATE', 'REVIEW', 'productRate', 'PRODUCTREVIEW'].indexOf($scope.newField.id) < 0) {
1778 $scope.newField.eav = $scope.generateEAV($scope.newField, (group.type == 'product'));
1779
1780 var map = {
1781 'id': $scope.newField.id,
1782 'label': $scope.cleanEAV($scope.newField.eav),
1783 'eav': $scope.newField.eav,
1784 'type': $scope.newField.type
1785 };
1786 // Mapping
1787 if (section.type == 'order') {
1788 $scope.form.orderMapping.push(map);
1789 } else {
1790 $scope.form.productMapping.push(map);
1791 }
1792
1793 var labelItem = {
1794 'eav': map.eav,
1795 'label': map.label,
1796 'destination': group.type
1797 };
1798 if ($scope.newField.hasOwnProperty('choiceList')) {
1799 labelItem['values'] = [];
1800 angular.forEach($scope.newField.choiceList, function (choice, indexC) {
1801 labelItem['values'].push({
1802 'label': choice.label,
1803 'value': choice.value
1804 });
1805 });
1806 }
1807 if ($scope.newField.type === 'received') {
1808 $scope.form.relance = {
1809 'eav': labelItem.eav,
1810 'value': $scope.newField.relanceValue,
1811 'idCss': $scope.newField.idCss ? $scope.newField.idCss : $scope.newField.id
1812 }
1813 }
1814 $scope.form.labels.push(labelItem);
1815 }
1816 }
1817
1818 $scope.form.sections[indexS].groups[indexG].fields.push($scope.newField);
1819 if ($scope.newField.type == "upload") {
1820 if (section.type == 'order') {
1821 $scope.form.enableUpload.order = false;
1822 } else {
1823 $scope.form.enableUpload.product = false;
1824 }
1825 } else if (!$scope.form.enableUpload[section.type]) {
1826 $scope.changeOrder('up', $scope.newField, group.fields);
1827 }
1828 }
1829 });
1830 }
1831 });
1832
1833 $("#addField").modal('hide');
1834 $scope.save();
1835 }
1836 };
1837 $scope.editMultilabellingforField = function () {
1838 $scope.selectedField['multilabelling']= angular.copy($scope.formInitCondition);
1839 $("#multilabels").modal('hide');
1840 $("#editField").modal('show');
1841
1842
1843 };
1844 $scope.verificationFormInitCondition = function () {
1845 var check = true;
1846 if($scope.formInitCondition != undefined){
1847 $scope.formInitCondition.forEach(function (row) {
1848 //console.log(row);
1849 if (row.label == '') check = false;
1850 if (row.term =='') check = false;
1851 if (row.replaceString.label.length == 0)
1852 check = false;
1853 else if ($scope.countNbSpecialCharsOcc($scope.formInitCondition.indexOf(row))==false)
1854 check = false;
1855
1856 });
1857 return check;
1858 }
1859 };
1860
1861 $scope.editField = function(idField) {
1862 $scope.errors.choice = {};
1863 if($scope.fieldValidator($scope.selectedField, idField)) {
1864 angular.forEach($scope.form.sections, function(section, indexS) {
1865 if(section.id == $scope.selectedField.sectionId) {
1866 angular.forEach(section.groups, function(group, indexG) {
1867 if(group.id == $scope.selectedField.groupId) {
1868 angular.forEach(group.fields, function(field, indexF) {
1869 if(field.id == idField) {
1870 if($scope.selectField.type != 'displayText') {
1871 if(['RATE', 'REVIEW', 'productRate', 'PRODUCTREVIEW'].indexOf($scope.newField.id) < 0) {
1872 $scope.selectedField.eav = $scope.generateEAV($scope.selectedField, (group.type == 'product'));
1873 var map = {
1874 'id': $scope.selectedField.id,
1875 'label': $scope.cleanEAV($scope.selectedField.eav),
1876 'eav': $scope.selectedField.eav,
1877 'type': $scope.selectedField.type
1878 };
1879
1880 // MAPPING
1881 if(section.type == 'order') {
1882 angular.forEach($scope.form.orderMapping, function(item, index) {
1883 if(item.id == idField) {
1884 $scope.form.orderMapping[index] = map;
1885 }
1886 });
1887 } else {
1888 angular.forEach($scope.form.productMapping, function(eav, index) {
1889 if(eav == idField) {
1890 $scope.form.productMapping[index] = map;
1891 }
1892 });
1893 }
1894
1895 var labelItem = {
1896 'eav': map.eav,
1897 'label': map.label,
1898 'destination': group.type
1899 };
1900 if($scope.selectedField.hasOwnProperty('choiceList')) {
1901 labelItem['values'] = [];
1902 angular.forEach($scope.selectedField.choiceList, function(choice, indexC) {
1903 labelItem['values'].push({
1904 'label': choice.label,
1905 'value': choice.value
1906 });
1907 });
1908 }
1909 if($scope.selectedField.type === 'received') {
1910 $scope.form.relance = {
1911 'eav': labelItem.eav,
1912 'value': $scope.selectedField.relanceValue,
1913 'idCss': $scope.selectedField.idCss ? $scope.selectedField.idCss : $scope.selectedField.id
1914 }
1915 }
1916 $scope.form.labels[$scope.form.labels.findIndex(i => i.eav === labelItem.eav)] = labelItem;
1917 }
1918
1919 $scope.form.sections[indexS].groups[indexG].fields[indexF] = angular.copy($scope.selectedField);
1920 }
1921 }
1922 });
1923 }
1924 });
1925 }
1926 });
1927 $("#editField").modal('hide');
1928 $scope.save();
1929 }
1930 };
1931
1932 $scope.deleteField = function () {
1933 var order = angular.copy($scope.selectedField.order);
1934 var sectionIndex = null;
1935 var groupIndex = null;
1936 var fieldIndex = null;
1937
1938 angular.forEach($scope.form.sections, function (section, indexS) {
1939 if (section.id == $scope.selectedField.sectionId) {
1940 sectionIndex = indexS;
1941 angular.forEach(section.groups, function (group, indexG) {
1942 if (group.id == $scope.selectedField.groupId) {
1943 groupIndex = indexG;
1944 angular.forEach(group.fields, function (field, indexF) {
1945 if (field.id == $scope.selectedField.id) {
1946 fieldIndex = indexF;
1947
1948 //Delete in mapping
1949 if ($scope.selectedField.id != 'RATE' && $scope.selectedField.id != 'REVIEW' || $scope.selectedField.id != 'productRate' && $scope.selectedField.id != 'PRODUCTREVIEW') {
1950 if (section.type == 'order') {
1951 $scope.form.orderMapping.splice($scope.form.orderMapping.findIndex(item => item.id == $scope.selectedField.id), 1);
1952 } else {
1953 $scope.form.productMapping.splice($scope.form.productMapping.findIndex(item => item.id == $scope.selectedField.id), 1);
1954 }
1955
1956 //Delete terms link to this field
1957 var termsId = [];
1958 angular.forEach($scope.form.terms, function (term, index) {
1959 if (term.data == $scope.selectedField.id) {
1960 termsId.push(term.id);
1961
1962 //dissociate the term to his behaviours
1963 var behaviorIdToDelete = [];
1964 angular.forEach($scope.form.behaviours, function (behavior, indexB) {
1965 if (behavior.terms.findIndex(i => i == term.id) !== -1) {
1966 behavior.terms.splice(behavior.terms.findIndex(i => i == term.id), 1);
1967
1968 //If no term, the behavior is deleted
1969 if (behavior.terms.length === 0) {
1970 behaviorIdToDelete.push(behavior.id);
1971 }
1972 }
1973 });
1974
1975 //delete behavior with no terms
1976 if (behaviorIdToDelete.length > 0) {
1977 angular.forEach(behaviorIdToDelete, function (id, key) {
1978 $scope.form.behaviours.splice($scope.form.behaviours.findIndex(i => i.id == id), 1);
1979 });
1980 }
1981
1982 }
1983 });
1984
1985 angular.forEach(termsId, function (termId, index) {
1986 $scope.form.terms.splice($scope.form.terms.findIndex(i => i.id == termId), 1);
1987 });
1988
1989 $scope.form.terms
1990 $scope.form.labels.splice($scope.form.labels.findIndex(i => i.eav === $scope.selectedField.eav), 1);
1991 if ($scope.selectedField.type == "upload") {
1992 if (section.type == 'order') {
1993 $scope.form.enableUpload.order = true;
1994 } else {
1995 $scope.form.enableUpload.product = true;
1996 }
1997 }
1998 if ($scope.selectedField.type == "received") {
1999 $scope.form.relance = null;
2000 }
2001 }
2002 } else if (field.order > order) {
2003 field.order -= 1;
2004 }
2005 });
2006 }
2007 });
2008 }
2009 });
2010
2011 if (sectionIndex != null && groupIndex != null && fieldIndex != null) {
2012 $scope.form.sections[sectionIndex].groups[groupIndex].fields.splice(fieldIndex, 1);
2013 }
2014
2015 $("#deleteField").modal('hide');
2016 $scope.save();
2017 };
2018
2019 $scope.addReplaceString = function (attribut, inputDataType, isNew) {
2020 if ($scope.selectedInputData[attribut] == 'denominationClient') {
2021 var label = $scope.form.denomination;
2022 } else {
2023 var inputData = $scope.form.inputDataMapping[inputDataType].find(i => i.id == $scope.selectedInputData[attribut]);
2024 var label = inputData.label;
2025 }
2026 if (isNew) {
2027 $scope.newField.replaceString[attribut].push({
2028 type: inputDataType,
2029 label: label,
2030 id: $scope.selectedInputData[attribut],
2031 order: $scope.newField.replaceString[attribut].length + 1
2032 });
2033 } else {
2034 $scope.selectedField.replaceString[attribut].push({
2035 type: inputDataType,
2036 label: label,
2037 id: $scope.selectedInputData[attribut],
2038 order: $scope.selectedField.replaceString[attribut].length + 1
2039 });
2040 }
2041 $scope.selectedInputData[attribut] = "";
2042 };
2043 $scope.addMultiLabelReplaceString = function ($index) {
2044 if ($scope.selectedVariable['label'] == 'denominationClient') {
2045 var label = $scope.form.denomination;
2046 } else {
2047 var inputData = $scope.form.inputDataMapping['product'].find(i => i.id == $scope.selectedVariable['label']);
2048 if(!inputData){
2049 var inputData = $scope.form.inputDataMapping['order'].find(i => i.id == $scope.selectedVariable['label']);
2050 }
2051
2052 var label = inputData.label;
2053 }
2054 $scope.formInitCondition[$index].replaceString['label'].push({
2055 type: 'product',
2056 label: label,
2057 id: $scope.selectedVariable['label'],
2058 order: $scope.formInitCondition[$index].replaceString['label'].length + 1
2059 });
2060
2061 $scope.selectedVariable['label'] = "";
2062 };
2063 $scope.deleteReplaceString = function (attribut, id, isNew) {
2064 if (isNew) {
2065 $scope.newField.replaceString[attribut].splice($scope.newField.replaceString[attribut].findIndex(i => i.id == id), 1);
2066 } else {
2067 $scope.selectedField.replaceString[attribut].splice($scope.selectedField.replaceString[attribut].findIndex(i => i.id == id), 1);
2068 }
2069 };
2070 $scope.deleteMultilabelReplaceString = function (attribut, id,$index) {
2071 $scope.formInitCondition[$index].replaceString[attribut].splice($scope.formInitCondition.replaceString[attribut].findIndex(i => i.id == id), 1);
2072
2073 };
2074 $scope.getFormattedId = function (element) {
2075 var regExId = /^([a-zA-Z0-9_-]+)$/;
2076 var idChar = element.id.split('');
2077 var formattedId = "";
2078 idChar.forEach(function (char) {
2079 if (regExId.test(char))
2080 formattedId += char.toUpperCase();
2081 });
2082 element.id = formattedId;
2083 }
2084
2085
2086 // set the type and add model attribut of field's type
2087 $scope.setNewFieldType = function (type) {
2088 $scope.newField.type = type;
2089 $scope.newField.classCss = '';
2090 $scope.newField.styleCss = '';
2091 switch (type) {
2092 case 'text':
2093 case 'textarea':
2094 $scope.newField.placeholder = '';
2095 $scope.newField.minChar = 2;
2096 $scope.newField.maxChar = 2500;
2097 $scope.newField.regEx = '';
2098 break;
2099 case 'rate':
2100 $scope.newField.button = 'star';
2101 $scope.newField.buttonSize = '35';
2102 $scope.newField.maxRate = '5';
2103 break;
2104 case 'nps':
2105 $scope.newField.noteBegin = '0';
2106 $scope.newField.nbColors = '4';
2107 $scope.newField.red = '3'; //max nps note color
2108 $scope.newField.orange = '6';
2109 $scope.newField.yellow = '8';
2110 $scope.newField.green = '10';
2111 $scope.newField.detracteur1 = npsLabelDetracteur1;
2112 $scope.newField.detracteur2 = npsLabelDetracteur2;
2113 $scope.newField.passif = npsLabelPassif;
2114 $scope.newField.promoteur = npsLabelPromoteur;
2115 break;
2116 case 'radio':
2117 $scope.newField.choiceList = [{
2118 'id': 1,
2119 'order': 1,
2120 'value': '0',
2121 'label': 'default'
2122 },
2123 {
2124 'id': 2,
2125 'order': 2,
2126 'value': '1',
2127 'label': 'choix 1'
2128 },
2129 {
2130 'id': 3,
2131 'order': 3,
2132 'value': '2',
2133 'label': 'choix 2'
2134 }];
2135 $scope.newChoice = {
2136 'id': 0,
2137 'order': 0,
2138 'value': '',
2139 'label': ''
2140 };
2141 $scope.newField.defaultChoiceValue = '0';
2142 $scope.newField.displayMode = 'horizontal';
2143 break;
2144 case 'multichoice':
2145 $scope.newField.choiceList = [{
2146 'id': 1,
2147 'order': 1,
2148 'value': '0',
2149 'label': 'choix 1'
2150 },
2151 {
2152 'id': 2,
2153 'order': 2,
2154 'value': '1',
2155 'label': 'choix 2'
2156 },
2157 {
2158 'id': 3,
2159 'order': 3,
2160 'value': '2',
2161 'label': 'choix 3'
2162 }];
2163 $scope.newChoice = {
2164 'id': 0,
2165 'order': 0,
2166 'value': '',
2167 'label': ''
2168 };
2169 $scope.newField.displayMode = 'horizontal';
2170 $scope.newField.input = 'checkbox';
2171 $scope.newField.maxChoices = 0;
2172 $scope.newField.minChoices = 0;
2173 break;
2174 case 'received':
2175 $scope.newField.label = notReceivedFieldLabel_txt;
2176 $scope.newField.choiceList = [
2177 {
2178 'id': 1,
2179 'order': 2,
2180 'value': 'yes',
2181 'label': yes_txt
2182 },
2183 {
2184 'id': 2,
2185 'order': 3,
2186 'value': 'no',
2187 'label': no_txt
2188 }
2189 ];
2190 $scope.newField.defaultChoiceValue = 'yes';
2191 $scope.newField.relanceValue = 'no';
2192 $scope.newField.displayMode = 'horizontal';
2193 break;
2194 case 'delivery':
2195 $scope.newField.label = deliveryLabel;
2196 $scope.newField.choiceList = [
2197 {
2198 'id': 1,
2199 'order': 2,
2200 'value': 'yes',
2201 'label': yes_txt
2202 },
2203 {
2204 'id': 2,
2205 'order': 3,
2206 'value': 'no',
2207 'label': no_txt
2208 }
2209 ];
2210 $scope.newField.defaultChoiceValue = 'yes';
2211 $scope.newField.info = deliveryInfo;
2212 $scope.newField.displayMode = 'horizontal';
2213 break;
2214 case 'list':
2215 $scope.newField.choiceList = [{
2216 'id': 1,
2217 'order': 1,
2218 'value': '-',
2219 'label': '-'
2220 },
2221 {
2222 'id': 2,
2223 'order': 2,
2224 'value': '1',
2225 'label': 'selection 1'
2226 },
2227 {
2228 'id': 3,
2229 'order': 3,
2230 'value': '2',
2231 'label': 'selection 2'
2232 }];
2233 $scope.newChoice = {
2234 'id': 0,
2235 'order': 0,
2236 'value': '',
2237 'label': ''
2238 };
2239 $scope.newField.defaultChoiceValue = '0';
2240 break;
2241 case 'date':
2242 $scope.newField.dateFormat = 'Y-m-d';
2243 break;
2244 case 'upload':
2245 var sectionType = $scope.form.sections.find(x => x.id === $scope.newField.sectionId).type; // We search the type of section, order or product
2246 $scope.newField.id = 'upload' + (sectionType.charAt(0).toUpperCase() + sectionType.substring(1).toLowerCase());
2247 $scope.newField.label = uploadLabel;
2248 $scope.newField.required = 'off';
2249 $scope.newField.uploadButton = uploadButton;
2250 $scope.newField.uploadFeedback = uploadFeedback;
2251 $scope.newField.uploadFeedback2 = uploadFeedback2;
2252 $scope.newField.uploadDrop = uploadDrop;
2253 $scope.newField.uploadRemoveConfirmation = uploadRemoveConfirmation;
2254 $scope.newField.uploadDragNDrop = uploadDragNDrop;
2255 $scope.newField.uploadOr = uploadOr;
2256 $scope.newField.uploadBrowseFiles = uploadBrowseFiles;
2257 $scope.newField.uploadSuccess = uploadSuccess;
2258 $scope.newField.uploadError = uploadError;
2259 $scope.newField.uploadErrorFilesLimit = uploadErrorFilesLimit;
2260 $scope.newField.uploadErrorFilesType = uploadErrorFilesType;
2261 $scope.newField.uploadErrorFilesSize = uploadErrorFilesSize;
2262 $scope.newField.uploadErrorFilesSizeAll = uploadErrorFilesSizeAll;
2263 $scope.newField.uploadErrorFolderUpload = uploadErrorFolderUpload;
2264 $scope.newField.uploadErrorEmpty = uploadErrorEmpty;
2265 $scope.newField.uploadAlready = uploadAlready;
2266 break;
2267 }
2268 };
2269
2270 $scope.fieldIdIsUnique = function (submittedField) {
2271 var result = true;
2272 angular.forEach($scope.form.sections, function (section, indexS) {
2273 angular.forEach(section.groups, function (group, indexG) {
2274 angular.forEach(group.fields, function (field, indexF) {
2275 if (field.id == submittedField.id && (field.order != submittedField.order || field.groupId != submittedField.groupId || field.sectionId != submittedField.sectionId)) {
2276 result = false;
2277 }
2278 });
2279 });
2280 });
2281 return result;
2282 };
2283
2284 $scope.fieldValidator = function (field, idField) {
2285 var result = true;
2286 if (!$scope.isUniqueIdCss(field.idCss, idField)) {
2287 result = false;
2288 message = "The css id is not unique.";
2289 $scope.errors.field.idCss = message;
2290 $("#glyphiconAddAdvancedConfiguration").toggle();
2291 $("#textAddAdvancedConfiguration").toggle();
2292 $("#addAdvancedConfiguration").toggle();
2293 }
2294
2295 if (field.id.length == 0 || !$scope.fieldIdIsUnique(field)) {
2296 result = false;
2297 $scope.errors.field.id = "The identifier of the field is mandatory and must be unique.";
2298 } else if (['version', 'microtime'].indexOf(field.id) !== -1) {
2299 result = false;
2300 $scope.errors.field.id = "The field id entered is part of the system fields, please enter another identifier.";
2301 }
2302
2303 switch (field.type) {
2304 case 'text':
2305 case 'textarea':
2306 if (field.minChar == null) {
2307 result = false;
2308 $scope.errors.field.minChar = "The minimum number of characters is mandatory.";
2309 }
2310
2311 if (field.maxChar == null || field.maxChar < field.minChar) {
2312 result = false;
2313 $scope.errors.field.maxChar = "The maximum number of characters is mandatory and must be logically greater than the minimum number of characters.";
2314 }
2315 break;
2316 case 'rate':
2317 if (field.buttonSize.length == 0) {
2318 result = false;
2319 $scope.errors.field.buttonSize = "The size of the buttons is mandatory.";
2320 } else {
2321 if (idField !== null && $scope.isTerm(idField) && field.maxRate == 5) {
2322 angular.forEach($scope.form.terms, function (term, index) {
2323 if (term.data == idField) {
2324 if (term.value > 5) {
2325 $scope.form.terms[index].value = 5;
2326 }
2327 }
2328 });
2329 }
2330 }
2331 break;
2332 case 'multichoice':
2333 if (field.maxChoices > 0 && field.minChoices > field.maxChoices) {
2334 result = false;
2335 $scope.errors.field.minChoices = "The minimum of required options can not be greater than the maximum of options allowed";
2336 }
2337 case 'radio':
2338 case 'list':
2339 if (field.choiceList.length < 2) {
2340 result = false;
2341 $scope.errors.field.choiceList = "You must fill in at least 2 choices of answers.";
2342 } else {
2343 if (idField !== null && $scope.isTerm(idField)) {
2344 angular.forEach($scope.form.terms, function (term, index) {
2345 if (term.data == idField) {
2346 var isInList = false;
2347 angular.forEach(field.choiceList, function (choice, indexC) {
2348 if (term.value == choice.value) {
2349 isInList = true;
2350 }
2351 });
2352 if (!isInList) {
2353 $scope.form.terms.splice(index, 1);
2354 }
2355 }
2356 });
2357 }
2358 }
2359 break;
2360 }
2361
2362 if (idField !== null && $scope.isTerm(idField) && idField != field.id) {
2363 angular.forEach($scope.form.terms, function (term, index) {
2364 if (term.data == idField) {
2365 $scope.form.terms[index].data = field.id;
2366 }
2367 });
2368 }
2369
2370 return result;
2371 };
2372
2373 $scope.isTerm = function (fieldId) {
2374 var result = false;
2375 if ($scope.form.terms.length > 0) {
2376 angular.forEach($scope.form.terms, function (term, indexT) {
2377 if (term.data == fieldId) {
2378 result = true;
2379 }
2380 });
2381 }
2382 return result;
2383 };
2384
2385 $scope.choiceValueIsUnique = function (field, newChoice) {
2386 var result = true;
2387 angular.forEach(field.choiceList, function (choice, index) {
2388 if (choice.value == newChoice.value) {
2389 result = false;
2390 }
2391 });
2392 return result;
2393 }
2394
2395 $scope.choiceValidator = function (field, newChoice) {
2396 var result = true;
2397 var message = "";
2398 if (newChoice.label.length == 0) {
2399 result = false;
2400 message = "Label is mandatory.";
2401 $scope.errors.choice.label = message;
2402 }
2403
2404 if (!$scope.choiceValueIsUnique(field, newChoice)) {
2405 result = false;
2406 message = "Value must be unique.";
2407 $scope.errors.choice.value = message;
2408 }
2409
2410 return result;
2411 }
2412
2413 $scope.addChoice = function (field) {
2414 $scope.errors.choice = {};
2415 if ($scope.choiceValidator(field, $scope.newChoice)) {
2416 var newChoice = angular.copy($scope.newChoice);
2417 var order = 0;
2418 angular.forEach(field.choiceList, function (choice, index) {
2419 if (choice.order > order) {
2420 order = angular.copy(choice.order);
2421 }
2422 });
2423 newChoice.id = newChoice.order = order + 1;
2424 field.choiceList.push(newChoice);
2425 $scope.newChoice = {
2426 'id': 0,
2427 'order': 0,
2428 'value': '',
2429 'label': ''
2430 };
2431 }
2432 };
2433
2434 $scope.deleteChoice = function (choiceToDelete, field) {
2435 var order = angular.copy(choiceToDelete.order);
2436 var choiceIndex = null
2437 angular.forEach(field.choiceList, function (choice, index) {
2438 if (choice.value == choiceToDelete.value) {
2439 //Manage default choice deleted
2440 if (field.defaultChoiceValue == choiceToDelete.value) {
2441 field.defaultChoiceValue = "";
2442 }
2443
2444 choiceIndex = index;
2445 } else if (choice.order > order) {
2446 choice.order -= 1;
2447 }
2448 });
2449 if (choiceIndex != null) {
2450 field.choiceList.splice(choiceIndex, 1);
2451 }
2452 };
2453
2454 // If default value change in list, defaultChoiceValue change too
2455 $scope.defaultChoiceValueHandle = function (originalValue, choice, field) {
2456 if (originalValue == field.defaultChoiceValue) {
2457 field.defaultChoiceValue = choice.value;
2458 }
2459 };
2460
2461 $scope.getDateFormatted = function (format) {
2462 var separator = "/";
2463 var dateFormatArray = format.split(separator);
2464 if (dateFormatArray.length == 1) {
2465 separator = "-";
2466 dateFormatArray = format.split(separator);
2467 }
2468
2469 var today = new Date();
2470
2471 return {
2472 'separator': separator,
2473 'today': {
2474 'd': today.getDate(),
2475 'm': today.getMonth() + 1,
2476 'Y': today.getFullYear()
2477 },
2478 'order': dateFormatArray
2479 };
2480 };
2481
2482 $scope.getSectionType = function (idSection) {
2483 return $scope.form.sections.find(x => x.id == idSection).type;
2484 }
2485
2486 $scope.getAllOtherSectionGroups = function (idSection, idGroup) {
2487 var allGroups = $scope.form.sections.find(x => x.id == idSection).groups;
2488 var groupsToReturn = [];
2489 angular.forEach(allGroups, function (group, indexG) {
2490 if (group.id != idGroup)
2491 groupsToReturn.push(group.id);
2492 });
2493 return groupsToReturn;
2494 }
2495
2496 $scope.getTypeNextField = function (group, field) {
2497 var lastField = group.fields.find(x => x.order === field.order + 1);
2498 var lastFieldType = null;
2499 if (lastField !== undefined) {
2500 lastFieldType = lastField.type;
2501 }
2502 return lastFieldType;
2503 }
2504
2505 $scope.toggleAddAdvancedConfiguration = function () {
2506 $("#glyphiconAddAdvancedConfiguration").toggle();
2507 $("#textAddAdvancedConfiguration").toggle();
2508 }
2509
2510 $scope.toggleEditAdvancedConfiguration = function () {
2511 $("#glyphiconEditAdvancedConfiguration").toggle();
2512 $("#textEditAdvancedConfiguration").toggle();
2513 }
2514
2515 //idGroup : group destinataire
2516 $scope.changeGroupField = function (idGroup, field) {
2517 $scope.deleteField();
2518 field.groupId = idGroup;
2519 angular.forEach($scope.form.sections, function (section, keyS) {
2520 //field.sectionId : nom de section(id)
2521 //section.id : nom de la section concerné
2522 if (field.sectionId == section.id) {
2523 angular.forEach(section.groups, function (group, keyG) {
2524 if (idGroup == group.id) {
2525 field.order = group.fields.length + 1;
2526 }
2527 });
2528 }
2529 });
2530 //field.id = id ;
2531 //$scope.addField(field.id);
2532 $scope.addField(field);
2533 $("#editField").modal('hide');
2534 $scope.save();
2535 }
2536 }
2537 ])
2538
2539 .controller('behaviorCtrl', ['$scope', 'UserService', 'FormService', '$location', '$compile',
2540 function ($scope, UserService, FormService, $location, $compile) {
2541 $scope.$on('initBehavior', function (event) {
2542 $scope.init();
2543 });
2544
2545 // MAIN
2546 $scope.init = function () {
2547 $scope.linkedBehaviours = [];
2548 $scope.freeTerms = [];
2549 $scope.refFieldTerm = {};
2550 $scope.hasInitProductTerms = false;
2551 $scope.newTerm = {};
2552 $scope.newBehavior = {};
2553
2554 $scope.selectedTerm = {};
2555 $scope.selectedBehavior = {};
2556
2557 $scope.disableOr = false;
2558
2559 $scope.errors = {
2560 'term': {},
2561 'behavior': {}
2562 }
2563 $scope.productInitConditions= [
2564 {
2565 'label': 'Category',
2566 'value': 'CATEGORY',
2567 },
2568 {
2569 'label': 'Ref produit',
2570 'value': 'REF_PRODUIT',
2571 },
2572 {
2573 'label': 'Sku',
2574 'value': 'SKU',
2575 },
2576 {
2577 'label': 'Brand',
2578 'value': 'BRAND_NAME',
2579 }
2580 ];
2581 $scope.operations = [
2582 {
2583 'value': 'less',
2584 'label': 'Inférieur(e) à'
2585 },
2586 {
2587 'value': 'equal',
2588 'label': 'Égale à'
2589 },
2590 {
2591 'value': 'different',
2592 'label': 'Différent(e) à'
2593 },
2594 {
2595 'value': 'greater',
2596 'label': 'Supérieur(e) à'
2597 },
2598 /*{
2599 'value': 'evenoddDay',
2600 'label': 'Dont le jour est (pair/impair)'
2601 },
2602 {
2603 'value': 'lessDay',
2604 'label': 'Dont le jour est antérieur au'
2605 },
2606 {
2607 'value': 'equalDay',
2608 'label': 'Dont le jour correspond au'
2609 },
2610 {
2611 'value': 'differentDay',
2612 'label': 'Dont le jour ne correspond pas au'
2613 },
2614 {
2615 'value': 'greaterDay',
2616 'label': 'Dont le jour est postérieur au'
2617 },
2618 {
2619 'value': 'lessMonth',
2620 'label': 'Dont le mois est antérieur à'
2621 },
2622 {
2623 'value': 'equalMonth',
2624 'label': 'Dont le mois correspond à'
2625 },
2626 {
2627 'value': 'differentMonth',
2628 'label': 'Dont le mois ne correspond pas à'
2629 },
2630 {
2631 'value': 'greaterMonth',
2632 'label': 'Dont le mois est postérieur à'
2633 },
2634 {
2635 'value': 'lessYear',
2636 'label': 'Dont l\'année est antérieure à'
2637 },
2638 {
2639 'value': 'equalYear',
2640 'label': 'Dont l\'année correspond à'
2641 },
2642 {
2643 'value': 'differentYear',
2644 'label': 'Dont l\'année ne correspond pas à'
2645 },
2646 {
2647 'value': 'greaterYear',
2648 'label': 'Dont l\'année est postérieure au'
2649 }*/
2650 ];
2651
2652 $scope.termMapping = {
2653 'order': [{
2654 'id': 'RATE',
2655 'label': 'rate',
2656 'eav': '#RATE=I1',
2657 'type': 'rate'
2658 }],
2659 'product': []
2660 };
2661
2662 if ($scope.form.enableProductsReview) {
2663 $scope.termMapping.product.push({
2664 'id': 'productRate',
2665 'label': 'productRate',
2666 'eav': '!#RATE=I1',
2667 'type': 'rate'
2668 })
2669 }
2670
2671 angular.forEach($scope.form.orderMapping, function (map, indexM) {
2672 if (map.type != 'text' && map.type != 'textarea' && map.type != 'date') {
2673 $scope.termMapping.order.push(map);
2674 }
2675 });
2676
2677 angular.forEach($scope.form.productMapping, function (map, indexM) {
2678 if (map.type != 'text' && map.type != 'textarea' && map.type != 'date') {
2679 $scope.termMapping.product.push(map);
2680 }
2681 });
2682
2683 // ELEMENT LIST TO BIND A BEHAVIOR
2684 $scope.elementList = {
2685 'sections': [],
2686 'groups': [],
2687 'fields': []
2688 };
2689
2690 angular.forEach($scope.form.sections, function (section, indexS) {
2691 $scope.elementList.sections.push(section);
2692 angular.forEach(section.groups, function (group, indexG) {
2693 $scope.elementList.groups.push(group);
2694 angular.forEach(group.fields, function (field, indexF) {
2695 $scope.elementList.fields.push(field);
2696 });
2697 });
2698 });
2699 };
2700
2701 //Get list of number with a max number (begin at 1)
2702 $scope.getNumber = function (num) {
2703 num = parseInt(num);
2704 var array = [];
2705 for (i = 1; i <= num; i++) {
2706 array.push(i);
2707 }
2708
2709 return array;
2710 };
2711
2712 $scope.save = function () {
2713 FormService.setForm($scope.form);
2714 //console.log($scope.form.id);
2715 return;
2716 $scope.$emit('addVersion');
2717 };
2718
2719 $scope.termValidator = function (term) {
2720 var result = true;
2721
2722 if (term.data.length == 0) {
2723 result = false;
2724 $scope.errors.term.data = "Data is mandatory.";
2725 }
2726
2727 //no operation
2728 if (term.operation.length == 0) {
2729 result = false;
2730 $scope.errors.term.operation = "Operation is mandatory.";
2731 }
2732
2733 //no value
2734 if (term.value.length == 0) {
2735 result = false;
2736 $scope.errors.term.value = "Value is mandatory";
2737 }
2738
2739 //already exist
2740 angular.forEach($scope.form.terms, function (item, index) {
2741 if (item.data == term.data && item.operation == term.operation && item.value == term.value) {
2742 result = false;
2743 $scope.errors.term.form = "Condition already exists.";
2744 }
2745 });
2746
2747 return result;
2748 };
2749
2750 $scope.getUniqueId = function (prefix, list) {
2751 var id = prefix + list.length;
2752 var loop = 1;
2753 var isUnique = false;
2754 while (!isUnique) {
2755 isUnique = true;
2756 angular.forEach(list, function (term, index) {
2757 if (id == term.id) {
2758 id = prefix + (list.length + loop);
2759 isUnique = false;
2760 }
2761 });
2762 loop++;
2763 }
2764
2765 return id;
2766 }
2767
2768 $scope.getRefField = function (idField, type, isNew) {
2769 if (type === 'event') {
2770 angular.forEach($scope.form.sections, function (section, indexS) {
2771 angular.forEach(section.groups, function (group, indexG) {
2772 angular.forEach(group.fields, function (field, indexF) {
2773 if (field.id == idField) {
2774 $scope.refFieldTerm = angular.copy(field);
2775 if (isNew) {
2776 $scope.newTerm['dataLabel'] = $scope.cleanEAV(field.eav);
2777 $scope.newTerm['dataType'] = field.type;
2778 $scope.newTerm['dataTypeSection'] = group.type;
2779 $scope.newTerm['idCss'] = (field.idCss === undefined || field.idCss.length === 0) ? field.id : field.idCss;
2780 } else {
2781 $scope.selectedTerm['dataLabel'] = $scope.cleanEAV(field.eav);
2782 $scope.selectedTerm['dataType'] = field.type;
2783 $scope.selectedTerm['dataTypeSection'] = group.type;
2784 $scope.selectedTerm['idCss'] = (field.idCss === undefined || field.idCss.length === 0) ? field.id : field.idCss;
2785 }
2786 }
2787 });
2788 });
2789 });
2790
2791 } else {
2792 var isOrderData = false;
2793 angular.forEach($scope.form.inputDataMapping.order, function (orderItem, indexO) {
2794 if (orderItem.id == idField) {
2795 $scope.refFieldTerm = angular.copy(orderItem);
2796 if (isNew) {
2797 $scope.newTerm['dataLabel'] = orderItem.label;
2798 } else {
2799 $scope.selectedTerm['dataLabel'] = orderItem.label;
2800 }
2801 isOrderData = true;
2802 }
2803 });
2804
2805 if (!isOrderData) {
2806 angular.forEach($scope.form.inputDataMapping.product, function (productItem, indexO) {
2807 if (productItem.id == idField) {
2808 $scope.refFieldTerm = angular.copy(productItem);
2809 if (isNew) {
2810 $scope.newTerm['dataLabel'] = productItem.label;
2811 } else {
2812 $scope.selectedTerm['dataLabel'] = productItem.label;
2813 }
2814 }
2815 });
2816 angular.forEach($scope.productInitConditions, function (productInitItem, indexO) {
2817 if (productInitItem.value == idField) {
2818 $scope.refFieldTerm = angular.copy(productInitItem);
2819 if (isNew) {
2820 $scope.newTerm['dataLabel'] = productInitItem.label;
2821 } else {
2822 $scope.selectedTerm['dataLabel'] = productInitItem.label;
2823 }
2824 }
2825 });
2826 }
2827 }
2828
2829 switch ($scope.refFieldTerm.type) {
2830 case 'multichoice':
2831 case 'radio':
2832 case 'list':
2833 case 'received':
2834 $scope.operations = [
2835 {
2836 'value': 'equal',
2837 'label': 'Égale à'
2838 },
2839 {
2840 'value': 'different',
2841 'label': 'Différent(e) à'
2842 }
2843 ];
2844 break;
2845 case 'date':
2846 $scope.operations = {
2847 'day': [
2848 {
2849 'value': 'evenoddDay',
2850 'label': 'Dont le jour est (pair/impair)'
2851 },
2852 {
2853 'value': 'lessDay',
2854 'label': 'Dont le jour est antérieur au'
2855 },
2856 {
2857 'value': 'equalDay',
2858 'label': 'Dont le jour correspond au'
2859 },
2860 {
2861 'value': 'differentDay',
2862 'label': 'Dont le jour ne correspond pas au'
2863 },
2864 {
2865 'value': 'greaterDay',
2866 'label': 'Dont le jour est postérieur au'
2867 }
2868 ],
2869 'month': [
2870 {
2871 'value': 'lessMonth',
2872 'label': 'Dont le mois est antérieur à'
2873 },
2874 {
2875 'value': 'equalMonth',
2876 'label': 'Dont le mois correspond à'
2877 },
2878 {
2879 'value': 'differentMonth',
2880 'label': 'Dont le mois ne correspond pas à'
2881 },
2882 {
2883 'value': 'greaterMonth',
2884 'label': 'Dont le mois est postérieur à'
2885 }
2886 ],
2887 'year': [
2888 {
2889 'value': 'lessYear',
2890 'label': 'Dont l\'année est antérieure à'
2891 },
2892 {
2893 'value': 'equalYear',
2894 'label': 'Dont l\'année correspond à'
2895 },
2896 {
2897 'value': 'differentYear',
2898 'label': 'Dont l\'année ne correspond pas à'
2899 },
2900 {
2901 'value': 'greaterYear',
2902 'label': 'Dont l\'année est postérieure au'
2903 }
2904 ]
2905 };
2906 break;
2907 default:
2908 $scope.operations = [
2909 {
2910 'value': 'less',
2911 'label': 'Inférieur(e) à'
2912 },
2913 {
2914 'value': 'equal',
2915 'label': 'Égale à'
2916 },
2917 {
2918 'value': 'different',
2919 'label': 'Différent(e) à'
2920 },
2921 {
2922 'value': 'greater',
2923 'label': 'Supérieur(e) à'
2924 },
2925 ];
2926 break;
2927 }
2928 };
2929
2930 // TERM
2931 $scope.createTerm = function () {
2932 var type = ($scope.form.inputDataMapping.order.length > 0 || $scope.form.inputDataMapping.product.length > 0) ? '' : 'event';
2933 $scope.newTerm = {
2934 'id': $scope.getUniqueId('term', $scope.form.terms),
2935 'type': type,
2936 'data': '',
2937 'operation': '',
2938 'value': ''
2939 };
2940 };
2941
2942 $scope.addTerm = function () {
2943 if ($scope.termValidator($scope.newTerm)) {
2944 $scope.form.terms.push(angular.copy($scope.newTerm));
2945 $scope.save();
2946 $scope.newTerm = {};
2947 }
2948 };
2949
2950 $scope.editTerm = function () {
2951 if ($scope.termValidator($scope.selectedTerm)) {
2952 angular.forEach($scope.form.terms, function (term, indexT) {
2953 if (term.id == $scope.selectedTerm.id) {
2954 $scope.form.terms[indexT] = angular.copy($scope.selectedTerm);
2955 }
2956 });
2957 }
2958 $scope.save();
2959 $scope.init();
2960 };
2961
2962 $scope.selectTerm = function (term) {
2963 $scope.selectedTerm = angular.copy(term);
2964 $scope.loadLinkedBehaviours(term.id);
2965 };
2966
2967 // BEHAVIOR
2968 // Update free terms list
2969 $scope.loadFreeTerms = function (behavior) {
2970 $scope.freeTerms = angular.copy($scope.form.terms);
2971
2972 var termIdToDelete = [];
2973 angular.forEach($scope.freeTerms, function (term, index) {
2974 if (behavior.terms.indexOf(term.id) !== -1) {
2975 termIdToDelete.push(term.id);
2976 }
2977 });
2978
2979 angular.forEach(termIdToDelete, function (termId, index) {
2980 $scope.freeTerms.splice($scope.freeTerms.findIndex(i => i.id == termId), 1);
2981 });
2982
2983
2984 $scope.disableOr = $scope.hasInitTerms(behavior.terms);
2985 };
2986
2987 $scope.createBehavior = function () {
2988 $scope.newBehavior = {
2989 "id": $scope.getUniqueId('behavior', $scope.form.behaviours),
2990 'terms': [],
2991 "operationTerm": "and",
2992 "elementType": "section",
2993 "elementId": "",
2994 "action": "show"
2995 };
2996
2997 $scope.loadFreeTerms($scope.newBehavior);
2998 };
2999
3000 $scope.selectBehavior = function (behavior) {
3001 $scope.init();
3002 $scope.selectedBehavior = angular.copy(behavior);
3003
3004 $scope.loadFreeTerms($scope.selectedBehavior);
3005 $scope.hasInitProductTerms = $scope.gotProductInitTerms(behavior.terms);
3006
3007 };
3008 $scope.hasProductTerms = function () {
3009
3010 var bool= false;
3011 angular.forEach($scope.selectedBehavior.terms, function (term, indext) {
3012 if (term.type == 'init') {
3013 if (term.data == 'CATEGORY' || term.data == 'REF_PRODUIT' || term.data == 'SKU' || term.data == 'BRAND_NAME') {
3014 bool=true;
3015 return bool;
3016 }
3017 }
3018
3019 });
3020 };
3021 $scope.behaviorValidator = function (behavior) {
3022 var result = true;
3023 if (behavior.terms.length == 0) {
3024 result = false;
3025 $scope.errors.behavior.terms = "You must add at least one condition";
3026 }
3027
3028 if (behavior.elementId.length == 0) {
3029 result = false;
3030 $scope.errors.behavior.elementId = "You must select one element.";
3031 }
3032
3033 return result;
3034 };
3035
3036 $scope.addBehavior = function () {
3037 $scope.errors.behavior = {};
3038 if ($scope.behaviorValidator($scope.newBehavior)) {
3039 $scope.form.behaviours.push(angular.copy($scope.newBehavior));
3040 $scope.save();
3041 $scope.init();
3042 }
3043 };
3044
3045 $scope.getElementTypeSection = function (type, elementId) {
3046 result = 'order';
3047 switch (type) {
3048 case 'section':
3049 var section = $scope.form.sections.find(i => i.id == elementId);
3050 if (section !== undefined) {
3051 result = section.type;
3052 }
3053 break;
3054 case 'group':
3055 angular.forEach($scope.form.sections, function (section, indexS) {
3056 if (section.groups.find(i => i.id == elementId) !== undefined) {
3057 result = section.type;
3058 }
3059 });
3060 break;
3061 case 'field':
3062 angular.forEach($scope.form.sections, function (section, indexS) {
3063 angular.forEach(section.groups, function (group, indexG) {
3064 if (group.fields.find(i => i.id == elementId) !== undefined) {
3065 result = group.type;
3066 }
3067 });
3068 });
3069 break;
3070 }
3071 return result;
3072 };
3073
3074 $scope.editElementTypeSection = function (isNew) {
3075 if (isNew) {
3076 $scope.newBehavior['elementTypeSection'] = $scope.getElementTypeSection($scope.newBehavior.elementType, $scope.newBehavior.elementId);
3077 } else {
3078 $scope.selectedBehavior['elementTypeSection'] = $scope.getElementTypeSection($scope.selectedBehavior.elementType, $scope.selectedBehavior.elementId);
3079 }
3080 };
3081
3082 $scope.editBehavior = function () {
3083 $scope.errors.behavior = {};
3084 if ($scope.behaviorValidator($scope.selectedBehavior)) {
3085 angular.forEach($scope.form.behaviours, function (behavior, indexB) {
3086 if (behavior.id == $scope.selectedBehavior.id) {
3087 $scope.form.behaviours[indexB] = angular.copy($scope.selectedBehavior);
3088 }
3089 });
3090 $scope.save();
3091 $scope.init();
3092 }
3093 };
3094
3095 $scope.associateTerm = function (termId, behavior) {
3096 $scope.errors.behavior = {};
3097 var indexTerm = null;
3098 ;
3099 angular.forEach($scope.freeTerms, function (term, index) {
3100 if (termId == term.id) {
3101 behavior.terms.push(termId);
3102 indexTerm = index;
3103 }
3104 });
3105 if (indexTerm != null) {
3106 $scope.freeTerms.splice(indexTerm, 1);
3107 }
3108 $scope.hasInitProductTerms = $scope.gotProductInitTerms(behavior.terms);
3109 };
3110
3111 $scope.dissociateTerm = function (termIdToDelete, behavior) {
3112 var indexToDelete = behavior.terms.findIndex(i => i == termIdToDelete);
3113
3114 if (indexToDelete !== -1) {
3115 behavior.terms.splice(indexToDelete, 1);
3116
3117 if (behavior.terms.length === 0) {
3118 $scope.deleteBehavior(behavior.id);
3119 }
3120 }
3121
3122 $scope.loadFreeTerms(behavior);
3123 $scope.hasInitProductTerms = $scope.gotProductInitTerms(behavior.terms);
3124
3125 };
3126
3127 $scope.deleteTerm = function (termIdToDelete) {
3128 if ($scope.form.behaviours.length > 0) {
3129 angular.forEach($scope.form.behaviours, function (behavior, indexB) {
3130 $scope.dissociateTerm(termIdToDelete, behavior);
3131 });
3132 }
3133
3134 $scope.form.terms.splice($scope.form.terms.findIndex(i => i.id == termIdToDelete), 1);
3135 $scope.save();
3136 $scope.init();
3137 };
3138
3139 $scope.deleteBehavior = function (behaviorId) {
3140 $scope.form.behaviours.splice($scope.form.behaviours.findIndex(i => i.id == behaviorId), 1);
3141 $scope.save();
3142 $scope.init();
3143 };
3144
3145 $scope.loadLinkedBehaviours = function (termId) {
3146 $scope.linkedBehaviours = [];
3147 angular.forEach($scope.form.behaviours, function (behavior, indexB) {
3148 angular.forEach(behavior.terms, function (term, indexT) {
3149 if (term == termId) {
3150 $scope.linkedBehaviours.push(angular.copy(behavior));
3151 }
3152 });
3153 });
3154 };
3155
3156 $scope.hasInitTerms = function (terms) {
3157 result = false;
3158
3159 angular.forEach(terms, function (termId, index) {
3160 var term = $scope.form.terms.find(i => i.id == termId);
3161 if (term !== undefined && term.type == 'init') {
3162 result = true;
3163 }
3164 });
3165
3166 return result;
3167 }
3168 $scope.gotProductInitTerms = function (terms) {
3169 var arr=['CATEGORY','REF_PRODUIT','SKU','BRAND_NAME'];
3170 bool= false;
3171 for (let i = 0; i < terms.length; i++) {
3172 var term = $scope.form.terms.find(is => is.id == terms[i]);
3173 if ((arr.includes(term.data) || term.data.indexOf('!') > -1 )&& term.type=='init') {
3174 // console.log('here');
3175 // console.log(term);
3176 bool= true;
3177 break;
3178 }
3179 }
3180
3181 return bool;
3182 };
3183 }
3184 ])
3185
3186 .directive('formRender', function () {
3187 return {
3188 restrict: 'E',
3189 scope: {
3190 form: '=form'
3191 },
3192 templateUrl: '/module/mod_form_builder/template/form/render.php',
3193 link: function (scope, element, attributes) {
3194 element.addClass('col-sm-12');
3195 }
3196 }
3197 })
3198
3199 .filter('int', function () {
3200 return function (input) {
3201 return parseInt(input);
3202 }
3203 })
3204
3205 .filter('operation', function () {
3206 return function (input) {
3207 var operations = [
3208 {
3209 'value': 'less',
3210 'label': 'Inférieur(e) à'
3211 },
3212 {
3213 'value': 'lessOrEqual',
3214 'label': 'Inférieur(e) ou égal(e) à'
3215 },
3216 {
3217 'value': 'equal',
3218 'label': 'Égale à'
3219 },
3220 {
3221 'value': 'different',
3222 'label': 'Différent(e) à'
3223 },
3224 {
3225 'value': 'greaterOrEqual',
3226 'label': 'Supérieur(e) ou égal(e) à'
3227 },
3228 {
3229 'value': 'greater',
3230 'label': 'Supérieur(e) à'
3231 },
3232 ];
3233
3234 var result = "";
3235 angular.forEach(operations, function (operation, index) {
3236 if (input == operation.value) {
3237 result = operation.label;
3238 }
3239 });
3240
3241 return result.toLowerCase();
3242 }
3243 });