isite 2022.5.8 → 2022.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1837 @@
1
+ app.directive('iControl', function () {
2
+ return {
3
+ restrict: 'E',
4
+ require: 'ngModel',
5
+ scope: {
6
+ v: '@',
7
+ id2: '@',
8
+ label: '@',
9
+ type: '@',
10
+ class2: '@',
11
+ disabled: '@',
12
+ ngModel: '=',
13
+ ngChange: '&',
14
+ ngKeydown: '&',
15
+ },
16
+ link: function ($scope, element, attrs, ctrl) {
17
+ attrs.type = attrs.type || 'text';
18
+ $scope.id2 = $scope.id2 || 'input_' + Math.random().toString().replace('0.', '');
19
+
20
+ if (typeof attrs.disabled !== 'undefined') {
21
+ attrs.disabled = 'disabled';
22
+ } else {
23
+ attrs.disabled = '';
24
+ }
25
+ $scope.class2 = $scope.class2 || '';
26
+ $(element)
27
+ .find('input')
28
+ .focus(() => {
29
+ $('.i-list .dropdown-content').css('display', 'none');
30
+ });
31
+ },
32
+ template: `
33
+ <div class="mb-3 {{class2}}">
34
+ <label for="{{id2}}" class="form-label">{{label}}</label>
35
+ <input id="{{id2}}" ng-disabled="disabled" autofocus v="{{v}}" type="{{type}}" ng-model="ngModel" ng-change="ngChange()" ngKeydown="ngKeydown()" class="form-control" placeholder="{{placeholder}}" aria-label="{{label}}" />
36
+ <div class="invalid-feedback">
37
+
38
+ </div>
39
+ </div>
40
+ `,
41
+ };
42
+ });
43
+
44
+ app.directive('iTextarea', function () {
45
+ return {
46
+ restrict: 'E',
47
+ require: 'ngModel',
48
+ scope: {
49
+ v: '@',
50
+ label: '@',
51
+ id2: '@',
52
+ disabled: '@',
53
+ rows: '@',
54
+ ngModel: '=',
55
+ ngChange: '&',
56
+ },
57
+ link: function ($scope, element, attrs, ctrl) {
58
+ if (typeof attrs.disabled !== 'undefined') {
59
+ attrs.disabled = 'disabled';
60
+ } else {
61
+ attrs.disabled = '';
62
+ }
63
+ $scope.rows = $scope.rows || 4;
64
+ $scope.id2 = $scope.id2 || 'input_' + Math.random().toString().replace('0.', '');
65
+ $(element)
66
+ .find('textarea')
67
+ .focus(() => {
68
+ $('.popup').hide();
69
+ });
70
+ },
71
+ template: `
72
+ <div class="mb-3">
73
+ <label for="{{id2}}" class="form-label">{{label}}</label>
74
+ <textarea ng-disabled="disabled" class="form-control" id="{{id2}}" ng-model="ngModel" ng-change="ngChange()" v="{{v}}" rows="{{rows}}"></textarea>
75
+ </div>
76
+ `,
77
+ };
78
+ });
79
+
80
+ app.directive('iCheckbox', function ($timeout) {
81
+ return {
82
+ restrict: 'E',
83
+ require: 'ngModel',
84
+ scope: {
85
+ label: '@',
86
+ id2: '@',
87
+ ngModel: '=',
88
+ ngChange: '&',
89
+ },
90
+ link: function ($scope, element, attrs, ctrl) {
91
+ if (typeof attrs.disabled !== 'undefined') {
92
+ $scope.disabled = 'disabled';
93
+ } else {
94
+ $scope.disabled = '';
95
+ }
96
+ $scope.id2 = $scope.id2 || 'input_' + Math.random().toString().replace('0.', '');
97
+ $scope.changed = function () {
98
+ $timeout(() => {
99
+ if ($scope.ngChange) {
100
+ $scope.ngChange();
101
+ }
102
+ }, 100);
103
+ };
104
+ },
105
+ template: `
106
+ <div class="form-check">
107
+ <input ng-change="changed()" ng-disabled="disabled" class="form-check-input" type="checkbox" ng-model="ngModel" id="{{id2}}">
108
+ <label class="form-check-label" for="{{id2}}">
109
+ {{label}}
110
+ </label>
111
+ </div>
112
+ `,
113
+ };
114
+ });
115
+
116
+ app.directive('iRadio', function () {
117
+ return {
118
+ restrict: 'E',
119
+ require: 'ngModel',
120
+ scope: {
121
+ label: '@',
122
+ group: '@',
123
+ id2: '@',
124
+ ngModel: '=',
125
+ ngChange: '&',
126
+ },
127
+ link: function ($scope, element, attrs, ctrl) {
128
+ if (typeof attrs.disabled !== 'undefined') {
129
+ attrs.disabled = 'disabled';
130
+ } else {
131
+ attrs.disabled = '';
132
+ }
133
+
134
+ $scope.group = $scope.group || attrs.group || attrs.ngModel.replaceAll('.', '_');
135
+ $scope.id2 = $scope.id2 || 'input_' + Math.random().toString().replace('0.', '');
136
+ },
137
+ template: `
138
+ <div class="form-check">
139
+ <input class="form-check-input" type="radio" ng-change="ngChange()" ng-disabled="disabled" ng-model="ngModel" id="{{id2}}" name="{{group}}" >
140
+ <label class="form-check-label" for="exampleRadios1">
141
+ {{label}}
142
+ </label>
143
+ </div>
144
+
145
+ `,
146
+ };
147
+ });
148
+
149
+ app.directive('iButton', function () {
150
+ return {
151
+ restrict: 'E',
152
+ scope: {
153
+ label: '@',
154
+ type: '@',
155
+ loading: '@',
156
+ click: '&',
157
+ fa: '@',
158
+ },
159
+ link: function ($scope, element, attrs, ctrl) {
160
+ $scope.type = $scope.type || '';
161
+ if ($scope.type.like('*exit*') || $scope.type.like('*close*')) {
162
+ $scope.fa = 'times';
163
+ } else if ($scope.type.like('*view*') || $scope.type.like('*details*')) {
164
+ $scope.fa = 'file';
165
+ } else if ($scope.type.like('*add*') || $scope.type.like('*new*')) {
166
+ $scope.fa = 'plus-circle';
167
+ } else if ($scope.type.like('*update*') || $scope.type.like('*edit*')) {
168
+ $scope.fa = 'edit';
169
+ } else if ($scope.type.like('*save*')) {
170
+ $scope.fa = 'save';
171
+ } else if ($scope.type.like('*delete*') || $scope.type.like('*remove*')) {
172
+ $scope.fa = 'trash';
173
+ } else if ($scope.type.like('*print*')) {
174
+ $scope.fa = 'print';
175
+ } else if ($scope.type.like('*search*')) {
176
+ $scope.fa = 'search';
177
+ } else if ($scope.type.like('*export*') || $scope.type.like('*excel*')) {
178
+ $scope.fa = 'table';
179
+ } else {
180
+ $scope.class = 'btn-primary';
181
+ }
182
+ $scope.$watch('loading', (loading) => {
183
+ if (loading === 'true' ) {
184
+ $scope.busy = true
185
+ } else {
186
+ $scope.busy = false
187
+ }
188
+ });
189
+ },
190
+ template: `
191
+ <button class="btn {{class}}" type="button" ng-click="click()" ng-disabled="busy">
192
+ <span ng-show="busy" class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
193
+ {{label}}
194
+ </button>
195
+ `,
196
+ };
197
+ });
198
+ app.directive('iList', [
199
+ '$interval',
200
+ '$timeout',
201
+ 'isite',
202
+ function ($interval, $timeout, isite) {
203
+ return {
204
+ restrict: 'E',
205
+ require: 'ngModel',
206
+ scope: {
207
+ v: '@',
208
+ label: '@',
209
+ display: '@',
210
+ display2: '@',
211
+ disabled: '@',
212
+ css: '@',
213
+ space: '@',
214
+ primary: '@',
215
+ ngValue: '@',
216
+ ngModel: '=',
217
+ ngSearch: '=',
218
+ ngChange: '&',
219
+ ngAdd: '&',
220
+ items: '=',
221
+ },
222
+ link: function ($scope, element, attrs, ctrl) {
223
+ $scope.display = attrs.display = attrs.display || 'name';
224
+ $scope.primary = attrs.primary = attrs.primary || 'id';
225
+ attrs.space = attrs.space || ' ';
226
+ attrs.ngValue = attrs.ngValue || '';
227
+
228
+ $scope.searchElement = $(element).find('.dropdown .search');
229
+ $scope.popupElement = $(element).find('.dropdown .dropdown-content');
230
+
231
+ if (typeof attrs.disabled !== 'undefined') {
232
+ attrs.disabled = 'disabled';
233
+ } else {
234
+ attrs.disabled = '';
235
+ }
236
+
237
+ if (typeof attrs.ngAdd == 'undefined') {
238
+ $scope.fa_add = 'fa-search';
239
+ } else {
240
+ $scope.fa_add = 'fa-plus';
241
+ }
242
+
243
+ if (typeof attrs.ngSearch == 'undefined') {
244
+ $scope.showSearch = !1;
245
+ } else {
246
+ $scope.showSearch = !0;
247
+ }
248
+
249
+ let input = $(element).find('input');
250
+ $(element).hover(
251
+ () => {
252
+ $scope.popupElement.css('display', 'block');
253
+ },
254
+ () => {
255
+ $scope.popupElement.css('display', 'none');
256
+ }
257
+ );
258
+ $scope.focus = function () {
259
+ $('.i-list .dropdown-content').css('display', 'none');
260
+ $scope.popupElement.css('display', 'block');
261
+ $scope.searchElement.focus();
262
+ };
263
+ $scope.hide = function () {
264
+ $scope.popupElement.css('display', 'none');
265
+ };
266
+
267
+ $scope.getValue = function (item) {
268
+ let v = isite.getValue(item, $scope.display);
269
+ return v || '';
270
+ };
271
+
272
+ $scope.getValue2 = function (item) {
273
+ if ($scope.display2) {
274
+ return isite.getValue(item, $scope.display2) || '';
275
+ }
276
+ return '';
277
+ };
278
+
279
+ $scope.getNgModelValue = function (ngModel) {
280
+ if (ngModel && $scope.display && $scope.ngValue) {
281
+ return isite.getValue(ngModel, $scope.display.replace($scope.ngValue + '.', '')) || '';
282
+ } else if (ngModel && $scope.display) {
283
+ return isite.getValue(ngModel, $scope.display) || '';
284
+ }
285
+ return '';
286
+ };
287
+
288
+ $scope.getNgModelValue2 = function (ngModel) {
289
+ if (ngModel && $scope.display2 && $scope.ngValue) {
290
+ return isite.getValue(ngModel, $scope.display2.replace($scope.ngValue + '.', '')) || '';
291
+ } else if (ngModel && $scope.display2) {
292
+ return isite.getValue(ngModel, $scope.display2) || '';
293
+ }
294
+ return '';
295
+ };
296
+
297
+ $scope.getNgValue = function (item) {
298
+ if (item && $scope.ngValue) {
299
+ return isite.getValue(item, $scope.ngValue);
300
+ }
301
+ return item;
302
+ };
303
+
304
+ $scope.$watch('items', (items) => {
305
+ input.val('');
306
+
307
+ if (items) {
308
+ items.forEach((item) => {
309
+ item.$display = $scope.getValue(item) + attrs.space + $scope.getValue2(item);
310
+ });
311
+ }
312
+
313
+ if (items && $scope.ngModel) {
314
+ items.forEach((item) => {
315
+ if (isite.getValue(item, $scope.primary) == isite.getValue($scope.ngModel, $scope.primary)) {
316
+ $scope.ngModel = item;
317
+ item.$display = $scope.getValue(item) + attrs.space + $scope.getValue2(item);
318
+ input.val(item.$display);
319
+ }
320
+ });
321
+ }
322
+ });
323
+
324
+ $scope.$watch('ngModel', (ngModel) => {
325
+ input.val('');
326
+
327
+ $scope.ngModel = ngModel;
328
+
329
+ if (ngModel) {
330
+ input.val(' ' + $scope.getNgModelValue(ngModel) + attrs.space + $scope.getNgModelValue2(ngModel));
331
+ }
332
+ });
333
+
334
+ $scope.updateModel = function (item) {
335
+ $scope.ngModel = $scope.getNgValue(item, $scope.ngValue);
336
+ input.val($scope.getNgModelValue($scope.ngModel) + attrs.space + $scope.getNgModelValue2($scope.ngModel));
337
+ $timeout(() => {
338
+ $scope.ngChange();
339
+ });
340
+ $scope.hide();
341
+ };
342
+ },
343
+ template: `/*##client-side/sub/i-list2.content.html*/`,
344
+ };
345
+ },
346
+ ]);
347
+ app.directive('iChecklist', [
348
+ '$interval',
349
+ '$timeout',
350
+ function ($interval, $timeout) {
351
+ return {
352
+ restrict: 'E',
353
+ required: 'ngModel',
354
+ scope: {
355
+ label: '@',
356
+ primary: '@',
357
+ display: '@',
358
+ class2: '@',
359
+ ngModel: '=',
360
+ items: '=',
361
+ like: '&',
362
+ ngChange: '&',
363
+ },
364
+ link: function ($scope, element, attrs, ctrl) {
365
+ $scope.primary = $scope.primary || 'id';
366
+ $scope.display = $scope.display || 'name';
367
+ $scope.class2 = $scope.class2 || 'col3';
368
+ $scope.selectedItems = [];
369
+
370
+ $scope.$watch('ngModel', (ngModel) => {
371
+ $scope.reload();
372
+ });
373
+
374
+ $scope.reload = function () {
375
+ $scope.selectedItems = [];
376
+
377
+ if ($scope.ngModel) {
378
+ $scope.ngModel.forEach((mitem) => {
379
+ $scope.selectedItems.push(mitem);
380
+ });
381
+
382
+ if ($scope.items) {
383
+ $scope.items.forEach((mitem) => {
384
+ let exist = !1;
385
+ $scope.selectedItems.forEach((sitem) => {
386
+ if (mitem[$scope.primary] === sitem[$scope.primary]) {
387
+ exist = !0;
388
+ }
389
+ });
390
+ if (exist) {
391
+ mitem.$selected = !0;
392
+ } else {
393
+ mitem.$selected = !1;
394
+ }
395
+ });
396
+ }
397
+ }
398
+ if (!$scope.ngModel) {
399
+ $scope.selectedItems = [];
400
+ if ($scope.items) {
401
+ $scope.items.forEach((mitem) => {
402
+ mitem.$selected = !1;
403
+ });
404
+ }
405
+ }
406
+ };
407
+
408
+ $scope.change = function (item) {
409
+ if (item.$selected) {
410
+ let exsits = !1;
411
+ $scope.selectedItems.forEach((sitem) => {
412
+ if (sitem[$scope.primary] === item[$scope.primary]) {
413
+ exsits = !0;
414
+ }
415
+ });
416
+ if (!exsits) {
417
+ let nitem = { ...item };
418
+ delete nitem.$selected;
419
+ delete nitem.$$hashKey;
420
+ $scope.selectedItems.push(nitem);
421
+ }
422
+ } else {
423
+ $scope.selectedItems.forEach((sitem, index) => {
424
+ if (sitem[$scope.primary] === item[$scope.primary]) {
425
+ $scope.selectedItems.splice(index, 1);
426
+ }
427
+ });
428
+ }
429
+
430
+ $scope.ngModel = $scope.selectedItems;
431
+ $timeout(() => {
432
+ if ($scope.ngChange) {
433
+ $scope.ngChange();
434
+ }
435
+ }, 100);
436
+ };
437
+ },
438
+ template: `
439
+ <div class="check-list">
440
+ <label class="title margin"> {{label}} </label>
441
+ <div class="row">
442
+ <i-checkbox class="{{class2}}" label="{{item[display]}}" ng-repeat="item in items" ng-model="item.$selected" ng-change="change(item);"></i-checkbox>
443
+ </div>
444
+ </div>
445
+ `,
446
+ };
447
+ },
448
+ ]);
449
+ app.directive('iDate', function () {
450
+ return {
451
+ link: function (scope, element, attrs) {
452
+ if (typeof attrs.disabled !== 'undefined') {
453
+ attrs.disabled = 'disabled';
454
+ } else {
455
+ attrs.disabled = '';
456
+ }
457
+
458
+ $(element)
459
+ .find('select')
460
+ .focus(() => {
461
+ $('.popup').hide();
462
+ });
463
+
464
+ scope.days1 = [];
465
+ for (let i = 1; i < 32; i++) {
466
+ scope.days1.push(i);
467
+ }
468
+ scope.years1 = [];
469
+ for (let i = 1900; i < 2100; i++) {
470
+ scope.years1.push(i);
471
+ }
472
+ scope.monthes1 = ['يناير', 'فبراير', 'مارس', 'ابريل', 'مايو', 'يونيو', 'يوليو', 'اغسطس', 'سبتمبر', 'اكتوبر', 'نوفمبر', 'ديسمبر'];
473
+ },
474
+ restrict: 'E',
475
+ require: 'ngModel',
476
+ scope: {
477
+ v: '@',
478
+ label: '@',
479
+ disabled: '@',
480
+ ngModel: '=',
481
+ },
482
+ template: `
483
+ <div class="row i-date">
484
+
485
+ <div class=" control">
486
+ <label> {{label}} </label>
487
+ <div class="row">
488
+ <div class="col3 day">
489
+ <select ng-disabled="disabled" v="{{v}}" ng-model="ngModel.day" class="appearance-none no-border-left no-border-radius" >
490
+ <option ng-repeat="d1 in days1" ng-value="d1"> {{d1}} </option>
491
+ </select>
492
+ </div>
493
+ <div class="col5 month">
494
+ <select ng-disabled="disabled" v="{{v}}" ng-model="ngModel.month" class="appearance-none no-border-left no-border-right no-border-radius" >
495
+ <option ng-repeat="m1 in monthes1" ng-value="$index"> {{m1}} </option>
496
+ </select>
497
+ </div>
498
+ <div class="col4 year">
499
+ <select ng-disabled="disabled" v="{{v}}" ng-model="ngModel.year" class="appearance-none no-border-right no-border-radius" >
500
+ <option ng-repeat="y1 in years1" ng-value="y1"> {{y1}} </option>
501
+ </select>
502
+ </div>
503
+ </div>
504
+ </div>
505
+
506
+
507
+ </div>
508
+ `,
509
+ };
510
+ });
511
+
512
+ app.directive('iDate2', function () {
513
+ return {
514
+ link: function ($scope, element, attrs) {
515
+ if (typeof attrs.disabled !== 'undefined') {
516
+ attrs.disabled = 'disabled';
517
+ } else {
518
+ attrs.disabled = '';
519
+ }
520
+
521
+ $scope.y_search = attrs.year || '202';
522
+ $scope.m_search = attrs.month || '';
523
+ $scope.d_search = attrs.day || '';
524
+
525
+ $scope.days1 = [];
526
+ for (let i = 1; i < 32; i++) {
527
+ $scope.days1.push({
528
+ id: i,
529
+ name: i,
530
+ });
531
+ }
532
+ $scope.years1 = [];
533
+ for (let i = 1900; i < 2100; i++) {
534
+ $scope.years1.push({
535
+ id: i,
536
+ name: i,
537
+ });
538
+ }
539
+
540
+ $scope.monthes1 = [
541
+ { id: 0, name: 'يناير / Jan' },
542
+ { id: 1, name: 'فبراير / Feb' },
543
+ { id: 2, name: 'مارس / Mar' },
544
+ { id: 3, name: 'ابريل / Aper' },
545
+ { id: 4, name: 'مايو / May' },
546
+ { id: 5, name: 'يونيو / June' },
547
+ { id: 6, name: 'يوليو / Jule' },
548
+ { id: 7, name: 'اغسطس / Aug' },
549
+ { id: 8, name: 'سبتمبر / Sep' },
550
+ { id: 9, name: 'اكتوبر / Oct' },
551
+ { id: 10, name: 'نوفمبر / Nov' },
552
+ { id: 11, name: 'ديسمبر / Des' },
553
+ ];
554
+
555
+ $scope.model = null;
556
+
557
+ $scope.$watch('ngModel', function (ngModel) {
558
+ if (ngModel) {
559
+ ngModel = new Date(ngModel);
560
+ $scope.model = $scope.model || {};
561
+ $scope.model.day = ngModel.getDate();
562
+ $scope.model.day_name = $scope.model.day;
563
+ $scope.model.month = ngModel.getMonth();
564
+ $scope.model.month_name = $scope.monthes1.find((m) => m.id == $scope.model.month).name;
565
+ $scope.model.year = ngModel.getFullYear();
566
+ $scope.model.year_name = $scope.model.year;
567
+ } else {
568
+ $scope.model = $scope.model || {};
569
+ $scope.model.day = 0;
570
+ $scope.model.day_name = '';
571
+ $scope.model.month = -1;
572
+ $scope.model.month_name = '';
573
+ $scope.model.year = 0;
574
+ $scope.model.year_name = '';
575
+ }
576
+ });
577
+
578
+ $scope.setDay = function () {
579
+ $scope.ngModel = new Date();
580
+ };
581
+ $scope.updateDate = function (date) {
582
+ if (date.year) {
583
+ $scope.model.year = date.year.id;
584
+ $scope.model.year_name = date.year.name;
585
+ } else if (date.month) {
586
+ $scope.model.month = date.month.id;
587
+ $scope.model.month_name = date.month.name;
588
+ } else if (date.day) {
589
+ $scope.model.day = date.day.id;
590
+ $scope.model.day_name = date.day.name;
591
+ }
592
+
593
+ if ($scope.model && $scope.model.year && $scope.model.day && $scope.model.month > -1) {
594
+ $scope.ngModel = new Date($scope.model.year, $scope.model.month, $scope.model.day, 0, 0, 0);
595
+ } else {
596
+ delete $scope.ngModel;
597
+ }
598
+ };
599
+ },
600
+ restrict: 'E',
601
+ require: 'ngModel',
602
+ scope: {
603
+ v: '@',
604
+ disabled: '@',
605
+ label: '@',
606
+ ngModel: '=',
607
+ },
608
+ template: `/*##client-side/sub/i-date2.content.html*/`,
609
+ };
610
+ });
611
+
612
+ app.directive('iTime', function () {
613
+ return {
614
+ link: function ($scope, element, attrs) {
615
+ if (typeof attrs.disabled !== 'undefined') {
616
+ attrs.disabled = 'disabled';
617
+ } else {
618
+ attrs.disabled = '';
619
+ }
620
+
621
+ $scope.model = {};
622
+
623
+ $scope.hours = [];
624
+ for (let i = 1; i < 25; i++) {
625
+ $scope.hours.push(i);
626
+ }
627
+
628
+ $scope.minutes = [];
629
+ for (let i = 0; i < 60; i++) {
630
+ $scope.minutes.push(i);
631
+ }
632
+
633
+ $(element)
634
+ .find('select')
635
+ .focus(() => {
636
+ $('.popup').hide();
637
+ });
638
+
639
+ $scope.$watch('ngModel', function (ngModel) {
640
+ if (ngModel) {
641
+ ngModel.date = new Date(ngModel.date);
642
+ $scope.model = $scope.model || {};
643
+ $scope.model.hour = ngModel.hour;
644
+ $scope.model.minute = ngModel.minute;
645
+ } else {
646
+ $scope.model = $scope.model || {};
647
+ $scope.model.hour = 0;
648
+ $scope.model.minute = 0;
649
+ }
650
+ });
651
+
652
+ $scope.updateTime = function () {
653
+ if ($scope.model) {
654
+ $scope.ngModel = $scope.ngModel || {};
655
+ $scope.ngModel.hour = $scope.model.hour;
656
+ $scope.ngModel.minute = $scope.model.minute;
657
+ $scope.ngModel.date = new Date(null, null, null, $scope.model.hour, $scope.model.minute, null);
658
+ } else {
659
+ delete $scope.ngModel;
660
+ }
661
+ };
662
+ },
663
+ restrict: 'E',
664
+ require: 'ngModel',
665
+ scope: {
666
+ v: '@',
667
+ disabled: '@',
668
+ label: '@',
669
+ ngModel: '=',
670
+ },
671
+ template: `
672
+ <div class="row i-time">
673
+ <div class=" control ">
674
+ <label class="text-center"> {{label}} </label>
675
+ <div class="row">
676
+ <div class="col6 right">
677
+ <div class="row">
678
+ <div class="col2"></div>
679
+ <div class="col8">
680
+ <select ng-disabled="disabled" ng-model="model.minute" ng-change="updateTime()" class="small appearance-none no-border-left no-border-radius" >
681
+ <option ng-repeat="m in minutes" ng-value="m"> {{m}}</option>
682
+ </select>
683
+ </div>
684
+ <div class="col2"></div>
685
+ </div>
686
+
687
+ </div>
688
+ <div class="col6">
689
+ <div class="row">
690
+ <div class="col2 space right">
691
+ <span> : </span>
692
+ </div>
693
+ <div class="col8">
694
+ <select ng-disabled="disabled" ng-model="model.hour" ng-change="updateTime()" class="large blue appearance-none no-border-left no-border-radius" >
695
+ <option ng-repeat="h in hours" ng-value="h"> {{h}} </option>
696
+ </select>
697
+ </div>
698
+
699
+ </div>
700
+
701
+ </div>
702
+ </div>
703
+ </div>
704
+ `,
705
+ };
706
+ });
707
+
708
+ app.directive('iDatetime2', function () {
709
+ return {
710
+ link: function ($scope, element, attrs) {
711
+ if (typeof attrs.disabled !== 'undefined') {
712
+ attrs.disabled = 'disabled';
713
+ } else {
714
+ attrs.disabled = '';
715
+ }
716
+
717
+ $scope.hour1 = [];
718
+ for (let i = 1; i < 25; i++) {
719
+ $scope.hour1.push(i);
720
+ }
721
+
722
+ $scope.minute_list = [];
723
+ for (let i = 1; i < 60; i++) {
724
+ $scope.minute_list.push({
725
+ name: i,
726
+ });
727
+ }
728
+
729
+ $scope.days1 = [];
730
+ for (let i = 1; i < 32; i++) {
731
+ $scope.days1.push(i);
732
+ }
733
+ $scope.years1 = [];
734
+ for (let i = 1900; i < 2100; i++) {
735
+ $scope.years1.push(i);
736
+ }
737
+ $scope.monthes1 = ['يناير', 'فبراير', 'مارس', 'ابريل', 'مايو', 'يونيو', 'يوليو', 'اغسطس', 'سبتمبر', 'اكتوبر', 'نوفمبر', 'ديسمبر'];
738
+
739
+ $scope.model = null;
740
+
741
+ $(element)
742
+ .find('select')
743
+ .focus(() => {
744
+ $('.popup').hide();
745
+ });
746
+
747
+ $scope.$watch('ngModel', function (ngModel) {
748
+ if (ngModel) {
749
+ ngModel = new Date(ngModel);
750
+ $scope.model = $scope.model || {};
751
+ $scope.model.hour = ngModel.getHours();
752
+ $scope.model.minute = ngModel.getMinutes();
753
+ $scope.model.day = ngModel.getDate();
754
+ $scope.model.month = ngModel.getMonth();
755
+ $scope.model.year = ngModel.getFullYear();
756
+ } else {
757
+ $scope.model = $scope.model || {};
758
+ $scope.model.hour = 0;
759
+ $scope.model.minute = 0;
760
+ $scope.model.day = 0;
761
+ $scope.model.month = -1;
762
+ $scope.model.year = 0;
763
+ }
764
+ });
765
+
766
+ $scope.updateDate = function () {
767
+ if ($scope.model && $scope.model.year && $scope.model.day) {
768
+ $scope.ngModel = new Date($scope.model.year, $scope.model.month, $scope.model.day, $scope.model.hour, $scope.model.minute);
769
+ } else {
770
+ delete $scope.ngModel;
771
+ }
772
+ };
773
+ },
774
+ restrict: 'E',
775
+ require: 'ngModel',
776
+ scope: {
777
+ v: '@',
778
+ disabled: '@',
779
+ label: '@',
780
+ ngModel: '=',
781
+ },
782
+ template: `
783
+ <div class="row i-datetime2">
784
+
785
+ <div class=" control">
786
+ <label> {{label}} </label>
787
+ <div class="row">
788
+
789
+ <div class="col2 day">
790
+ <select v="{{v}}" ng-disabled="disabled" ng-model="model.day" ng-change="updateDate()" class="appearance-none no-border-left no-border-radius" >
791
+ <option ng-repeat="d1 in days1" ng-value="d1"> {{d1}} </option>
792
+ </select>
793
+ </div>
794
+ <div class="col5 month">
795
+ <select v="{{v}}" ng-disabled="disabled" ng-model="model.month" ng-change="updateDate()" class="appearance-none no-border-left no-border-right no-border-radius" >
796
+ <option ng-repeat="m1 in monthes1" ng-value="$index"> {{m1}} </option>
797
+ </select>
798
+ </div>
799
+ <div class="col3 year">
800
+ <select v="{{v}}" ng-disabled="disabled" ng-model="model.year" ng-change="updateDate()" class="appearance-none no-border-right no-border-radius" >
801
+ <option ng-repeat="y1 in years1" ng-value="y1"> {{y1}} </option>
802
+ </select>
803
+ </div>
804
+
805
+ <div class="col1 hour">
806
+ <select v="{{v}}" ng-disabled="disabled" ng-model="model.hour" ng-change="updateDate()" class="appearance-none no-border-radius" >
807
+ <option ng-repeat="h1 in hour1" ng-value="h1"> {{h1}} </option>
808
+ </select>
809
+ </div>
810
+ <div class="col1 minute">
811
+ <select v="{{v}}" ng-disabled="disabled" ng-model="model.minute" ng-change="updateDate()" class="green appearance-none no-border-right no-border-radius" >
812
+ <option ng-repeat="m1 in minute_list" ng-value="m1.name" class="green"> {{m1.name}} </option>
813
+ </select>
814
+ </div>
815
+
816
+ </div>
817
+ </div>
818
+
819
+
820
+ </div>
821
+ `,
822
+ };
823
+ });
824
+
825
+ app.directive('iMonth2', function () {
826
+ return {
827
+ link: function ($scope, element, attrs) {
828
+ if (typeof attrs.disabled !== 'undefined') {
829
+ attrs.disabled = 'disabled';
830
+ } else {
831
+ attrs.disabled = '';
832
+ }
833
+
834
+ $scope.years = [];
835
+ for (let i = 1900; i < 2100; i++) {
836
+ $scope.years.push(i);
837
+ }
838
+ $scope.monthes = ['يناير', 'فبراير', 'مارس', 'ابريل', 'مايو', 'يونيو', 'يوليو', 'اغسطس', 'سبتمبر', 'اكتوبر', 'نوفمبر', 'ديسمبر'];
839
+
840
+ $scope.model = null;
841
+
842
+ $(element)
843
+ .find('select')
844
+ .focus(() => {
845
+ $('.popup').hide();
846
+ });
847
+
848
+ $scope.$watch('ngModel', function (ngModel) {
849
+ if (ngModel) {
850
+ ngModel = new Date(ngModel);
851
+ $scope.model = $scope.model || {};
852
+ $scope.model.day = 1;
853
+ $scope.model.month = ngModel.getMonth();
854
+ $scope.model.year = ngModel.getFullYear();
855
+ } else {
856
+ $scope.model = $scope.model || {};
857
+ $scope.model.day = 0;
858
+ $scope.model.month = -1;
859
+ $scope.model.year = 0;
860
+ }
861
+ });
862
+
863
+ $scope.updateDate = function () {
864
+ if ($scope.model && $scope.model.year) {
865
+ $scope.ngModel = new Date($scope.model.year, $scope.model.month, 1);
866
+ } else {
867
+ delete $scope.ngModel;
868
+ }
869
+ };
870
+ },
871
+ restrict: 'E',
872
+ require: 'ngModel',
873
+ scope: {
874
+ v: '@',
875
+ label: '@',
876
+ disabled: '@',
877
+ ngModel: '=',
878
+ },
879
+ template: `
880
+ <div class="row i-date2">
881
+
882
+ <div class=" control">
883
+ <label> {{label}} </label>
884
+ <div class="row">
885
+
886
+ <div class="col7 month">
887
+ <select ng-disabled="disabled" v="{{v}}" ng-model="model.month" ng-change="updateDate()" class="appearance-none no-border-left no-border-radius" >
888
+ <option ng-repeat="m1 in monthes" ng-value="$index"> {{m1}} </option>
889
+ </select>
890
+ </div>
891
+
892
+ <div class="col5 year">
893
+ <select ng-disabled="disabled" v="{{v}}" ng-model="model.year" ng-change="updateDate()" class="appearance-none no-border-right no-border-radius" >
894
+ <option ng-repeat="y1 in years" ng-value="y1"> {{y1}} </option>
895
+ </select>
896
+ </div>
897
+
898
+ </div>
899
+ </div>
900
+
901
+
902
+ </div>
903
+ `,
904
+ };
905
+ });
906
+
907
+ app.directive('iFulldate', [
908
+ '$http',
909
+ function ($http) {
910
+ return {
911
+ link: function ($scope, element, attrs, ngModel) {
912
+ let _busy = !1;
913
+
914
+ if (typeof attrs.disabled !== 'undefined') {
915
+ attrs.disabled = 'disabled';
916
+ } else {
917
+ attrs.disabled = '';
918
+ }
919
+
920
+ $(element)
921
+ .find('select')
922
+ .focus(() => {
923
+ $('.popup').hide();
924
+ });
925
+
926
+ $scope.days1 = [];
927
+ for (let i = 1; i < 32; i++) {
928
+ $scope.days1.push(i);
929
+ }
930
+ $scope.years1 = [];
931
+ for (let i = 1950; i < 2030; i++) {
932
+ $scope.years1.push(i);
933
+ }
934
+
935
+ $scope.monthes1 = ['يناير', 'فبراير', 'مارس', 'ابريل', 'مايو', 'يونيو', 'يوليو', 'اغسطس', 'سبتمبر', 'اكتوبر', 'نوفمبر', 'ديسمبر'];
936
+
937
+ $scope.days2 = [];
938
+ for (let i = 1; i < 31; i++) {
939
+ $scope.days2.push(i);
940
+ }
941
+ $scope.years2 = [];
942
+ for (let i = 1370; i < 1450; i++) {
943
+ $scope.years2.push(i);
944
+ }
945
+ $scope.monthes2 = ['محرم', 'صفر', 'ربيع اول', 'ربيع ثان', 'جمادى اول', 'جمادى ثان', 'رجب', 'شعبان', 'رمضان', 'شوال', 'ذى القعدة', 'ذى الحجة'];
946
+
947
+ $scope.model = {};
948
+
949
+ $scope.$watch('ngModel', function (ngModel) {
950
+ if (ngModel) {
951
+ $scope.model = ngModel;
952
+ } else {
953
+ $scope.model = {};
954
+ }
955
+ });
956
+
957
+ $scope.$watch('ngModel.date', function (date) {
958
+ if (date) {
959
+ if (typeof date == 'string') {
960
+ date = new Date(date);
961
+ }
962
+ $scope.model = $scope.model || {};
963
+ $scope.model.date = date;
964
+ $scope.model.day = date.getDate();
965
+ $scope.model.month = date.getMonth();
966
+ $scope.model.year = date.getFullYear();
967
+ $scope.get_hijri_date();
968
+ }
969
+ });
970
+
971
+ $scope.get_hijri_date = function () {
972
+ if ($scope.model && $scope.model.year && $scope.model.day) {
973
+ ngModel.$setViewValue($scope.model);
974
+ if (_busy) {
975
+ return;
976
+ }
977
+ _busy = !0;
978
+ $scope.model.date = new Date($scope.model.year, $scope.model.month, $scope.model.day);
979
+ $http({
980
+ method: 'POST',
981
+ url: '/api/get_hijri_date',
982
+ data: {
983
+ date: $scope.model.year + '/' + ($scope.model.month + 1) + '/' + $scope.model.day,
984
+ },
985
+ })
986
+ .then((response) => {
987
+ if (response.data.done) {
988
+ $scope.model.hijri = response.data.hijri;
989
+ $scope.model.day2 = parseInt($scope.model.hijri.split('/')[2]);
990
+ $scope.model.month2 = parseInt($scope.model.hijri.split('/')[1]) - 1;
991
+ $scope.model.year2 = parseInt($scope.model.hijri.split('/')[0]);
992
+ ngModel.$setViewValue($scope.model);
993
+ _busy = !1;
994
+ }
995
+ })
996
+ .catch(() => {
997
+ _busy = !1;
998
+ });
999
+ }
1000
+ };
1001
+
1002
+ $scope.get_normal_date = function () {
1003
+ if ($scope.model && $scope.model.year2 && $scope.model.day2) {
1004
+ ngModel.$setViewValue($scope.model);
1005
+ if (_busy) {
1006
+ return;
1007
+ }
1008
+ _busy = !0;
1009
+ $http({
1010
+ method: 'POST',
1011
+ url: '/api/get_normal_date',
1012
+ data: {
1013
+ hijri: $scope.model.year2 + '/' + ($scope.model.month2 + 1) + '/' + $scope.model.day2,
1014
+ },
1015
+ })
1016
+ .then((response) => {
1017
+ if (response.data.done) {
1018
+ $scope.model.date = new Date(response.data.date);
1019
+ $scope.model.day = parseInt(response.data.date.split('/')[2]);
1020
+ $scope.model.month = parseInt(response.data.date.split('/')[1]) - 1;
1021
+ $scope.model.year = parseInt(response.data.date.split('/')[0]);
1022
+ ngModel.$setViewValue($scope.model);
1023
+ _busy = !1;
1024
+ }
1025
+ })
1026
+ .catch(() => {
1027
+ _busy = !1;
1028
+ });
1029
+ }
1030
+ };
1031
+ },
1032
+ restrict: 'E',
1033
+ require: 'ngModel',
1034
+ scope: {
1035
+ v: '@',
1036
+ label1: '@',
1037
+ label2: '@',
1038
+ disabled: '@',
1039
+ ngModel: '=',
1040
+ ngChange: '&',
1041
+ },
1042
+ template: `
1043
+ <div class="row i-date">
1044
+
1045
+ <div class="col6 control">
1046
+ <label> {{label1}} </label>
1047
+ <div class="row">
1048
+ <div class="col3 day">
1049
+ <select ng-change="get_hijri_date()" ng-disabled="disabled" v="{{v}}" ng-model="model.day" class="appearance-none no-border-left no-border-radius">
1050
+ <option ng-repeat="d1 in days1" ng-value="d1"> {{d1}} </option>
1051
+ </select>
1052
+ </div>
1053
+ <div class="col5 month">
1054
+ <select ng-change="get_hijri_date()" ng-disabled="disabled" v="{{v}}" ng-model="model.month" class="appearance-none no-border-left no-border-right no-border-radius">
1055
+ <option ng-repeat="m1 in monthes1" ng-value="$index"> {{m1}} </option>
1056
+ </select>
1057
+ </div>
1058
+ <div class="col4 year">
1059
+ <select ng-change="get_hijri_date()" ng-disabled="disabled" v="{{v}}" ng-model="model.year" class="appearance-none no-border-right no-border-radius">
1060
+ <option ng-repeat="y1 in years1" ng-value="y1"> {{y1}} </option>
1061
+ </select>
1062
+ </div>
1063
+ </div>
1064
+ </div>
1065
+
1066
+ <div class="col6 control">
1067
+ <label> {{label2}} </label>
1068
+ <div class="row">
1069
+ <div class="col3 day">
1070
+ <select ng-change="get_normal_date()" ng-disabled="disabled" v="{{v}}" ng-model="model.day2" class="appearance-none no-border-left no-border-radius">
1071
+ <option ng-repeat="d2 in days2" ng-value="d2"> {{d2}} </option>
1072
+ </select>
1073
+ </div>
1074
+ <div class="col5 month">
1075
+ <select ng-change="get_normal_date()" ng-disabled="disabled" v="{{v}}" ng-model="model.month2" class="appearance-none no-border-left no-border-right no-border-radius">
1076
+ <option ng-repeat="m2 in monthes2" ng-value="$index"> {{m2}} </option>
1077
+ </select>
1078
+ </div>
1079
+ <div class="col4 year">
1080
+ <select ng-change="get_normal_date()" ng-disabled="disabled" v="{{v}}" ng-model="model.year2" class="appearance-none no-border-right no-border-radius">
1081
+ <option ng-repeat="y2 in years2" ng-value="y2"> {{y2}} </option>
1082
+ </select>
1083
+ </div>
1084
+ </div>
1085
+ </div>
1086
+
1087
+ </div>
1088
+ `,
1089
+ };
1090
+ },
1091
+ ]);
1092
+
1093
+ app.directive('iChecklist2', [
1094
+ '$interval',
1095
+ function ($interval) {
1096
+ return {
1097
+ restrict: 'E',
1098
+ required: 'ngModel',
1099
+ scope: {
1100
+ label: '@',
1101
+ primary: '@',
1102
+ display: '@',
1103
+ ngModel: '=',
1104
+ items: '=',
1105
+ like: '&',
1106
+ },
1107
+ link: function ($scope, element, attrs, ctrl) {
1108
+ attrs.primary = attrs.primary || 'id';
1109
+
1110
+ $scope.selectedItems = [];
1111
+
1112
+ $scope.$watch('ngModel', (ngModel) => {
1113
+ $scope.reload();
1114
+ });
1115
+
1116
+ $scope.reload = function () {
1117
+ $scope.selectedItems = [];
1118
+
1119
+ if ($scope.ngModel) {
1120
+ $scope.ngModel.forEach((mitem) => {
1121
+ $scope.selectedItems.push(mitem);
1122
+ });
1123
+
1124
+ if ($scope.items) {
1125
+ $scope.items.forEach((mitem) => {
1126
+ let exist = !1;
1127
+ $scope.selectedItems.forEach((sitem) => {
1128
+ if (mitem[$scope.primary] === sitem[$scope.primary]) {
1129
+ exist = !0;
1130
+ }
1131
+ });
1132
+ if (exist) {
1133
+ mitem.$selected = !0;
1134
+ } else {
1135
+ mitem.$selected = !1;
1136
+ }
1137
+ });
1138
+ }
1139
+ }
1140
+ if (!$scope.ngModel) {
1141
+ $scope.selectedItems = [];
1142
+ if ($scope.items) {
1143
+ $scope.items.forEach((mitem) => {
1144
+ mitem.$selected = !1;
1145
+ });
1146
+ }
1147
+ }
1148
+ };
1149
+
1150
+ $scope.change = function (item) {
1151
+ if (item.$selected) {
1152
+ let exsits = !1;
1153
+ $scope.selectedItems.forEach((sitem) => {
1154
+ if (sitem[$scope.primary] === item[$scope.primary]) {
1155
+ exsits = !0;
1156
+ }
1157
+ });
1158
+ if (!exsits) {
1159
+ $scope.selectedItems.push(item);
1160
+ }
1161
+ } else {
1162
+ $scope.selectedItems.forEach((sitem, index) => {
1163
+ if (sitem[$scope.primary] === item[$scope.primary]) {
1164
+ $scope.selectedItems.splice(index, 1);
1165
+ }
1166
+ });
1167
+ }
1168
+
1169
+ $scope.ngModel = $scope.selectedItems;
1170
+ };
1171
+ },
1172
+ template: `
1173
+ <div class="row padding check-list">
1174
+ <label class="title"> {{label}} </label>
1175
+ <div class="control" ng-repeat="item in items">
1176
+ <label class="checkbox" >
1177
+ <span > {{item[display]}} </span>
1178
+ <input type="checkbox" ng-model="item.$selected" ng-change="change(item)" >
1179
+ <span class="checkmark"></span>
1180
+ </label>
1181
+ </div>
1182
+ </div>
1183
+ `,
1184
+ };
1185
+ },
1186
+ ]);
1187
+
1188
+ app.directive('iRadiolist', [
1189
+ '$interval',
1190
+ function ($interval) {
1191
+ return {
1192
+ restrict: 'E',
1193
+ required: 'ngModel',
1194
+ scope: {
1195
+ label: '@',
1196
+ display: '@',
1197
+ ngModel: '=',
1198
+ items: '=',
1199
+ },
1200
+ link: function (scope, element, attrs) {
1201
+ scope.model = scope.ngModel;
1202
+
1203
+ scope.code = 'radio_' + Math.random();
1204
+
1205
+ scope.change = function (item) {
1206
+ scope.ngModel = item;
1207
+ };
1208
+
1209
+ scope.isChecked = function (item) {
1210
+ if (item && scope.ngModel && scope.ngModel.id === item.id) {
1211
+ return !0;
1212
+ }
1213
+ return !1;
1214
+ };
1215
+ },
1216
+ template: `
1217
+ <div class="row padding radio-list">
1218
+ <label class="title"> {{label}} </label>
1219
+ <div class="control" ng-repeat="item in items">
1220
+ <label class="radio" >
1221
+ <span > {{item[display]}} </span>
1222
+ <input name="{{code}}" type="radio" ng-model="model" ng-checked="isChecked(item)" ng-click="change(item)" ng-change="change(item)" >
1223
+ <span class="checkmark"></span>
1224
+ </label>
1225
+ </div>
1226
+ </div>
1227
+ `,
1228
+ };
1229
+ },
1230
+ ]);
1231
+
1232
+ app.directive('iFile', [
1233
+ '$interval',
1234
+ 'isite',
1235
+ function ($interval, isite) {
1236
+ return {
1237
+ restrict: 'E',
1238
+ required: 'ngModel',
1239
+ scope: {
1240
+ label: '@',
1241
+ folder: '@',
1242
+ ngModel: '=',
1243
+ ngClick: '&',
1244
+ onSelected: '&',
1245
+ },
1246
+ link: function ($scope, element, attrs, ctrl) {
1247
+ $scope.label = $scope.label || 'Select File to Upload';
1248
+ let input = $(element).find('input')[0];
1249
+ let button = $(element).find('button')[0];
1250
+ if (attrs.view === '') {
1251
+ $scope.viewOnly = !0;
1252
+ }
1253
+ let progress = $(element).find('.progress')[0];
1254
+ $(progress).hide();
1255
+ $scope.folder = $scope.folder || 'default';
1256
+ $scope.id = Math.random().toString().replace('.', '_');
1257
+ if (attrs.view !== '') {
1258
+ button.addEventListener('click', function () {
1259
+ input.click();
1260
+ });
1261
+ }
1262
+
1263
+ input.addEventListener('change', function () {
1264
+ isite.uploadFile(
1265
+ this.files,
1266
+ {
1267
+ folder: $scope.folder,
1268
+ },
1269
+ (err, file, e) => {
1270
+ if (e) {
1271
+ $(progress).show();
1272
+ $scope.value = (e.loaded / e.total) * 100;
1273
+ $scope.max = e.total;
1274
+ if ($scope.value === 100) {
1275
+ $(progress).hide();
1276
+ }
1277
+ }
1278
+
1279
+ if (file) {
1280
+ $scope.ngModel = file;
1281
+ console.log(file);
1282
+ }
1283
+ }
1284
+ );
1285
+ $scope.ngModel = this.files[0].path;
1286
+ $scope.onSelected(this.files[0].path);
1287
+ $scope.$applyAsync();
1288
+ });
1289
+
1290
+ $scope.$watch('ngModel', (ngModel) => {
1291
+ if (ngModel) {
1292
+ a.setAttribute('url', ngModel);
1293
+ }
1294
+ });
1295
+ },
1296
+ template: `/*##client-side/sub/i-file.content.html*/`,
1297
+ };
1298
+ },
1299
+ ]);
1300
+
1301
+ app.directive('iImage', [
1302
+ '$interval',
1303
+ 'isite',
1304
+ function ($interval, isite) {
1305
+ return {
1306
+ restrict: 'E',
1307
+ required: 'ngModel',
1308
+ scope: {
1309
+ folder: '@',
1310
+ ngModel: '=',
1311
+ ngClick: '&',
1312
+ },
1313
+ link: function ($scope, element, attrs, ctrl) {
1314
+ $scope.folder = $scope.folder || 'default';
1315
+
1316
+ let input = $(element).find('input')[0];
1317
+ let img = $(element).find('img')[0];
1318
+ let progress = $(element).find('.progress')[0];
1319
+ $(progress).hide();
1320
+
1321
+ if (attrs.view !== '') {
1322
+ img.addEventListener('click', function () {
1323
+ input.click();
1324
+ });
1325
+ }
1326
+
1327
+ input.addEventListener('change', function () {
1328
+ isite.uploadImage(
1329
+ this.files,
1330
+ {
1331
+ folder: $scope.folder,
1332
+ },
1333
+ (err, image, e) => {
1334
+ if (e) {
1335
+ $(progress).show();
1336
+ $scope.value = (e.loaded / e.total) * 100;
1337
+ $scope.max = e.total;
1338
+ if ($scope.value === 100) {
1339
+ $(progress).hide();
1340
+ }
1341
+ }
1342
+
1343
+ if (image) {
1344
+ $scope.ngModel = image;
1345
+ }
1346
+ }
1347
+ );
1348
+ });
1349
+
1350
+ $scope.$watch('ngModel', (ngModel) => {
1351
+ if (ngModel) {
1352
+ img.setAttribute('src', ngModel.url);
1353
+ }
1354
+ });
1355
+ },
1356
+ template: `
1357
+ <div class=" text-center pointer">
1358
+ <input class="hidden" type="file" name="fileToUpload" accept="image/*"/>
1359
+ <img class="rounded" ng-src="{{ngModel.url}}" ngClick="ngClick()" onerror="this.src='/images/no.jpg'" />
1360
+ <div class="progress row">
1361
+ <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="{{value}}" aria-valuemin="0" aria-valuemax="100" style="width: {{value}}%"></div>
1362
+ </div>
1363
+ </div>
1364
+ `,
1365
+ };
1366
+ },
1367
+ ]);
1368
+
1369
+ app.directive('iUpload', [
1370
+ '$interval',
1371
+ 'isite',
1372
+ function ($interval, isite) {
1373
+ return {
1374
+ restrict: 'E',
1375
+ required: 'ngModel',
1376
+ scope: {
1377
+ label: '@',
1378
+ api: '@',
1379
+ type: '@',
1380
+ ngModel: '=',
1381
+ ngClick: '&',
1382
+ onUploaded: '&',
1383
+ },
1384
+ link: function (scope, element, attrs, ctrl) {
1385
+ scope.type = scope.type || 'bg-green';
1386
+
1387
+ let input = $(element).find('input')[0];
1388
+ let a = $(element).find('a')[0];
1389
+ let progress = $(element).find('progress')[0];
1390
+ $(progress).hide();
1391
+
1392
+ if (attrs.view !== '') {
1393
+ a.addEventListener('click', function () {
1394
+ input.click();
1395
+ });
1396
+ }
1397
+
1398
+ input.addEventListener('change', function () {
1399
+ isite.upload(
1400
+ this.files,
1401
+ {
1402
+ api: scope.api,
1403
+ },
1404
+ (err, file, e) => {
1405
+ if (e) {
1406
+ $(progress).show();
1407
+ progress.value = e.loaded;
1408
+ progress.max = e.total;
1409
+ }
1410
+
1411
+ if (file) {
1412
+ scope.ngModel = file;
1413
+ scope.onUploaded();
1414
+ }
1415
+ }
1416
+ );
1417
+ });
1418
+
1419
+ scope.$watch('ngModel', (ngModel) => {
1420
+ if (ngModel) {
1421
+ a.setAttribute('url', ngModel);
1422
+ }
1423
+ });
1424
+ },
1425
+ template: `
1426
+ <form class="form text-center pointer">
1427
+ <input class="hidden" type="file" name="file" />
1428
+ <a class="btn {{type}}" ngClick="ngClick()" url="{{ngModel}}"> {{label}} </a>
1429
+ <progress class="row"></progress>
1430
+ </form>
1431
+ `,
1432
+ };
1433
+ },
1434
+ ]);
1435
+
1436
+ app.directive('iFiles', [
1437
+ '$interval',
1438
+ 'isite',
1439
+ function ($interval, isite) {
1440
+ return {
1441
+ restrict: 'E',
1442
+ required: 'ngModel',
1443
+ scope: {
1444
+ category: '@',
1445
+ label: '@',
1446
+ ngModel: '=',
1447
+ },
1448
+ link: function (scope, element, attrs, ctrl) {
1449
+ if (attrs.view === '') {
1450
+ scope.viewOnly = !0;
1451
+ }
1452
+
1453
+ let progress = $(element).find('progress')[0];
1454
+
1455
+ scope.category = scope.category || 'default';
1456
+ scope.id = Math.random().toString().replace('.', '_');
1457
+ scope.deleteFile = function (file) {
1458
+ isite.deleteFile(file, () => {
1459
+ for (let i = 0; i < scope.ngModel.length; i++) {
1460
+ let f = scope.ngModel[i];
1461
+ if (f.url === file.url) {
1462
+ scope.ngModel.splice(i, 1);
1463
+ return;
1464
+ }
1465
+ }
1466
+ });
1467
+ };
1468
+
1469
+ let setEvent = !1;
1470
+ $interval(() => {
1471
+ if (setEvent) {
1472
+ return;
1473
+ }
1474
+
1475
+ if (attrs.view !== '') {
1476
+ let btn = document.querySelector('#btn_' + scope.id);
1477
+ if (btn) {
1478
+ setEvent = !0;
1479
+ btn.addEventListener('click', function () {
1480
+ document.querySelector('#input_' + scope.id).click();
1481
+ });
1482
+ }
1483
+
1484
+ let input = document.querySelector('#input_' + scope.id);
1485
+ if (input) {
1486
+ input.addEventListener('change', function () {
1487
+ isite.uploadFile(
1488
+ this.files,
1489
+ {
1490
+ category: scope.category,
1491
+ },
1492
+ (err, file, e) => {
1493
+ if (e) {
1494
+ $(progress).show();
1495
+ progress.value = e.loaded;
1496
+ progress.max = e.total;
1497
+ }
1498
+
1499
+ if (file) {
1500
+ if (typeof scope.ngModel === 'undefined') {
1501
+ scope.ngModel = [];
1502
+ }
1503
+ scope.ngModel.push(file);
1504
+ }
1505
+ }
1506
+ );
1507
+ });
1508
+ }
1509
+ } else {
1510
+ setEvent = !0;
1511
+ }
1512
+ }, 500);
1513
+ },
1514
+ template: `
1515
+ <div class="files">
1516
+ <label> {{label}} </label>
1517
+ <form ng-if="viewOnly !== !0" id="img_{{id}}" class="form text-center pointer">
1518
+ <input id="input_{{id}}" class="hidden" type="file" name="file" />
1519
+ <a id="btn_{{id}}" class="btn bg-green"> <i class="fa fa-upload white"></i> </a>
1520
+ </form>
1521
+ <progress class="row"></progress>
1522
+ <div class="padding">
1523
+
1524
+ <div class="row padding" ng-repeat="f in ngModel">
1525
+ <h2>
1526
+ <a class="btn default bg-blue" href="{{f.url}}"> <i class="fa fa-2x fa-download white"></i> </a>
1527
+ <a ng-if="viewOnly !== !0" class="btn default bg-red" ng-click="deleteFile(f)"> <i class="fa fa-trash white"></i> </a>
1528
+ <span> {{f.name}} </span>
1529
+ </h2>
1530
+ </div>
1531
+ </div>
1532
+ </div>
1533
+
1534
+ `,
1535
+ };
1536
+ },
1537
+ ]);
1538
+
1539
+ app.directive('iDrag', [
1540
+ '$document',
1541
+ function ($document) {
1542
+ return function (scope, element, attr) {
1543
+ var startX = 0,
1544
+ startY = 0,
1545
+ x = 0,
1546
+ y = 0;
1547
+
1548
+ element.css({
1549
+ position: 'relative',
1550
+ });
1551
+
1552
+ element.on('mousedown', function (event) {
1553
+ event.preventDefault();
1554
+ startX = event.screenX - x;
1555
+ startY = event.screenY - y;
1556
+ $document.on('mousemove', mousemove);
1557
+ $document.on('mouseup', mouseup);
1558
+ });
1559
+
1560
+ function mousemove(event) {
1561
+ y = event.screenY - startY;
1562
+ x = event.screenX - startX;
1563
+ element.css({
1564
+ top: y + 'px',
1565
+ left: x + 'px',
1566
+ });
1567
+ }
1568
+
1569
+ function mouseup() {
1570
+ $document.off('mousemove', mousemove);
1571
+ $document.off('mouseup', mouseup);
1572
+ }
1573
+ };
1574
+ },
1575
+ ]);
1576
+
1577
+ app.directive('iTreeview', [
1578
+ '$interval',
1579
+ '$timeout',
1580
+ 'isite',
1581
+ function ($interval, $timeout, isite) {
1582
+ return {
1583
+ restrict: 'E',
1584
+ require: 'ngModel',
1585
+ scope: {
1586
+ v: '@',
1587
+ label: '@',
1588
+ display: '@',
1589
+ display2: '@',
1590
+ disabled: '@',
1591
+ space: '@',
1592
+ primary: '@',
1593
+ ngValue: '@',
1594
+ ngModel: '=',
1595
+ ngSearch: '=',
1596
+ ngChange: '&',
1597
+ ngClick: '&',
1598
+ ngAdd: '&',
1599
+ ngNode: '&',
1600
+ ngEdit: '&',
1601
+ ngDelete: '&',
1602
+ nodes: '=',
1603
+ },
1604
+ link: function ($scope, element, attrs, ctrl) {
1605
+ attrs.display = attrs.display || 'name';
1606
+ attrs.primary = attrs.primary || 'id';
1607
+ attrs.space = attrs.space || ' ';
1608
+ attrs.ngValue = attrs.ngValue || '';
1609
+
1610
+ $scope.source = {};
1611
+
1612
+ $scope.setNodes = function (v_node) {
1613
+ v_node.nodes.forEach((v_node2) => {
1614
+ v_node2.nodes = v_node2.nodes || [];
1615
+ $scope.nodes.forEach((node) => {
1616
+ if (node.$parent_id == v_node2.id) {
1617
+ node.v_display = node.v_display || '';
1618
+ node.v_display += node[attrs.display];
1619
+
1620
+ let exist = !1;
1621
+ v_node2.nodes.forEach((n) => {
1622
+ if (n.id == node.id) {
1623
+ exist = !0;
1624
+ }
1625
+ });
1626
+ if (!exist) {
1627
+ v_node2.nodes.push(node);
1628
+ }
1629
+ }
1630
+ });
1631
+ $scope.setNodes(v_node2);
1632
+ });
1633
+ };
1634
+
1635
+ $scope.v_nodes = [];
1636
+
1637
+ $scope.$watch('ngModel', (ngModel) => {
1638
+ if (ngModel) {
1639
+ $scope.ngModel = ngModel;
1640
+ $scope.ngModel.v_display = $scope.ngModel.v_display || ngModel[attrs.display];
1641
+ }
1642
+ });
1643
+
1644
+ $scope.$watch('nodes', (nodes) => {
1645
+ $scope.v_nodes = [];
1646
+ if (nodes) {
1647
+ nodes.forEach((node) => {
1648
+ node.$parent_id = node.parent_id || 0;
1649
+ node.v_display = node.v_display || '';
1650
+ node.v_display += node[attrs.display];
1651
+ if (node.$parent_id == 0) {
1652
+ let exist = !1;
1653
+ $scope.v_nodes.forEach((n) => {
1654
+ if (n.id == node.id) {
1655
+ exist = !0;
1656
+ }
1657
+ });
1658
+ if (!exist) {
1659
+ $scope.v_nodes.push(node);
1660
+ }
1661
+ }
1662
+ });
1663
+
1664
+ $scope.v_nodes.forEach((v_node) => {
1665
+ v_node.nodes = v_node.nodes || [];
1666
+
1667
+ nodes.forEach((node) => {
1668
+ node.$parent_id = node.parent_id || 0;
1669
+ if (node.$parent_id == v_node.id) {
1670
+ node.v_display = node.v_display || '';
1671
+ node.v_display += node[attrs.display];
1672
+
1673
+ let exist = !1;
1674
+ v_node.nodes.forEach((n) => {
1675
+ if (n.id == node.id) {
1676
+ exist = !0;
1677
+ }
1678
+ });
1679
+ if (!exist) {
1680
+ v_node.nodes.push(node);
1681
+ }
1682
+ }
1683
+ });
1684
+
1685
+ $scope.setNodes(v_node);
1686
+ });
1687
+ }
1688
+ });
1689
+ },
1690
+ template: `
1691
+ <div class="treeview">
1692
+ <ul >
1693
+ <li ng-dblclick="$event.preventDefault();$event.stopPropagation();source.$actions = !0" ng-mouseleave="source.$actions = !1">
1694
+
1695
+ <i ng-hide="openTree" class="fa fa-folder"></i> <i ng-show="openTree" class="fa fa-folder"></i>
1696
+
1697
+
1698
+ <span ng-click="openTree = !openTree" class="title"> {{label}} <small class="display"> [ {{ngModel.v_display}} ] </small> </span>
1699
+ <div class="actions" ng-show="source.$actions === !0">
1700
+ <i-button type="add default" ng-click="ngClick($event , ngModel);ngNode($event , ngModel)"></i-button>
1701
+ </div>
1702
+ <i-treenode display="{{display}}" ng-click="ngClick($event)" ng-add="ngAdd()" ng-edit="ngEdit()" ng-delete="ngDelete()" ng-show="openTree" ng-model="ngModel" nodes="v_nodes" ></i-treenode>
1703
+ </li>
1704
+ </ul>
1705
+ </div>
1706
+ `,
1707
+ };
1708
+ },
1709
+ ]);
1710
+
1711
+ app.directive('iTreenode', [
1712
+ '$interval',
1713
+ '$timeout',
1714
+ 'isite',
1715
+ function ($interval, $timeout, isite) {
1716
+ return {
1717
+ restrict: 'E',
1718
+ require: 'ngModel',
1719
+ scope: {
1720
+ v: '@',
1721
+ label: '@',
1722
+ display: '@',
1723
+ display2: '@',
1724
+ disabled: '@',
1725
+ space: '@',
1726
+ primary: '@',
1727
+ ngValue: '@',
1728
+ ngChange: '&',
1729
+ ngClick: '&',
1730
+ ngAdd: '&',
1731
+ ngEdit: '&',
1732
+ ngDelete: '&',
1733
+ ngModel: '=',
1734
+ ngSearch: '=',
1735
+ nodes: '=',
1736
+ nodes: '=',
1737
+ },
1738
+ link: function ($scope, element, attrs, ctrl) {
1739
+ attrs.display = attrs.display || 'name';
1740
+ attrs.primary = attrs.primary || 'id';
1741
+ attrs.space = attrs.space || ' ';
1742
+ attrs.ngValue = attrs.ngValue || '';
1743
+ $scope.nodes = $scope.nodes || [];
1744
+
1745
+ $scope.v_nodes = [];
1746
+
1747
+ $scope.$watch('nodes', (nodes) => {
1748
+ $scope.v_nodes = [];
1749
+ if (nodes) {
1750
+ nodes.forEach((node, i) => {
1751
+ if (node.nodes) {
1752
+ node.nodes.forEach((node2, i) => {
1753
+ node2.$parent_id = node2.parent_id || node.id;
1754
+ node2.v_display = node.v_display || ' ';
1755
+ node2.v_display += ' - ' + node2[attrs.display];
1756
+ });
1757
+ }
1758
+ });
1759
+ }
1760
+ });
1761
+
1762
+ $scope.updateParentModal = function (parent, node) {
1763
+ if (parent) {
1764
+ parent.ngModel = node;
1765
+ if (parent.$parent) {
1766
+ $scope.updateParentModal(parent.$parent, node);
1767
+ }
1768
+ }
1769
+ };
1770
+
1771
+ $scope.unSelectParent = function (parent) {
1772
+ if (parent && parent.nodes) {
1773
+ parent.nodes.forEach((node) => {
1774
+ node.$selected = !1;
1775
+ });
1776
+ if (parent.$parent) {
1777
+ $scope.unSelectParent(parent.$parent);
1778
+ }
1779
+ }
1780
+ };
1781
+
1782
+ $scope.unSelectNodes = function (nodes) {
1783
+ if (nodes) {
1784
+ nodes.forEach((node) => {
1785
+ node.$selected = !1;
1786
+ if (node.nodes) {
1787
+ $scope.unSelectNodes(node.nodes);
1788
+ }
1789
+ });
1790
+ }
1791
+ };
1792
+
1793
+ $scope.updateModal = function (node) {
1794
+ $scope.ngModel = node;
1795
+ $scope.updateParentModal($scope.$parent, node);
1796
+ };
1797
+
1798
+ $scope.selected = function (node) {
1799
+ $scope.unSelectParent($scope.$parent);
1800
+ $scope.unSelectNodes($scope.nodes);
1801
+
1802
+ if (node.nodes) {
1803
+ node.nodes.forEach((itm) => {
1804
+ itm.$selected = !1;
1805
+ });
1806
+ }
1807
+
1808
+ node.$selected = !0;
1809
+ };
1810
+ },
1811
+ template: `
1812
+ <div class="treenode">
1813
+ <ul >
1814
+ <li ng-repeat="node in nodes" >
1815
+ <div class="row" ng-dblclick="$event.preventDefault();$event.stopPropagation();node.$actions = !0;source.$actions = !1" ng-mouseleave="node.$actions = !1">
1816
+ <span ng-show="node.nodes.length > 0" ng-click="node.$expand = !node.$expand;">
1817
+ <i ng-hide="node.$expand" class="fa fa-caret-left"></i> <i ng-show="node.$expand" class="fa fa-caret-down"></i>
1818
+ </span>
1819
+ <span ng-hide="node.nodes.length > 0" >
1820
+ <i class="fa fa-file"></i>
1821
+ </span>
1822
+
1823
+ <span class="text" ng-class="{'selected' : node.$selected == !0}" ng-click="ngClick($event , node);node.$expand = !node.$expand;selected(node);updateModal(node)" > {{node[display]}} </span>
1824
+ <div class="actions" ng-show="node.$actions === !0">
1825
+ <i-button type="add default" ng-click="ngAdd(node)"></i-button>
1826
+ <i-button type="edit default" ng-click="ngEdit(node)"></i-button>
1827
+ <i-button type="delete default" ng-click="ngDelete(node)"></i-button>
1828
+ </div>
1829
+ </div>
1830
+ <i-treenode display="{{display}}" ng-click="ngClick($event)" ng-add="ngAdd()" ng-edit="ngEdit()" ng-delete="ngDelete()" ng-show="node.$expand" ng-model="ngModel" nodes="node.nodes" nodes="node.nodes"></i-treenode>
1831
+ </li>
1832
+ </ul>
1833
+ </div>
1834
+ `,
1835
+ };
1836
+ },
1837
+ ]);