isite 2022.8.2 → 2022.8.5

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.
Files changed (28) hide show
  1. package/apps/client-side/app.js +27 -17
  2. package/apps/client-side/site_files/css/bootstrap5-addon.css +76 -1
  3. package/apps/client-side/site_files/css/dropdown.css +22 -4
  4. package/apps/client-side/site_files/css/effect.css +283 -283
  5. package/apps/client-side/site_files/css/images.css +40 -35
  6. package/apps/client-side/site_files/css/table.css +3 -3
  7. package/apps/client-side/site_files/html/directive/i-date.html +19 -0
  8. package/apps/client-side/site_files/html/directive/i-file.html +19 -0
  9. package/apps/client-side/site_files/html/directive/i-image.html +7 -0
  10. package/apps/client-side/site_files/html/directive/i-list.html +20 -0
  11. package/apps/client-side/site_files/images/no.jpg +0 -0
  12. package/apps/client-side/site_files/js/bootstrap-5-directive.js +302 -966
  13. package/apps/client-side/site_files/js/directive-core.js +7 -8
  14. package/apps/client-side/site_files/js/directive.js +2 -2
  15. package/apps/client-side/site_files/js/site.js +18 -2
  16. package/index.js +280 -278
  17. package/isite_files/images/no.jpg +0 -0
  18. package/lib/cookie.js +3 -5
  19. package/lib/email.js +108 -0
  20. package/lib/integrated.js +10 -26
  21. package/lib/routing.js +2 -0
  22. package/lib/security.js +1109 -1081
  23. package/object-options/index.js +18 -0
  24. package/object-options/lib/fn.js +6 -3
  25. package/package.json +3 -2
  26. package/apps/client-side/site_files/html/sub/i-date2.content.html +0 -64
  27. package/apps/client-side/site_files/html/sub/i-list.content.html +0 -31
  28. package/apps/client-side/site_files/html/sub/i-list2.content.html +0 -22
