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