@@ -15,6 +15,7 @@ app.directive('iControl', function () {
15
15
  },
16
16
  link: function ($scope, element, attrs, ctrl) {
17
17
  attrs.type = attrs.type || 'text';
18
+ $scope.id2 = $scope.id2 || 'input_' + Math.random().toString().replace('0.', '');
18
19
 
19
20
  if (typeof attrs.disabled !== 'undefined') {
20
21
  attrs.disabled = 'disabled';
@@ -30,8 +31,8 @@ app.directive('iControl', function () {
30
31
  },
31
32
  template: `
32
33
  <div class="mb-3 {{class2}}">
33
- <label for="id2" class="form-label">{{label}}</label>
34
- <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}}" />
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}}" />
35
36
  <div class="invalid-feedback">
36
37
 
37
38
  </div>
@@ -40,7 +41,43 @@ app.directive('iControl', function () {
40
41
  };
41
42
  });
42
43
 
43
- app.directive('iCheckbox', function () {
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) {
44
81
  return {
45
82
  restrict: 'E',
46
83
  require: 'ngModel',
@@ -57,10 +94,17 @@ app.directive('iCheckbox', function () {
57
94
  $scope.disabled = '';
58
95
  }
59
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
+ };
60
104
  },
61
105
  template: `
62
106
  <div class="form-check">
63
- <input ng-change="ngChange()" ng-disabled="disabled" class="form-check-input" type="checkbox" ng-model="ngModel" id="{{id2}}">
107
+ <input ng-change="changed()" ng-disabled="disabled" class="form-check-input" type="checkbox" ng-model="ngModel" id="{{id2}}">
64
108
  <label class="form-check-label" for="{{id2}}">
65
109
  {{label}}
66
110
  </label>
@@ -108,39 +152,55 @@ app.directive('iButton', function () {
108
152
  scope: {
109
153
  label: '@',
110
154
  type: '@',
111
- busy: '@',
155
+ loading: '@',
112
156
  click: '&',
113
157
  fa: '@',
114
158
  },
115
159
  link: function ($scope, element, attrs, ctrl) {
116
- attrs.type = attrs.type || '';
117
- if (attrs.type.like('*exit*') || attrs.type.like('*close*')) {
118
- attrs.fa = 'times';
119
- } else if (attrs.type.like('*view*') || attrs.type.like('*details*')) {
120
- attrs.fa = 'file';
121
- } else if (attrs.type.like('*add*') || attrs.type.like('*new*')) {
122
- attrs.fa = 'plus-circle';
123
- } else if (attrs.type.like('*update*') || attrs.type.like('*edit*')) {
124
- attrs.fa = 'edit';
125
- } else if (attrs.type.like('*save*')) {
126
- attrs.fa = 'save';
127
- } else if (attrs.type.like('*delete*') || attrs.type.like('*remove*')) {
128
- attrs.fa = 'trash';
129
- } else if (attrs.type.like('*print*')) {
130
- attrs.fa = 'print';
131
- } else if (attrs.type.like('*search*')) {
132
- attrs.fa = 'search';
133
- } else if (attrs.type.like('*export*') || attrs.type.like('*excel*')) {
134
- attrs.fa = 'table';
135
- } else {
160
+ $scope.type = $scope.type || '';
161
+ $scope.class = $scope.class = 'btn-dark';
162
+ $scope.fa = $scope.fa || $scope.label ? '' : 'fas fa-play';
163
+
164
+ if ($scope.type.like('*add*') || $scope.type.like('*new*')) {
165
+ $scope.fa = 'fas fa-plus';
136
166
  $scope.class = 'btn-primary';
167
+ } else if ($scope.type.like('*update*') || $scope.type.like('*edit*')) {
168
+ $scope.fa = 'fas fa-edit';
169
+ $scope.class = 'btn-warning';
170
+ } else if ($scope.type.like('*save*')) {
171
+ $scope.fa = 'fas fa-save';
172
+ $scope.class = 'btn-success';
173
+ } else if ($scope.type.like('*view*') || $scope.type.like('*details*')) {
174
+ $scope.fa = 'fas fa-eye';
175
+ $scope.class = 'btn-info';
176
+ } else if ($scope.type.like('*delete*') || $scope.type.like('*remove*')) {
177
+ $scope.fa = 'fas fa-trash';
178
+ $scope.class = 'btn-danger';
179
+ } else if ($scope.type.like('*exit*') || $scope.type.like('*close*')) {
180
+ $scope.fa = 'fas fa-times-circle';
181
+ $scope.class = 'btn-danger';
182
+ } else if ($scope.type.like('*print*')) {
183
+ $scope.fa = 'fas fa-print';
184
+ $scope.class = 'btn-secondary';
185
+ } else if ($scope.type.like('*search*')) {
186
+ $scope.fa = 'search';
187
+ } else if ($scope.type.like('*export*') || $scope.type.like('*excel*')) {
188
+ $scope.fa = 'fas fa-file-export';
189
+ $scope.class = 'btn-secondary';
137
190
  }
138
-
191
+ $scope.$watch('loading', (loading) => {
192
+ if (loading === 'true') {
193
+ $scope.busy = true;
194
+ } else {
195
+ $scope.busy = false;
196
+ }
197
+ });
139
198
  },
140
199
  template: `
141
200
  <button class="btn {{class}}" type="button" ng-click="click()" ng-disabled="busy">
142
201
  <span ng-show="busy" class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
143
202
  {{label}}
203
+ <i class="{{fa}}"></i>
144
204
  </button>
145
205
  `,
146
206
  };
@@ -170,9 +230,10 @@ app.directive('iList', [
170
230
  items: '=',
171
231
  },
172
232
  link: function ($scope, element, attrs, ctrl) {
173
- $scope.display = attrs.display = attrs.display || 'name';
174
- $scope.primary = attrs.primary = attrs.primary || 'id';
175
- attrs.space = attrs.space || ' ';
233
+ $scope.primary = $scope.primary || 'id';
234
+ $scope.display = $scope.display || 'name';
235
+ $scope.display2 = $scope.display2 || '';
236
+ $scope.space = $scope.space || ' - ';
176
237
  attrs.ngValue = attrs.ngValue || '';
177
238
 
178
239
  $scope.searchElement = $(element).find('.dropdown .search');
@@ -256,7 +317,11 @@ app.directive('iList', [
256
317
 
257
318
  if (items) {
258
319
  items.forEach((item) => {
259
- item.$display = $scope.getValue(item) + attrs.space + $scope.getValue2(item);
320
+ if ($scope.display2) {
321
+ item.$display = $scope.getValue(item) + $scope.space + $scope.getValue2(item);
322
+ } else {
323
+ item.$display = $scope.getValue(item);
324
+ }
260
325
  });
261
326
  }
262
327
 
@@ -264,7 +329,12 @@ app.directive('iList', [
264
329
  items.forEach((item) => {
265
330
  if (isite.getValue(item, $scope.primary) == isite.getValue($scope.ngModel, $scope.primary)) {
266
331
  $scope.ngModel = item;
267
- item.$display = $scope.getValue(item) + attrs.space + $scope.getValue2(item);
332
+ if ($scope.display2) {
333
+ item.$display = $scope.getValue(item) + $scope.space + $scope.getValue2(item);
334
+ } else {
335
+ item.$display = $scope.getValue(item);
336
+ }
337
+
268
338
  input.val(item.$display);
269
339
  }
270
340
  });
@@ -277,707 +347,37 @@ app.directive('iList', [
277
347
  $scope.ngModel = ngModel;
278
348
 
279
349
  if (ngModel) {
280
- input.val(' ' + $scope.getNgModelValue(ngModel) + attrs.space + $scope.getNgModelValue2(ngModel));
281
- }
282
- });
283
-
284
- $scope.updateModel = function (item) {
285
- $scope.ngModel = $scope.getNgValue(item, $scope.ngValue);
286
- input.val($scope.getNgModelValue($scope.ngModel) + attrs.space + $scope.getNgModelValue2($scope.ngModel));
287
- $timeout(() => {
288
- $scope.ngChange();
289
- });
290
- $scope.hide();
291
- };
292
- },
293
- template: `/*##client-side/sub/i-list2.content.html*/`,
294
- };
295
- },
296
- ]);
297
- app.directive('iDate', function () {
298
- return {
299
- link: function (scope, element, attrs) {
300
- if (typeof attrs.disabled !== 'undefined') {
301
- attrs.disabled = 'disabled';
302
- } else {
303
- attrs.disabled = '';
304
- }
305
-
306
- $(element)
307
- .find('select')
308
- .focus(() => {
309
- $('.popup').hide();
310
- });
311
-
312
- scope.days1 = [];
313
- for (let i = 1; i < 32; i++) {
314
- scope.days1.push(i);
315
- }
316
- scope.years1 = [];
317
- for (let i = 1900; i < 2100; i++) {
318
- scope.years1.push(i);
319
- }
320
- scope.monthes1 = ['يناير', 'فبراير', 'مارس', 'ابريل', 'مايو', 'يونيو', 'يوليو', 'اغسطس', 'سبتمبر', 'اكتوبر', 'نوفمبر', 'ديسمبر'];
321
- },
322
- restrict: 'E',
323
- require: 'ngModel',
324
- scope: {
325
- v: '@',
326
- label: '@',
327
- disabled: '@',
328
- ngModel: '=',
329
- },
330
- template: `
331
- <div class="row i-date">
332
-
333
- <div class=" control">
334
- <label> {{label}} </label>
335
- <div class="row">
336
- <div class="col3 day">
337
- <select ng-disabled="disabled" v="{{v}}" ng-model="ngModel.day" class="appearance-none no-border-left no-border-radius" >
338
- <option ng-repeat="d1 in days1" ng-value="d1"> {{d1}} </option>
339
- </select>
340
- </div>
341
- <div class="col5 month">
342
- <select ng-disabled="disabled" v="{{v}}" ng-model="ngModel.month" class="appearance-none no-border-left no-border-right no-border-radius" >
343
- <option ng-repeat="m1 in monthes1" ng-value="$index"> {{m1}} </option>
344
- </select>
345
- </div>
346
- <div class="col4 year">
347
- <select ng-disabled="disabled" v="{{v}}" ng-model="ngModel.year" class="appearance-none no-border-right no-border-radius" >
348
- <option ng-repeat="y1 in years1" ng-value="y1"> {{y1}} </option>
349
- </select>
350
- </div>
351
- </div>
352
- </div>
353
-
354
-
355
- </div>
356
- `,
357
- };
358
- });
359
-
360
- app.directive('iDate2', function () {
361
- return {
362
- link: function ($scope, element, attrs) {
363
- if (typeof attrs.disabled !== 'undefined') {
364
- attrs.disabled = 'disabled';
365
- } else {
366
- attrs.disabled = '';
367
- }
368
-
369
- $scope.y_search = attrs.year || '202';
370
- $scope.m_search = attrs.month || '';
371
- $scope.d_search = attrs.day || '';
372
-
373
- $scope.days1 = [];
374
- for (let i = 1; i < 32; i++) {
375
- $scope.days1.push({
376
- id: i,
377
- name: i,
378
- });
379
- }
380
- $scope.years1 = [];
381
- for (let i = 1900; i < 2100; i++) {
382
- $scope.years1.push({
383
- id: i,
384
- name: i,
385
- });
386
- }
387
-
388
- $scope.monthes1 = [
389
- { id: 0, name: 'يناير / Jan' },
390
- { id: 1, name: 'فبراير / Feb' },
391
- { id: 2, name: 'مارس / Mar' },
392
- { id: 3, name: 'ابريل / Aper' },
393
- { id: 4, name: 'مايو / May' },
394
- { id: 5, name: 'يونيو / June' },
395
- { id: 6, name: 'يوليو / Jule' },
396
- { id: 7, name: 'اغسطس / Aug' },
397
- { id: 8, name: 'سبتمبر / Sep' },
398
- { id: 9, name: 'اكتوبر / Oct' },
399
- { id: 10, name: 'نوفمبر / Nov' },
400
- { id: 11, name: 'ديسمبر / Des' },
401
- ];
402
-
403
- $scope.model = null;
404
-
405
- $scope.$watch('ngModel', function (ngModel) {
406
- if (ngModel) {
407
- ngModel = new Date(ngModel);
408
- $scope.model = $scope.model || {};
409
- $scope.model.day = ngModel.getDate();
410
- $scope.model.day_name = $scope.model.day;
411
- $scope.model.month = ngModel.getMonth();
412
- $scope.model.month_name = $scope.monthes1.find((m) => m.id == $scope.model.month).name;
413
- $scope.model.year = ngModel.getFullYear();
414
- $scope.model.year_name = $scope.model.year;
415
- } else {
416
- $scope.model = $scope.model || {};
417
- $scope.model.day = 0;
418
- $scope.model.day_name = '';
419
- $scope.model.month = -1;
420
- $scope.model.month_name = '';
421
- $scope.model.year = 0;
422
- $scope.model.year_name = '';
423
- }
424
- });
425
-
426
- $scope.setDay = function () {
427
- $scope.ngModel = new Date();
428
- };
429
- $scope.updateDate = function (date) {
430
- if (date.year) {
431
- $scope.model.year = date.year.id;
432
- $scope.model.year_name = date.year.name;
433
- } else if (date.month) {
434
- $scope.model.month = date.month.id;
435
- $scope.model.month_name = date.month.name;
436
- } else if (date.day) {
437
- $scope.model.day = date.day.id;
438
- $scope.model.day_name = date.day.name;
439
- }
440
-
441
- if ($scope.model && $scope.model.year && $scope.model.day && $scope.model.month > -1) {
442
- $scope.ngModel = new Date($scope.model.year, $scope.model.month, $scope.model.day, 0, 0, 0);
443
- } else {
444
- delete $scope.ngModel;
445
- }
446
- };
447
- },
448
- restrict: 'E',
449
- require: 'ngModel',
450
- scope: {
451
- v: '@',
452
- disabled: '@',
453
- label: '@',
454
- ngModel: '=',
455
- },
456
- template: `/*##client-side/sub/i-date2.content.html*/`,
457
- };
458
- });
459
-
460
- app.directive('iTime', function () {
461
- return {
462
- link: function ($scope, element, attrs) {
463
- if (typeof attrs.disabled !== 'undefined') {
464
- attrs.disabled = 'disabled';
465
- } else {
466
- attrs.disabled = '';
467
- }
468
-
469
- $scope.model = {};
470
-
471
- $scope.hours = [];
472
- for (let i = 1; i < 25; i++) {
473
- $scope.hours.push(i);
474
- }
475
-
476
- $scope.minutes = [];
477
- for (let i = 0; i < 60; i++) {
478
- $scope.minutes.push(i);
479
- }
480
-
481
- $(element)
482
- .find('select')
483
- .focus(() => {
484
- $('.popup').hide();
485
- });
486
-
487
- $scope.$watch('ngModel', function (ngModel) {
488
- if (ngModel) {
489
- ngModel.date = new Date(ngModel.date);
490
- $scope.model = $scope.model || {};
491
- $scope.model.hour = ngModel.hour;
492
- $scope.model.minute = ngModel.minute;
493
- } else {
494
- $scope.model = $scope.model || {};
495
- $scope.model.hour = 0;
496
- $scope.model.minute = 0;
497
- }
498
- });
499
-
500
- $scope.updateTime = function () {
501
- if ($scope.model) {
502
- $scope.ngModel = $scope.ngModel || {};
503
- $scope.ngModel.hour = $scope.model.hour;
504
- $scope.ngModel.minute = $scope.model.minute;
505
- $scope.ngModel.date = new Date(null, null, null, $scope.model.hour, $scope.model.minute, null);
506
- } else {
507
- delete $scope.ngModel;
508
- }
509
- };
510
- },
511
- restrict: 'E',
512
- require: 'ngModel',
513
- scope: {
514
- v: '@',
515
- disabled: '@',
516
- label: '@',
517
- ngModel: '=',
518
- },
519
- template: `
520
- <div class="row i-time">
521
- <div class=" control ">
522
- <label class="text-center"> {{label}} </label>
523
- <div class="row">
524
- <div class="col6 right">
525
- <div class="row">
526
- <div class="col2"></div>
527
- <div class="col8">
528
- <select ng-disabled="disabled" ng-model="model.minute" ng-change="updateTime()" class="small appearance-none no-border-left no-border-radius" >
529
- <option ng-repeat="m in minutes" ng-value="m"> {{m}}</option>
530
- </select>
531
- </div>
532
- <div class="col2"></div>
533
- </div>
534
-
535
- </div>
536
- <div class="col6">
537
- <div class="row">
538
- <div class="col2 space right">
539
- <span> : </span>
540
- </div>
541
- <div class="col8">
542
- <select ng-disabled="disabled" ng-model="model.hour" ng-change="updateTime()" class="large blue appearance-none no-border-left no-border-radius" >
543
- <option ng-repeat="h in hours" ng-value="h"> {{h}} </option>
544
- </select>
545
- </div>
546
-
547
- </div>
548
-
549
- </div>
550
- </div>
551
- </div>
552
- `,
553
- };
554
- });
555
-
556
- app.directive('iDatetime2', function () {
557
- return {
558
- link: function ($scope, element, attrs) {
559
- if (typeof attrs.disabled !== 'undefined') {
560
- attrs.disabled = 'disabled';
561
- } else {
562
- attrs.disabled = '';
563
- }
564
-
565
- $scope.hour1 = [];
566
- for (let i = 1; i < 25; i++) {
567
- $scope.hour1.push(i);
568
- }
569
-
570
- $scope.minute_list = [];
571
- for (let i = 1; i < 60; i++) {
572
- $scope.minute_list.push({
573
- name: i,
574
- });
575
- }
576
-
577
- $scope.days1 = [];
578
- for (let i = 1; i < 32; i++) {
579
- $scope.days1.push(i);
580
- }
581
- $scope.years1 = [];
582
- for (let i = 1900; i < 2100; i++) {
583
- $scope.years1.push(i);
584
- }
585
- $scope.monthes1 = ['يناير', 'فبراير', 'مارس', 'ابريل', 'مايو', 'يونيو', 'يوليو', 'اغسطس', 'سبتمبر', 'اكتوبر', 'نوفمبر', 'ديسمبر'];
586
-
587
- $scope.model = null;
588
-
589
- $(element)
590
- .find('select')
591
- .focus(() => {
592
- $('.popup').hide();
593
- });
594
-
595
- $scope.$watch('ngModel', function (ngModel) {
596
- if (ngModel) {
597
- ngModel = new Date(ngModel);
598
- $scope.model = $scope.model || {};
599
- $scope.model.hour = ngModel.getHours();
600
- $scope.model.minute = ngModel.getMinutes();
601
- $scope.model.day = ngModel.getDate();
602
- $scope.model.month = ngModel.getMonth();
603
- $scope.model.year = ngModel.getFullYear();
604
- } else {
605
- $scope.model = $scope.model || {};
606
- $scope.model.hour = 0;
607
- $scope.model.minute = 0;
608
- $scope.model.day = 0;
609
- $scope.model.month = -1;
610
- $scope.model.year = 0;
611
- }
612
- });
613
-
614
- $scope.updateDate = function () {
615
- if ($scope.model && $scope.model.year && $scope.model.day) {
616
- $scope.ngModel = new Date($scope.model.year, $scope.model.month, $scope.model.day, $scope.model.hour, $scope.model.minute);
617
- } else {
618
- delete $scope.ngModel;
619
- }
620
- };
621
- },
622
- restrict: 'E',
623
- require: 'ngModel',
624
- scope: {
625
- v: '@',
626
- disabled: '@',
627
- label: '@',
628
- ngModel: '=',
629
- },
630
- template: `
631
- <div class="row i-datetime2">
632
-
633
- <div class=" control">
634
- <label> {{label}} </label>
635
- <div class="row">
636
-
637
- <div class="col2 day">
638
- <select v="{{v}}" ng-disabled="disabled" ng-model="model.day" ng-change="updateDate()" class="appearance-none no-border-left no-border-radius" >
639
- <option ng-repeat="d1 in days1" ng-value="d1"> {{d1}} </option>
640
- </select>
641
- </div>
642
- <div class="col5 month">
643
- <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" >
644
- <option ng-repeat="m1 in monthes1" ng-value="$index"> {{m1}} </option>
645
- </select>
646
- </div>
647
- <div class="col3 year">
648
- <select v="{{v}}" ng-disabled="disabled" ng-model="model.year" ng-change="updateDate()" class="appearance-none no-border-right no-border-radius" >
649
- <option ng-repeat="y1 in years1" ng-value="y1"> {{y1}} </option>
650
- </select>
651
- </div>
652
-
653
- <div class="col1 hour">
654
- <select v="{{v}}" ng-disabled="disabled" ng-model="model.hour" ng-change="updateDate()" class="appearance-none no-border-radius" >
655
- <option ng-repeat="h1 in hour1" ng-value="h1"> {{h1}} </option>
656
- </select>
657
- </div>
658
- <div class="col1 minute">
659
- <select v="{{v}}" ng-disabled="disabled" ng-model="model.minute" ng-change="updateDate()" class="green appearance-none no-border-right no-border-radius" >
660
- <option ng-repeat="m1 in minute_list" ng-value="m1.name" class="green"> {{m1.name}} </option>
661
- </select>
662
- </div>
663
-
664
- </div>
665
- </div>
666
-
667
-
668
- </div>
669
- `,
670
- };
671
- });
672
-
673
- app.directive('iMonth2', function () {
674
- return {
675
- link: function ($scope, element, attrs) {
676
- if (typeof attrs.disabled !== 'undefined') {
677
- attrs.disabled = 'disabled';
678
- } else {
679
- attrs.disabled = '';
680
- }
681
-
682
- $scope.years = [];
683
- for (let i = 1900; i < 2100; i++) {
684
- $scope.years.push(i);
685
- }
686
- $scope.monthes = ['يناير', 'فبراير', 'مارس', 'ابريل', 'مايو', 'يونيو', 'يوليو', 'اغسطس', 'سبتمبر', 'اكتوبر', 'نوفمبر', 'ديسمبر'];
687
-
688
- $scope.model = null;
689
-
690
- $(element)
691
- .find('select')
692
- .focus(() => {
693
- $('.popup').hide();
694
- });
695
-
696
- $scope.$watch('ngModel', function (ngModel) {
697
- if (ngModel) {
698
- ngModel = new Date(ngModel);
699
- $scope.model = $scope.model || {};
700
- $scope.model.day = 1;
701
- $scope.model.month = ngModel.getMonth();
702
- $scope.model.year = ngModel.getFullYear();
703
- } else {
704
- $scope.model = $scope.model || {};
705
- $scope.model.day = 0;
706
- $scope.model.month = -1;
707
- $scope.model.year = 0;
708
- }
709
- });
710
-
711
- $scope.updateDate = function () {
712
- if ($scope.model && $scope.model.year) {
713
- $scope.ngModel = new Date($scope.model.year, $scope.model.month, 1);
714
- } else {
715
- delete $scope.ngModel;
716
- }
717
- };
718
- },
719
- restrict: 'E',
720
- require: 'ngModel',
721
- scope: {
722
- v: '@',
723
- label: '@',
724
- disabled: '@',
725
- ngModel: '=',
726
- },
727
- template: `
728
- <div class="row i-date2">
729
-
730
- <div class=" control">
731
- <label> {{label}} </label>
732
- <div class="row">
733
-
734
- <div class="col7 month">
735
- <select ng-disabled="disabled" v="{{v}}" ng-model="model.month" ng-change="updateDate()" class="appearance-none no-border-left no-border-radius" >
736
- <option ng-repeat="m1 in monthes" ng-value="$index"> {{m1}} </option>
737
- </select>
738
- </div>
739
-
740
- <div class="col5 year">
741
- <select ng-disabled="disabled" v="{{v}}" ng-model="model.year" ng-change="updateDate()" class="appearance-none no-border-right no-border-radius" >
742
- <option ng-repeat="y1 in years" ng-value="y1"> {{y1}} </option>
743
- </select>
744
- </div>
745
-
746
- </div>
747
- </div>
748
-
749
-
750
- </div>
751
- `,
752
- };
753
- });
754
-
755
- app.directive('iFulldate', [
756
- '$http',
757
- function ($http) {
758
- return {
759
- link: function ($scope, element, attrs, ngModel) {
760
- let _busy = !1;
761
-
762
- if (typeof attrs.disabled !== 'undefined') {
763
- attrs.disabled = 'disabled';
764
- } else {
765
- attrs.disabled = '';
766
- }
767
-
768
- $(element)
769
- .find('select')
770
- .focus(() => {
771
- $('.popup').hide();
772
- });
773
-
774
- $scope.days1 = [];
775
- for (let i = 1; i < 32; i++) {
776
- $scope.days1.push(i);
777
- }
778
- $scope.years1 = [];
779
- for (let i = 1950; i < 2030; i++) {
780
- $scope.years1.push(i);
781
- }
782
-
783
- $scope.monthes1 = ['يناير', 'فبراير', 'مارس', 'ابريل', 'مايو', 'يونيو', 'يوليو', 'اغسطس', 'سبتمبر', 'اكتوبر', 'نوفمبر', 'ديسمبر'];
784
-
785
- $scope.days2 = [];
786
- for (let i = 1; i < 31; i++) {
787
- $scope.days2.push(i);
788
- }
789
- $scope.years2 = [];
790
- for (let i = 1370; i < 1450; i++) {
791
- $scope.years2.push(i);
792
- }
793
- $scope.monthes2 = ['محرم', 'صفر', 'ربيع اول', 'ربيع ثان', 'جمادى اول', 'جمادى ثان', 'رجب', 'شعبان', 'رمضان', 'شوال', 'ذى القعدة', 'ذى الحجة'];
794
-
795
- $scope.model = {};
796
-
797
- $scope.$watch('ngModel', function (ngModel) {
798
- if (ngModel) {
799
- $scope.model = ngModel;
800
- } else {
801
- $scope.model = {};
802
- }
803
- });
804
-
805
- $scope.$watch('ngModel.date', function (date) {
806
- if (date) {
807
- if (typeof date == 'string') {
808
- date = new Date(date);
350
+ if ($scope.display2) {
351
+ input.val(' ' + $scope.getNgModelValue(ngModel) + $scope.space + $scope.getNgModelValue2(ngModel));
352
+ } else {
353
+ input.val(' ' + $scope.getNgModelValue(ngModel));
809
354
  }
810
- $scope.model = $scope.model || {};
811
- $scope.model.date = date;
812
- $scope.model.day = date.getDate();
813
- $scope.model.month = date.getMonth();
814
- $scope.model.year = date.getFullYear();
815
- $scope.get_hijri_date();
816
355
  }
817
356
  });
818
357
 
819
- $scope.get_hijri_date = function () {
820
- if ($scope.model && $scope.model.year && $scope.model.day) {
821
- ngModel.$setViewValue($scope.model);
822
- if (_busy) {
823
- return;
824
- }
825
- _busy = !0;
826
- $scope.model.date = new Date($scope.model.year, $scope.model.month, $scope.model.day);
827
- $http({
828
- method: 'POST',
829
- url: '/api/get_hijri_date',
830
- data: {
831
- date: $scope.model.year + '/' + ($scope.model.month + 1) + '/' + $scope.model.day,
832
- },
833
- })
834
- .then((response) => {
835
- if (response.data.done) {
836
- $scope.model.hijri = response.data.hijri;
837
- $scope.model.day2 = parseInt($scope.model.hijri.split('/')[2]);
838
- $scope.model.month2 = parseInt($scope.model.hijri.split('/')[1]) - 1;
839
- $scope.model.year2 = parseInt($scope.model.hijri.split('/')[0]);
840
- ngModel.$setViewValue($scope.model);
841
- _busy = !1;
842
- }
843
- })
844
- .catch(() => {
845
- _busy = !1;
846
- });
358
+ $scope.updateModel = function (item) {
359
+ $scope.ngModel = $scope.getNgValue(item, $scope.ngValue);
360
+ if ($scope.display2) {
361
+ input.val($scope.getNgModelValue($scope.ngModel) + $scope.space + $scope.getNgModelValue2($scope.ngModel));
362
+ } else {
363
+ input.val($scope.getNgModelValue($scope.ngModel));
847
364
  }
848
- };
849
-
850
- $scope.get_normal_date = function () {
851
- if ($scope.model && $scope.model.year2 && $scope.model.day2) {
852
- ngModel.$setViewValue($scope.model);
853
- if (_busy) {
854
- return;
365
+ $timeout(() => {
366
+ if ($scope.ngChange) {
367
+ $scope.ngChange();
855
368
  }
856
- _busy = !0;
857
- $http({
858
- method: 'POST',
859
- url: '/api/get_normal_date',
860
- data: {
861
- hijri: $scope.model.year2 + '/' + ($scope.model.month2 + 1) + '/' + $scope.model.day2,
862
- },
863
- })
864
- .then((response) => {
865
- if (response.data.done) {
866
- $scope.model.date = new Date(response.data.date);
867
- $scope.model.day = parseInt(response.data.date.split('/')[2]);
868
- $scope.model.month = parseInt(response.data.date.split('/')[1]) - 1;
869
- $scope.model.year = parseInt(response.data.date.split('/')[0]);
870
- ngModel.$setViewValue($scope.model);
871
- _busy = !1;
872
- }
873
- })
874
- .catch(() => {
875
- _busy = !1;
876
- });
877
- }
369
+ }, 100);
370
+ $scope.hide();
878
371
  };
879
372
  },
880
- restrict: 'E',
881
- require: 'ngModel',
882
- scope: {
883
- v: '@',
884
- label1: '@',
885
- label2: '@',
886
- disabled: '@',
887
- ngModel: '=',
888
- ngChange: '&',
889
- },
890
- template: `
891
- <div class="row i-date">
892
-
893
- <div class="col6 control">
894
- <label> {{label1}} </label>
895
- <div class="row">
896
- <div class="col3 day">
897
- <select ng-change="get_hijri_date()" ng-disabled="disabled" v="{{v}}" ng-model="model.day" class="appearance-none no-border-left no-border-radius">
898
- <option ng-repeat="d1 in days1" ng-value="d1"> {{d1}} </option>
899
- </select>
900
- </div>
901
- <div class="col5 month">
902
- <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">
903
- <option ng-repeat="m1 in monthes1" ng-value="$index"> {{m1}} </option>
904
- </select>
905
- </div>
906
- <div class="col4 year">
907
- <select ng-change="get_hijri_date()" ng-disabled="disabled" v="{{v}}" ng-model="model.year" class="appearance-none no-border-right no-border-radius">
908
- <option ng-repeat="y1 in years1" ng-value="y1"> {{y1}} </option>
909
- </select>
910
- </div>
911
- </div>
912
- </div>
913
-
914
- <div class="col6 control">
915
- <label> {{label2}} </label>
916
- <div class="row">
917
- <div class="col3 day">
918
- <select ng-change="get_normal_date()" ng-disabled="disabled" v="{{v}}" ng-model="model.day2" class="appearance-none no-border-left no-border-radius">
919
- <option ng-repeat="d2 in days2" ng-value="d2"> {{d2}} </option>
920
- </select>
921
- </div>
922
- <div class="col5 month">
923
- <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">
924
- <option ng-repeat="m2 in monthes2" ng-value="$index"> {{m2}} </option>
925
- </select>
926
- </div>
927
- <div class="col4 year">
928
- <select ng-change="get_normal_date()" ng-disabled="disabled" v="{{v}}" ng-model="model.year2" class="appearance-none no-border-right no-border-radius">
929
- <option ng-repeat="y2 in years2" ng-value="y2"> {{y2}} </option>
930
- </select>
931
- </div>
932
- </div>
933
- </div>
934
-
935
- </div>
936
- `,
373
+ template: `/*##client-side/directive/i-list.html*/`,
937
374
  };
938
375
  },
939
376
  ]);
940
-
941
- app.directive('iTextarea', function () {
942
- return {
943
- restrict: 'E',
944
- require: 'ngModel',
945
- scope: {
946
- v: '@',
947
- label: '@',
948
- disabled: '@',
949
- rows: '@',
950
- ngModel: '=',
951
- ngChange: '&',
952
- },
953
- link: function (scope, element, attrs, ctrl) {
954
- if (typeof attrs.disabled !== 'undefined') {
955
- attrs.disabled = 'disabled';
956
- } else {
957
- attrs.disabled = '';
958
- }
959
- scope.rows = scope.rows || 4;
960
-
961
- $(element)
962
- .find('textarea')
963
- .focus(() => {
964
- $('.popup').hide();
965
- });
966
- },
967
- template: `
968
- <div class="control">
969
- <label> {{label}} </label>
970
- <textarea ng-disabled="disabled" rows="{{rows}}" v="{{v}}" ng-model="ngModel" ng-change="ngChange()"></textarea>
971
- </div>
972
- `,
973
- };
974
- });
975
-
976
-
977
-
978
377
  app.directive('iChecklist', [
979
378
  '$interval',
980
- function ($interval) {
379
+ '$timeout',
380
+ function ($interval, $timeout) {
981
381
  return {
982
382
  restrict: 'E',
983
383
  required: 'ngModel',
@@ -985,13 +385,16 @@ app.directive('iChecklist', [
985
385
  label: '@',
986
386
  primary: '@',
987
387
  display: '@',
388
+ class2: '@',
988
389
  ngModel: '=',
989
390
  items: '=',
990
391
  like: '&',
392
+ ngChange: '&',
991
393
  },
992
394
  link: function ($scope, element, attrs, ctrl) {
993
- attrs.primary = attrs.primary || 'id';
994
-
395
+ $scope.primary = $scope.primary || 'id';
396
+ $scope.display = $scope.display || 'name';
397
+ $scope.class2 = $scope.class2 || 'col';
995
398
  $scope.selectedItems = [];
996
399
 
997
400
  $scope.$watch('ngModel', (ngModel) => {
@@ -1033,8 +436,6 @@ app.directive('iChecklist', [
1033
436
  };
1034
437
 
1035
438
  $scope.change = function (item) {
1036
- item.$selected = !item.$selected;
1037
-
1038
439
  if (item.$selected) {
1039
440
  let exsits = !1;
1040
441
  $scope.selectedItems.forEach((sitem) => {
@@ -1043,7 +444,10 @@ app.directive('iChecklist', [
1043
444
  }
1044
445
  });
1045
446
  if (!exsits) {
1046
- $scope.selectedItems.push(item);
447
+ let nitem = { ...item };
448
+ delete nitem.$selected;
449
+ delete nitem.$$hashKey;
450
+ $scope.selectedItems.push(nitem);
1047
451
  }
1048
452
  } else {
1049
453
  $scope.selectedItems.forEach((sitem, index) => {
@@ -1054,20 +458,131 @@ app.directive('iChecklist', [
1054
458
  }
1055
459
 
1056
460
  $scope.ngModel = $scope.selectedItems;
461
+ $timeout(() => {
462
+ if ($scope.ngChange) {
463
+ $scope.ngChange();
464
+ }
465
+ }, 100);
1057
466
  };
1058
467
  },
1059
468
  template: `
1060
- <div class="row padding check-list">
1061
- <label class="title"> {{label}} </label>
1062
- <div ng-repeat="item in items" ng-click="change(item);ngChange($event , item);" class="selector" ng-class="{'selected' : item.$selected , 'un-selected' : !item.$selected }" >
1063
- <i ng-show="!item.$selected" class="fa fa-square"></i> <i ng-show="item.$selected" class="fa fa-check"></i> {{item[display]}}
1064
- </div>
469
+ <div class="check-list">
470
+ <label class="title margin"> {{label}} </label>
471
+ <div class="row">
472
+ <i-checkbox class="{{class2}}" label="{{item[display]}}" ng-repeat="item in items" ng-model="item.$selected" ng-change="change(item);"></i-checkbox>
473
+ </div>
1065
474
  </div>
1066
475
  `,
1067
476
  };
1068
477
  },
1069
478
  ]);
1070
479
 
480
+ app.directive('iDate', function () {
481
+ return {
482
+ restrict: 'E',
483
+ required: 'ngModel',
484
+ scope: {
485
+ label: '@',
486
+ year: '@',
487
+ ngModel: '=',
488
+ ngChange: '&',
489
+ },
490
+ link: function ($scope, element, attrs) {
491
+ if (typeof attrs.disabled !== 'undefined') {
492
+ attrs.disabled = 'disabled';
493
+ } else {
494
+ attrs.disabled = '';
495
+ }
496
+ $scope.year = $scope.year ? parseInt($scope.year) : 1960;
497
+
498
+ $scope.model = {};
499
+
500
+ $scope.days = [];
501
+ for (let i = 1; i < 32; i++) {
502
+ $scope.days.push({
503
+ id: i,
504
+ name: i,
505
+ });
506
+ }
507
+ $scope.years = [];
508
+ for (let i = $scope.year; i < 2100; i++) {
509
+ $scope.years.push({
510
+ id: i,
511
+ name: i,
512
+ });
513
+ }
514
+ $scope.lang = site.session ? site.session.lang : 'en';
515
+ if ($scope.lang === 'ar') {
516
+ $scope.monthes = [
517
+ { id: 0, name: 'يناير' },
518
+ { id: 1, name: 'فبراير' },
519
+ { id: 2, name: 'مارس' },
520
+ { id: 3, name: 'ابريل' },
521
+ { id: 4, name: 'مايو' },
522
+ { id: 5, name: 'يونيو' },
523
+ { id: 6, name: 'يوليو' },
524
+ { id: 7, name: 'اغسطس' },
525
+ { id: 8, name: 'سبتمبر' },
526
+ { id: 9, name: 'اكتوبر' },
527
+ { id: 10, name: 'نوفمبر' },
528
+ { id: 11, name: 'ديسمبر' },
529
+ ];
530
+ } else {
531
+ $scope.monthes = [
532
+ { id: 0, name: 'Jan' },
533
+ { id: 1, name: 'Feb' },
534
+ { id: 2, name: 'Mar' },
535
+ { id: 3, name: 'Aper' },
536
+ { id: 4, name: 'May' },
537
+ { id: 5, name: 'June' },
538
+ { id: 6, name: 'Jule' },
539
+ { id: 7, name: 'Aug' },
540
+ { id: 8, name: 'Sep' },
541
+ { id: 9, name: 'Oct' },
542
+ { id: 10, name: 'Nov' },
543
+ { id: 11, name: 'Des' },
544
+ ];
545
+ }
546
+
547
+ $scope.$watch('ngModel', function (ngModel) {
548
+ if (ngModel) {
549
+ ngModel = new Date(ngModel);
550
+ $scope.model = $scope.model || {};
551
+ $scope.model.selectedDay = $scope.days.find((d) => d.id == ngModel.getDate());
552
+ $scope.model.selectedMonth = $scope.monthes.find((m) => m.id == ngModel.getMonth());
553
+ $scope.model.selectedYear = $scope.years.find((y) => y.id == ngModel.getFullYear());
554
+ } else {
555
+ $scope.model = $scope.model || {};
556
+ $scope.model.selectedDay = null;
557
+ $scope.model.selectedMonth = null;
558
+ $scope.model.selectedYear = null;
559
+ }
560
+ });
561
+
562
+ $scope.setDay = function () {
563
+ $scope.ngModel = new Date();
564
+ };
565
+ $scope.updateDate = function (date) {
566
+ if ($scope.model.selectedDay && $scope.model.selectedMonth && $scope.model.selectedYear) {
567
+ $scope.ngModel = new Date($scope.model.selectedYear.id, $scope.model.selectedMonth.id, $scope.model.selectedDay.id, 0, 0, 0);
568
+ if ($scope.ngChange) {
569
+ $scope.ngChange();
570
+ }
571
+ }
572
+ };
573
+ },
574
+ restrict: 'E',
575
+ require: 'ngModel',
576
+ scope: {
577
+ v: '@',
578
+ disabled: '@',
579
+ label: '@',
580
+ ngModel: '=',
581
+ },
582
+ template: `/*##client-side/directive/i-date.html*/`,
583
+ };
584
+ });
585
+
1071
586
  app.directive('iChecklist2', [
1072
587
  '$interval',
1073
588
  function ($interval) {
@@ -1216,109 +731,73 @@ app.directive('iFile', [
1216
731
  required: 'ngModel',
1217
732
  scope: {
1218
733
  label: '@',
1219
- type: '@',
734
+ accept: '@',
735
+ folder: '@',
1220
736
  ngModel: '=',
1221
737
  ngClick: '&',
1222
738
  onSelected: '&',
739
+ ngChange: '&',
1223
740
  },
1224
- link: function (scope, element, attrs, ctrl) {
1225
- scope.type = scope.type || 'bg-green';
1226
-
741
+ link: function ($scope, element, attrs, ctrl) {
742
+ $scope.label = $scope.label || 'Select File to Upload';
743
+ $scope.folder = $scope.folder || 'default';
744
+ $scope.accept = $scope.accept ? $scope.accept : '';
1227
745
  let input = $(element).find('input')[0];
1228
- let a = $(element).find('a')[0];
1229
-
1230
- if (attrs.view !== '') {
1231
- a.addEventListener('click', function () {
1232
- input.click();
1233
- });
746
+ let button = $(element).find('button')[0];
747
+ if (attrs.view === '') {
748
+ $scope.viewOnly = !0;
1234
749
  }
1235
-
1236
- input.addEventListener('change', function () {
1237
- scope.ngModel = this.files[0].path;
1238
- scope.onSelected(this.files[0].path);
1239
- scope.$applyAsync();
1240
- });
1241
-
1242
- scope.$watch('ngModel', (ngModel) => {
1243
- if (ngModel) {
1244
- a.setAttribute('url', ngModel);
1245
- }
1246
- });
1247
- },
1248
- template: `
1249
- <form class="form text-center pointer">
1250
- <input class="hidden" type="file" name="file" />
1251
- <a class="btn {{type}}" ngClick="ngClick()" url="{{ngModel}}"> {{label}} </a>
1252
- </form>
1253
- `,
1254
- };
1255
- },
1256
- ]);
1257
-
1258
- app.directive('iImage', [
1259
- '$interval',
1260
- 'isite',
1261
- function ($interval, isite) {
1262
- return {
1263
- restrict: 'E',
1264
- required: 'ngModel',
1265
- scope: {
1266
- category: '@',
1267
- ngModel: '=',
1268
- ngClick: '&',
1269
- },
1270
- link: function (scope, element, attrs, ctrl) {
1271
- scope.category = scope.category || 'default';
1272
-
1273
- let input = $(element).find('input')[0];
1274
- let img = $(element).find('img')[0];
1275
- let progress = $(element).find('progress')[0];
750
+ let progress = $(element).find('.progress')[0];
1276
751
  $(progress).hide();
1277
752
 
753
+ $scope.id = Math.random().toString().replace('.', '_');
1278
754
  if (attrs.view !== '') {
1279
- img.addEventListener('click', function () {
755
+ button.addEventListener('click', function () {
1280
756
  input.click();
1281
757
  });
1282
758
  }
1283
759
 
1284
760
  input.addEventListener('change', function () {
1285
- isite.uploadImage(
761
+ isite.uploadFile(
1286
762
  this.files,
1287
763
  {
1288
- category: scope.category,
764
+ folder: $scope.folder,
1289
765
  },
1290
- (err, image_url, e) => {
766
+ (err, file, e) => {
1291
767
  if (e) {
1292
768
  $(progress).show();
1293
- progress.value = e.loaded;
1294
- progress.max = e.total;
769
+ $scope.value = (e.loaded / e.total) * 100;
770
+ $scope.max = e.total;
771
+ if ($scope.value === 100) {
772
+ $(progress).hide();
773
+ }
1295
774
  }
1296
775
 
1297
- if (image_url) {
1298
- scope.ngModel = image_url;
776
+ if (file) {
777
+ $scope.ngModel = file;
778
+ if ($scope.ngChange) {
779
+ $scope.ngChange();
780
+ }
1299
781
  }
1300
782
  }
1301
783
  );
784
+ $scope.ngModel = this.files[0].path;
785
+ $scope.onSelected(this.files[0].path);
786
+ $scope.$applyAsync();
1302
787
  });
1303
788
 
1304
- scope.$watch('ngModel', (ngModel) => {
789
+ $scope.$watch('ngModel', (ngModel) => {
1305
790
  if (ngModel) {
1306
- img.setAttribute('src', ngModel);
791
+ a.setAttribute('url', ngModel);
1307
792
  }
1308
793
  });
1309
794
  },
1310
- template: `
1311
- <form class="form text-center pointer">
1312
- <input class="hidden" type="file" name="file" />
1313
- <img class="bg-white" ng-src="{{ngModel}}" ngClick="ngClick()" onerror="this.src='/images/no.jpg'" />
1314
- <progress class="row"></progress>
1315
- </form>
1316
- `,
795
+ template: `/*##client-side/directive/i-file.html*/`,
1317
796
  };
1318
797
  },
1319
798
  ]);
1320
799
 
1321
- app.directive('iUpload', [
800
+ app.directive('iImage', [
1322
801
  '$interval',
1323
802
  'isite',
1324
803
  function ($interval, isite) {
@@ -1326,202 +805,59 @@ app.directive('iUpload', [
1326
805
  restrict: 'E',
1327
806
  required: 'ngModel',
1328
807
  scope: {
1329
- label: '@',
1330
- api: '@',
1331
- type: '@',
808
+ folder: '@',
809
+ accept: '@',
1332
810
  ngModel: '=',
1333
811
  ngClick: '&',
1334
- onUploaded: '&',
812
+ ngChange: '&',
1335
813
  },
1336
- link: function (scope, element, attrs, ctrl) {
1337
- scope.type = scope.type || 'bg-green';
1338
-
814
+ link: function ($scope, element, attrs, ctrl) {
815
+ $scope.folder = $scope.folder || 'default';
816
+ $scope.accept = $scope.accept ? $scope.accept : 'image/*';
1339
817
  let input = $(element).find('input')[0];
1340
- let a = $(element).find('a')[0];
1341
- let progress = $(element).find('progress')[0];
818
+ let img = $(element).find('img')[0];
819
+ let progress = $(element).find('.progress')[0];
1342
820
  $(progress).hide();
1343
821
 
1344
822
  if (attrs.view !== '') {
1345
- a.addEventListener('click', function () {
823
+ img.addEventListener('click', function () {
1346
824
  input.click();
1347
825
  });
1348
826
  }
1349
827
 
1350
828
  input.addEventListener('change', function () {
1351
- isite.upload(
829
+ isite.uploadImage(
1352
830
  this.files,
1353
831
  {
1354
- api: scope.api,
832
+ folder: $scope.folder,
1355
833
  },
1356
- (err, file, e) => {
834
+ (err, image, e) => {
1357
835
  if (e) {
1358
836
  $(progress).show();
1359
- progress.value = e.loaded;
1360
- progress.max = e.total;
837
+ $scope.value = (e.loaded / e.total) * 100;
838
+ $scope.max = e.total;
839
+ if ($scope.value === 100) {
840
+ $(progress).hide();
841
+ }
1361
842
  }
1362
843
 
1363
- if (file) {
1364
- scope.ngModel = file;
1365
- scope.onUploaded();
844
+ if (image) {
845
+ $scope.ngModel = image;
846
+ if ($scope.ngChange) {
847
+ $scope.ngChange();
848
+ }
1366
849
  }
1367
850
  }
1368
851
  );
1369
852
  });
1370
853
 
1371
- scope.$watch('ngModel', (ngModel) => {
854
+ $scope.$watch('ngModel', (ngModel) => {
1372
855
  if (ngModel) {
1373
- a.setAttribute('url', ngModel);
856
+ img.setAttribute('src', ngModel.url);
1374
857
  }
1375
858
  });
1376
859
  },
1377
- template: `
1378
- <form class="form text-center pointer">
1379
- <input class="hidden" type="file" name="file" />
1380
- <a class="btn {{type}}" ngClick="ngClick()" url="{{ngModel}}"> {{label}} </a>
1381
- <progress class="row"></progress>
1382
- </form>
1383
- `,
1384
- };
1385
- },
1386
- ]);
1387
-
1388
- app.directive('iFiles', [
1389
- '$interval',
1390
- 'isite',
1391
- function ($interval, isite) {
1392
- return {
1393
- restrict: 'E',
1394
- required: 'ngModel',
1395
- scope: {
1396
- category: '@',
1397
- label: '@',
1398
- ngModel: '=',
1399
- },
1400
- link: function (scope, element, attrs, ctrl) {
1401
- if (attrs.view === '') {
1402
- scope.viewOnly = !0;
1403
- }
1404
-
1405
- let progress = $(element).find('progress')[0];
1406
-
1407
- scope.category = scope.category || 'default';
1408
- scope.id = Math.random().toString().replace('.', '_');
1409
- scope.deleteFile = function (file) {
1410
- isite.deleteFile(file, () => {
1411
- for (let i = 0; i < scope.ngModel.length; i++) {
1412
- let f = scope.ngModel[i];
1413
- if (f.url === file.url) {
1414
- scope.ngModel.splice(i, 1);
1415
- return;
1416
- }
1417
- }
1418
- });
1419
- };
1420
-
1421
- let setEvent = !1;
1422
- $interval(() => {
1423
- if (setEvent) {
1424
- return;
1425
- }
1426
-
1427
- if (attrs.view !== '') {
1428
- let btn = document.querySelector('#btn_' + scope.id);
1429
- if (btn) {
1430
- setEvent = !0;
1431
- btn.addEventListener('click', function () {
1432
- document.querySelector('#input_' + scope.id).click();
1433
- });
1434
- }
1435
-
1436
- let input = document.querySelector('#input_' + scope.id);
1437
- if (input) {
1438
- input.addEventListener('change', function () {
1439
- isite.uploadFile(
1440
- this.files,
1441
- {
1442
- category: scope.category,
1443
- },
1444
- (err, file, e) => {
1445
- if (e) {
1446
- $(progress).show();
1447
- progress.value = e.loaded;
1448
- progress.max = e.total;
1449
- }
1450
-
1451
- if (file) {
1452
- if (typeof scope.ngModel === 'undefined') {
1453
- scope.ngModel = [];
1454
- }
1455
- scope.ngModel.push(file);
1456
- }
1457
- }
1458
- );
1459
- });
1460
- }
1461
- } else {
1462
- setEvent = !0;
1463
- }
1464
- }, 500);
1465
- },
1466
- template: `
1467
- <div class="files">
1468
- <label> {{label}} </label>
1469
- <form ng-if="viewOnly !== !0" id="img_{{id}}" class="form text-center pointer">
1470
- <input id="input_{{id}}" class="hidden" type="file" name="file" />
1471
- <a id="btn_{{id}}" class="btn bg-green"> <i class="fa fa-upload white"></i> </a>
1472
- </form>
1473
- <progress class="row"></progress>
1474
- <div class="padding">
1475
-
1476
- <div class="row padding" ng-repeat="f in ngModel">
1477
- <h2>
1478
- <a class="btn default bg-blue" href="{{f.url}}"> <i class="fa fa-2x fa-download white"></i> </a>
1479
- <a ng-if="viewOnly !== !0" class="btn default bg-red" ng-click="deleteFile(f)"> <i class="fa fa-trash white"></i> </a>
1480
- <span> {{f.name}} </span>
1481
- </h2>
1482
- </div>
1483
- </div>
1484
- </div>
1485
-
1486
- `,
1487
- };
1488
- },
1489
- ]);
1490
-
1491
- app.directive('iDrag', [
1492
- '$document',
1493
- function ($document) {
1494
- return function (scope, element, attr) {
1495
- var startX = 0,
1496
- startY = 0,
1497
- x = 0,
1498
- y = 0;
1499
-
1500
- element.css({
1501
- position: 'relative',
1502
- });
1503
-
1504
- element.on('mousedown', function (event) {
1505
- event.preventDefault();
1506
- startX = event.screenX - x;
1507
- startY = event.screenY - y;
1508
- $document.on('mousemove', mousemove);
1509
- $document.on('mouseup', mouseup);
1510
- });
1511
-
1512
- function mousemove(event) {
1513
- y = event.screenY - startY;
1514
- x = event.screenX - startX;
1515
- element.css({
1516
- top: y + 'px',
1517
- left: x + 'px',
1518
- });
1519
- }
1520
-
1521
- function mouseup() {
1522
- $document.off('mousemove', mousemove);
1523
- $document.off('mouseup', mouseup);
1524
- }
860
+ template: `/*##client-side/directive/i-image.html*/`,
1525
861
  };
1526
862
  },
1527
863
  ]);