ps-toolkit-ui 0.0.210 → 0.0.211
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.
- package/karma.conf.js +32 -0
- package/ng-package.json +16 -0
- package/package.json +19 -22
- package/src/lib/classes/chart.class.ts +140 -0
- package/src/lib/classes/enum.class.ts +193 -0
- package/src/lib/classes/excel.class.ts +46 -0
- package/src/lib/classes/form.class.ts +528 -0
- package/src/lib/classes/helper.class.ts +283 -0
- package/src/lib/classes/lang.class.ts +32 -0
- package/src/lib/classes/login.class.ts +27 -0
- package/src/lib/classes/modal.class.ts +59 -0
- package/src/lib/classes/permission.class.ts +55 -0
- package/src/lib/classes/request.class.ts +255 -0
- package/src/lib/classes/safestyle.class.ts +4 -0
- package/src/lib/classes/sidebar.class.ts +20 -0
- package/src/lib/classes/steps.class.ts +19 -0
- package/src/lib/classes/string.class.ts +219 -0
- package/src/lib/classes/table.class.ts +228 -0
- package/src/lib/components/accordion/accordion.component.css +116 -0
- package/src/lib/components/accordion/accordion.component.html +19 -0
- package/src/lib/components/accordion/accordion.component.ts +41 -0
- package/src/lib/components/alert/alert.component.css +112 -0
- package/src/lib/components/alert/alert.component.html +1 -0
- package/src/lib/components/alert/alert.component.ts +35 -0
- package/src/lib/components/base.component.ts +38 -0
- package/src/lib/components/calendar/calendar.component.css +206 -0
- package/src/lib/components/calendar/calendar.component.html +36 -0
- package/src/lib/components/calendar/calendar.component.ts +99 -0
- package/src/lib/components/chart/chart.component.css +24 -0
- package/src/lib/components/chart/chart.component.html +6 -0
- package/src/lib/components/chart/chart.component.ts +14 -0
- package/src/lib/components/clock/clock.component.css +141 -0
- package/src/lib/components/clock/clock.component.html +10 -0
- package/src/lib/components/clock/clock.component.ts +37 -0
- package/src/lib/components/confirm/confirm.component.css +112 -0
- package/src/lib/components/confirm/confirm.component.html +1 -0
- package/src/lib/components/confirm/confirm.component.ts +47 -0
- package/src/lib/components/footer/footer.component.css +46 -0
- package/src/lib/components/footer/footer.component.html +9 -0
- package/src/lib/components/footer/footer.component.ts +18 -0
- package/src/lib/components/form/bank-card/form.bank-card.component.css +115 -0
- package/src/lib/components/form/bank-card/form.bank-card.component.html +13 -0
- package/src/lib/components/form/bank-card/form.bank-card.component.ts +144 -0
- package/src/lib/components/form/button/form.button.component.css +222 -0
- package/src/lib/components/form/button/form.button.component.html +16 -0
- package/src/lib/components/form/button/form.button.component.ts +65 -0
- package/src/lib/components/form/car/form.car.component.css +287 -0
- package/src/lib/components/form/car/form.car.component.html +11 -0
- package/src/lib/components/form/car/form.car.component.ts +82 -0
- package/src/lib/components/form/car/search/form.car.search.component.css +287 -0
- package/src/lib/components/form/car/search/form.car.search.component.html +15 -0
- package/src/lib/components/form/car/search/form.car.search.component.ts +170 -0
- package/src/lib/components/form/checkbox/form.checkbox.component.css +128 -0
- package/src/lib/components/form/checkbox/form.checkbox.component.html +8 -0
- package/src/lib/components/form/checkbox/form.checkbox.component.ts +64 -0
- package/src/lib/components/form/date/form.date.component.css +310 -0
- package/src/lib/components/form/date/form.date.component.html +46 -0
- package/src/lib/components/form/date/form.date.component.ts +247 -0
- package/src/lib/components/form/datetime/form.datetime.component.css +157 -0
- package/src/lib/components/form/datetime/form.datetime.component.html +11 -0
- package/src/lib/components/form/datetime/form.datetime.component.ts +98 -0
- package/src/lib/components/form/file/form.file.component.css +151 -0
- package/src/lib/components/form/file/form.file.component.html +12 -0
- package/src/lib/components/form/file/form.file.component.ts +130 -0
- package/src/lib/components/form/finger/form.finger.component.css +215 -0
- package/src/lib/components/form/finger/form.finger.component.html +59 -0
- package/src/lib/components/form/finger/form.finger.component.ts +131 -0
- package/src/lib/components/form/hidden/form.hidden.component.css +0 -0
- package/src/lib/components/form/hidden/form.hidden.component.html +0 -0
- package/src/lib/components/form/hidden/form.hidden.component.ts +29 -0
- package/src/lib/components/form/icon/form.icon.component.css +108 -0
- package/src/lib/components/form/icon/form.icon.component.html +14 -0
- package/src/lib/components/form/icon/form.icon.component.ts +73 -0
- package/src/lib/components/form/index/form.component.css +89 -0
- package/src/lib/components/form/index/form.component.html +35 -0
- package/src/lib/components/form/index/form.component.ts +45 -0
- package/src/lib/components/form/label/form.label.component.css +45 -0
- package/src/lib/components/form/label/form.label.component.html +2 -0
- package/src/lib/components/form/label/form.label.component.ts +30 -0
- package/src/lib/components/form/plaque/form.plaque.component.css +76 -0
- package/src/lib/components/form/plaque/form.plaque.component.html +10 -0
- package/src/lib/components/form/plaque/form.plaque.component.ts +178 -0
- package/src/lib/components/form/plaque/select/form.plaque.select.component.css +167 -0
- package/src/lib/components/form/plaque/select/form.plaque.select.component.html +19 -0
- package/src/lib/components/form/plaque/select/form.plaque.select.component.ts +385 -0
- package/src/lib/components/form/radio/form.radio.component.css +158 -0
- package/src/lib/components/form/radio/form.radio.component.html +16 -0
- package/src/lib/components/form/radio/form.radio.component.ts +78 -0
- package/src/lib/components/form/select/form.select.component.css +326 -0
- package/src/lib/components/form/select/form.select.component.html +16 -0
- package/src/lib/components/form/select/form.select.component.ts +358 -0
- package/src/lib/components/form/select/item/form.select.item.component.css +59 -0
- package/src/lib/components/form/select/item/form.select.item.component.html +10 -0
- package/src/lib/components/form/select/item/form.select.item.component.ts +40 -0
- package/src/lib/components/form/table/form.table.component.css +50 -0
- package/src/lib/components/form/table/form.table.component.html +8 -0
- package/src/lib/components/form/table/form.table.component.ts +94 -0
- package/src/lib/components/form/textarea/form.textarea.component.css +109 -0
- package/src/lib/components/form/textarea/form.textarea.component.html +10 -0
- package/src/lib/components/form/textarea/form.textarea.component.ts +76 -0
- package/src/lib/components/form/textbox/form.textbox.component.css +296 -0
- package/src/lib/components/form/textbox/form.textbox.component.html +13 -0
- package/src/lib/components/form/textbox/form.textbox.component.ts +185 -0
- package/src/lib/components/form/time/form.time.component.css +205 -0
- package/src/lib/components/form/time/form.time.component.html +22 -0
- package/src/lib/components/form/time/form.time.component.ts +139 -0
- package/src/lib/components/form/tree/form.tree.component.css +109 -0
- package/src/lib/components/form/tree/form.tree.component.html +11 -0
- package/src/lib/components/form/tree/form.tree.component.ts +98 -0
- package/src/lib/components/form/tree/item/form.tree.item.component.css +142 -0
- package/src/lib/components/form/tree/item/form.tree.item.component.html +9 -0
- package/src/lib/components/form/tree/item/form.tree.item.component.ts +49 -0
- package/src/lib/components/header/header.component.css +57 -0
- package/src/lib/components/header/header.component.html +5 -0
- package/src/lib/components/header/header.component.ts +28 -0
- package/src/lib/components/header/sub/sub.header.component.css +62 -0
- package/src/lib/components/header/sub/sub.header.component.html +8 -0
- package/src/lib/components/header/sub/sub.header.component.ts +11 -0
- package/src/lib/components/layout/layout.component.css +300 -0
- package/src/lib/components/layout/layout.component.html +20 -0
- package/src/lib/components/layout/layout.component.ts +21 -0
- package/src/lib/components/loading/loading.component.css +39 -0
- package/src/lib/components/loading/loading.component.html +8 -0
- package/src/lib/components/loading/loading.component.ts +18 -0
- package/src/lib/components/login/login.component.css +389 -0
- package/src/lib/components/login/login.component.html +27 -0
- package/src/lib/components/login/login.component.ts +145 -0
- package/src/lib/components/modal/modal.component.css +60 -0
- package/src/lib/components/modal/modal.component.html +12 -0
- package/src/lib/components/modal/modal.component.ts +23 -0
- package/src/lib/components/notfound/notfound.component.css +134 -0
- package/src/lib/components/notfound/notfound.component.html +10 -0
- package/src/lib/components/notfound/notfound.component.ts +25 -0
- package/src/lib/components/notification/notification.component.css +45 -0
- package/src/lib/components/notification/notification.component.html +2 -0
- package/src/lib/components/notification/notification.component.ts +11 -0
- package/src/lib/components/sidebar/item/sidebar.item.component.css +236 -0
- package/src/lib/components/sidebar/item/sidebar.item.component.html +16 -0
- package/src/lib/components/sidebar/item/sidebar.item.component.ts +54 -0
- package/src/lib/components/sidebar/sidebar.component.css +42 -0
- package/src/lib/components/sidebar/sidebar.component.html +10 -0
- package/src/lib/components/sidebar/sidebar.component.ts +60 -0
- package/src/lib/components/steps/steps.component.css +320 -0
- package/src/lib/components/steps/steps.component.html +18 -0
- package/src/lib/components/steps/steps.component.ts +44 -0
- package/src/lib/components/table/loading/table.loading.component.css +29 -0
- package/src/lib/components/table/loading/table.loading.component.html +9 -0
- package/src/lib/components/table/loading/table.loading.component.ts +14 -0
- package/src/lib/components/table/pagination/table.pagination.component.css +138 -0
- package/src/lib/components/table/pagination/table.pagination.component.html +9 -0
- package/src/lib/components/table/pagination/table.pagination.component.ts +89 -0
- package/src/lib/components/table/report/table.report.component.css +125 -0
- package/src/lib/components/table/report/table.report.component.html +19 -0
- package/src/lib/components/table/report/table.report.component.ts +238 -0
- package/src/lib/components/table/row/table.row.component.css +170 -0
- package/src/lib/components/table/row/table.row.component.html +21 -0
- package/src/lib/components/table/row/table.row.component.ts +373 -0
- package/src/lib/components/table/table.component.css +116 -0
- package/src/lib/components/table/table.component.html +62 -0
- package/src/lib/components/table/table.component.ts +180 -0
- package/src/lib/components/tooltip/tooltip.component.css +159 -0
- package/src/lib/components/tooltip/tooltip.component.html +1 -0
- package/src/lib/components/tooltip/tooltip.component.ts +15 -0
- package/src/lib/ps-toolkit-ui.module.ts +94 -0
- package/src/lib/services/config.service.ts +8 -0
- package/{public-api.d.ts → src/public-api.ts} +53 -48
- package/src/test.ts +26 -0
- package/tsconfig.lib.json +25 -0
- package/tsconfig.lib.prod.json +10 -0
- package/tsconfig.spec.json +17 -0
- package/tslint.json +17 -0
- package/bundles/ps-toolkit-ui.umd.js +0 -7646
- package/bundles/ps-toolkit-ui.umd.js.map +0 -1
- package/bundles/ps-toolkit-ui.umd.min.js +0 -2
- package/bundles/ps-toolkit-ui.umd.min.js.map +0 -1
- package/esm2015/lib/classes/chart.class.js +0 -140
- package/esm2015/lib/classes/enum.class.js +0 -187
- package/esm2015/lib/classes/form.class.js +0 -481
- package/esm2015/lib/classes/helper.class.js +0 -284
- package/esm2015/lib/classes/lang.class.js +0 -32
- package/esm2015/lib/classes/login.class.js +0 -22
- package/esm2015/lib/classes/modal.class.js +0 -52
- package/esm2015/lib/classes/permission.class.js +0 -61
- package/esm2015/lib/classes/request.class.js +0 -256
- package/esm2015/lib/classes/safestyle.class.js +0 -15
- package/esm2015/lib/classes/sidebar.class.js +0 -14
- package/esm2015/lib/classes/steps.class.js +0 -20
- package/esm2015/lib/classes/string.class.js +0 -220
- package/esm2015/lib/classes/table.class.js +0 -215
- package/esm2015/lib/components/accordion/accordion.component.js +0 -45
- package/esm2015/lib/components/alert/alert.component.js +0 -39
- package/esm2015/lib/components/base.component.js +0 -45
- package/esm2015/lib/components/calendar/calendar.component.js +0 -97
- package/esm2015/lib/components/chart/chart.component.js +0 -17
- package/esm2015/lib/components/clock/clock.component.js +0 -33
- package/esm2015/lib/components/confirm/confirm.component.js +0 -50
- package/esm2015/lib/components/footer/footer.component.js +0 -23
- package/esm2015/lib/components/form/bank-card/form.bank-card.component.js +0 -148
- package/esm2015/lib/components/form/button/form.button.component.js +0 -68
- package/esm2015/lib/components/form/car/form.car.component.js +0 -84
- package/esm2015/lib/components/form/car/search/form.car.search.component.js +0 -172
- package/esm2015/lib/components/form/checkbox/form.checkbox.component.js +0 -66
- package/esm2015/lib/components/form/date/form.date.component.js +0 -254
- package/esm2015/lib/components/form/datetime/form.datetime.component.js +0 -104
- package/esm2015/lib/components/form/file/form.file.component.js +0 -133
- package/esm2015/lib/components/form/finger/form.finger.component.js +0 -138
- package/esm2015/lib/components/form/hidden/form.hidden.component.js +0 -31
- package/esm2015/lib/components/form/icon/form.icon.component.js +0 -76
- package/esm2015/lib/components/form/index/form.component.js +0 -48
- package/esm2015/lib/components/form/label/form.label.component.js +0 -32
- package/esm2015/lib/components/form/plaque/form.plaque.component.js +0 -176
- package/esm2015/lib/components/form/plaque/select/form.plaque.select.component.js +0 -390
- package/esm2015/lib/components/form/radio/form.radio.component.js +0 -79
- package/esm2015/lib/components/form/select/form.select.component.js +0 -374
- package/esm2015/lib/components/form/select/item/form.select.item.component.js +0 -43
- package/esm2015/lib/components/form/table/form.table.component.js +0 -98
- package/esm2015/lib/components/form/textarea/form.textarea.component.js +0 -78
- package/esm2015/lib/components/form/textbox/form.textbox.component.js +0 -186
- package/esm2015/lib/components/form/time/form.time.component.js +0 -145
- package/esm2015/lib/components/form/tree/form.tree.component.js +0 -99
- package/esm2015/lib/components/form/tree/item/form.tree.item.component.js +0 -48
- package/esm2015/lib/components/header/header.component.js +0 -33
- package/esm2015/lib/components/header/sub/sub.header.component.js +0 -14
- package/esm2015/lib/components/layout/layout.component.js +0 -25
- package/esm2015/lib/components/loading/loading.component.js +0 -22
- package/esm2015/lib/components/login/login.component.js +0 -148
- package/esm2015/lib/components/modal/modal.component.js +0 -25
- package/esm2015/lib/components/notfound/notfound.component.js +0 -29
- package/esm2015/lib/components/notification/notification.component.js +0 -14
- package/esm2015/lib/components/sidebar/item/sidebar.item.component.js +0 -53
- package/esm2015/lib/components/sidebar/sidebar.component.js +0 -67
- package/esm2015/lib/components/steps/steps.component.js +0 -51
- package/esm2015/lib/components/table/loading/table.loading.component.js +0 -17
- package/esm2015/lib/components/table/pagination/table.pagination.component.js +0 -84
- package/esm2015/lib/components/table/report/table.report.component.js +0 -246
- package/esm2015/lib/components/table/row/table.row.component.js +0 -379
- package/esm2015/lib/components/table/table.component.js +0 -179
- package/esm2015/lib/components/tooltip/tooltip.component.js +0 -19
- package/esm2015/lib/ps-toolkit-ui.module.js +0 -95
- package/esm2015/lib/services/config.service.js +0 -14
- package/esm2015/ps-toolkit-ui.js +0 -20
- package/esm2015/public-api.js +0 -52
- package/fesm2015/ps-toolkit-ui.js +0 -6566
- package/fesm2015/ps-toolkit-ui.js.map +0 -1
- package/lib/classes/chart.class.d.ts +0 -11
- package/lib/classes/enum.class.d.ts +0 -158
- package/lib/classes/form.class.d.ts +0 -173
- package/lib/classes/helper.class.d.ts +0 -28
- package/lib/classes/lang.class.d.ts +0 -5
- package/lib/classes/login.class.d.ts +0 -17
- package/lib/classes/modal.class.d.ts +0 -19
- package/lib/classes/permission.class.d.ts +0 -31
- package/lib/classes/request.class.d.ts +0 -12
- package/lib/classes/safestyle.class.d.ts +0 -7
- package/lib/classes/sidebar.class.d.ts +0 -11
- package/lib/classes/steps.class.d.ts +0 -17
- package/lib/classes/string.class.d.ts +0 -218
- package/lib/classes/table.class.d.ts +0 -69
- package/lib/components/accordion/accordion.component.d.ts +0 -7
- package/lib/components/alert/alert.component.d.ts +0 -10
- package/lib/components/base.component.d.ts +0 -14
- package/lib/components/calendar/calendar.component.d.ts +0 -26
- package/lib/components/chart/chart.component.d.ts +0 -5
- package/lib/components/clock/clock.component.d.ts +0 -11
- package/lib/components/confirm/confirm.component.d.ts +0 -14
- package/lib/components/footer/footer.component.d.ts +0 -6
- package/lib/components/form/bank-card/form.bank-card.component.d.ts +0 -22
- package/lib/components/form/button/form.button.component.d.ts +0 -15
- package/lib/components/form/car/form.car.component.d.ts +0 -16
- package/lib/components/form/car/search/form.car.search.component.d.ts +0 -17
- package/lib/components/form/checkbox/form.checkbox.component.d.ts +0 -14
- package/lib/components/form/date/form.date.component.d.ts +0 -42
- package/lib/components/form/datetime/form.datetime.component.d.ts +0 -13
- package/lib/components/form/file/form.file.component.d.ts +0 -17
- package/lib/components/form/finger/form.finger.component.d.ts +0 -15
- package/lib/components/form/hidden/form.hidden.component.d.ts +0 -7
- package/lib/components/form/icon/form.icon.component.d.ts +0 -15
- package/lib/components/form/index/form.component.d.ts +0 -10
- package/lib/components/form/label/form.label.component.d.ts +0 -8
- package/lib/components/form/plaque/form.plaque.component.d.ts +0 -22
- package/lib/components/form/plaque/select/form.plaque.select.component.d.ts +0 -36
- package/lib/components/form/radio/form.radio.component.d.ts +0 -13
- package/lib/components/form/select/form.select.component.d.ts +0 -39
- package/lib/components/form/select/item/form.select.item.component.d.ts +0 -12
- package/lib/components/form/table/form.table.component.d.ts +0 -9
- package/lib/components/form/textarea/form.textarea.component.d.ts +0 -13
- package/lib/components/form/textbox/form.textbox.component.d.ts +0 -20
- package/lib/components/form/time/form.time.component.d.ts +0 -25
- package/lib/components/form/tree/form.tree.component.d.ts +0 -16
- package/lib/components/form/tree/item/form.tree.item.component.d.ts +0 -17
- package/lib/components/header/header.component.d.ts +0 -9
- package/lib/components/header/sub/sub.header.component.d.ts +0 -3
- package/lib/components/layout/layout.component.d.ts +0 -8
- package/lib/components/loading/loading.component.d.ts +0 -5
- package/lib/components/login/login.component.d.ts +0 -13
- package/lib/components/modal/modal.component.d.ts +0 -9
- package/lib/components/notfound/notfound.component.d.ts +0 -8
- package/lib/components/notification/notification.component.d.ts +0 -3
- package/lib/components/sidebar/item/sidebar.item.component.d.ts +0 -14
- package/lib/components/sidebar/sidebar.component.d.ts +0 -19
- package/lib/components/steps/steps.component.d.ts +0 -10
- package/lib/components/table/loading/table.loading.component.d.ts +0 -5
- package/lib/components/table/pagination/table.pagination.component.d.ts +0 -15
- package/lib/components/table/report/table.report.component.d.ts +0 -34
- package/lib/components/table/row/table.row.component.d.ts +0 -34
- package/lib/components/table/table.component.d.ts +0 -40
- package/lib/components/tooltip/tooltip.component.d.ts +0 -5
- package/lib/ps-toolkit-ui.module.d.ts +0 -4
- package/lib/services/config.service.d.ts +0 -6
- package/ps-toolkit-ui.d.ts +0 -19
- package/ps-toolkit-ui.metadata.json +0 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<div #inputDiv [id]="inp.name + 'Input'" [style]="inp.style" [className]="inp.class + ' form-input-con date' + (inp.error == null ? '' : ' error') + (inp.disabled ? ' disabled' : '')">
|
|
2
|
+
<div class="form-input" (click)="toggleCalendar()">
|
|
3
|
+
<div *ngIf="inp.displayLabel" class="label"><i *ngIf="inp.required" class="fas fa-star-of-life required-icon"></i>{{inp.getLabel()}}</div>
|
|
4
|
+
<div class="w-100 p-r">
|
|
5
|
+
<i *ngIf="inp.icon != null || inp.loading" #inputIcon [className]="(inp.loading ? 'fa-duotone fa-spin fa-spinner' : inp.icon) + ' icon'"></i>
|
|
6
|
+
<i *ngIf="inp.withClear && inp.value" (click)="inp.clear()" class="fa-duotone fa-eraser clear-icon"></i>
|
|
7
|
+
<input (keydown)="onKeyDown($event)" (keyup)="onKeyUp($event)" (focusout)="onFocusOut()" [disabled]="inp.disabled" [(ngModel)]="inp.search" #inputBase [name]="inp.name" [placeholder]="inp.l(inp.name)" class="control" autocomplete="off" maxlength="">
|
|
8
|
+
<div #inputCalendarDiv class="calendar">
|
|
9
|
+
<div class="header">
|
|
10
|
+
<i (click)="add(state === 'day' || state === 'month' ? -1 : -20)" class="fas fa-angle-right previous-month"></i>
|
|
11
|
+
<div class="title">
|
|
12
|
+
<div (click)="(state === 'day' || state === 'month') && changeState('year')" class="year header-item">
|
|
13
|
+
{{active.format('jYYYY')}}
|
|
14
|
+
</div>
|
|
15
|
+
<div (click)="state === 'day' && changeState('month')" class="month header-item">
|
|
16
|
+
{{getActiveMonth()}}
|
|
17
|
+
</div>
|
|
18
|
+
</div>
|
|
19
|
+
<i (click)="add(state === 'day' || state === 'month' ? 1 : 20)" class="fas fa-angle-left next-month"></i>
|
|
20
|
+
</div>
|
|
21
|
+
<div [style]="state === 'day' ? {} : {display: 'none'}" class="days-con">
|
|
22
|
+
<div class="day-names underline">
|
|
23
|
+
<div class="item">ش</div>
|
|
24
|
+
<div class="item">ی</div>
|
|
25
|
+
<div class="item">د</div>
|
|
26
|
+
<div class="item">س</div>
|
|
27
|
+
<div class="item">چ</div>
|
|
28
|
+
<div class="item">پ</div>
|
|
29
|
+
<div class="item">ج</div>
|
|
30
|
+
</div>
|
|
31
|
+
<div class="days">
|
|
32
|
+
<div [className]="'item not-in-month' + (d.today ? ' today' : '')" *ngFor="let d of previousDays">{{d.day}}</div>
|
|
33
|
+
<div (click)="selectDate(d)" [className]="'item' + (d.today ? ' today' : '') + (d.selected ? ' selected' : '')" *ngFor="let d of days">{{d.day}}</div>
|
|
34
|
+
<div [className]="'item not-in-month' + (d.today ? ' today' : '')" *ngFor="let d of nextDays">{{d.day}}</div>
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
<div [style]="state === 'month' ? {} : {display: 'none'}" class="months-con">
|
|
38
|
+
<div [className]="(i + 1 == active.format('jM') ? 'selected ' : '') + 'month'" (click)="changeMonth(i + 1)" *ngFor="let m of months; let i = index">{{m}}</div>
|
|
39
|
+
</div>
|
|
40
|
+
<div [style]="state === 'year' ? {} : {display: 'none'}" class="years-con">
|
|
41
|
+
<div [className]="(y == active.format('jYYYY') ? 'selected ' : '') + 'year'" (click)="changeYear(y)" *ngFor="let y of getYears()">{{y}}</div>
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
|
|
2
|
+
import * as moment from 'jalali-moment';
|
|
3
|
+
import * as $ from 'jquery';
|
|
4
|
+
import {DayClass, InputClass} from '../../../classes/form.class';
|
|
5
|
+
import {InputError} from '../../../classes/enum.class';
|
|
6
|
+
|
|
7
|
+
@Component({
|
|
8
|
+
selector: 'lib-form-date',
|
|
9
|
+
templateUrl: './form.date.component.html',
|
|
10
|
+
styleUrls: ['./form.date.component.css']
|
|
11
|
+
})
|
|
12
|
+
export class FormDateComponent implements OnInit{
|
|
13
|
+
@Input()
|
|
14
|
+
inp: InputClass;
|
|
15
|
+
@Input()
|
|
16
|
+
inForm: boolean;
|
|
17
|
+
@Output()
|
|
18
|
+
changeIndex = new EventEmitter<string>();
|
|
19
|
+
previousDays: DayClass[] = [];
|
|
20
|
+
nextDays: DayClass[] = [];
|
|
21
|
+
days: DayClass[] = [];
|
|
22
|
+
todayDay: number;
|
|
23
|
+
todayMonth: number;
|
|
24
|
+
todayYear: number;
|
|
25
|
+
cSearch = '';
|
|
26
|
+
state = 'day';
|
|
27
|
+
months = ['فروردین', 'اردیبهشت', 'خرداد', 'تیر', 'مرداد', 'شهریور', 'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند'];
|
|
28
|
+
active: moment.Moment = moment();
|
|
29
|
+
@ViewChild('inputBase') inputBase: ElementRef;
|
|
30
|
+
@ViewChild('inputDiv') inputDiv: ElementRef;
|
|
31
|
+
@ViewChild('inputLabel') inputLabel: ElementRef;
|
|
32
|
+
@ViewChild('inputCalendarDiv') inputCalendarDiv: ElementRef;
|
|
33
|
+
constructor(){
|
|
34
|
+
}
|
|
35
|
+
ngOnInit(): void{
|
|
36
|
+
// moment.locale('fa');
|
|
37
|
+
const today = moment().locale('fa');
|
|
38
|
+
this.todayDay = parseInt(today.format('jDD'), 10);
|
|
39
|
+
this.todayMonth = parseInt(today.format('jMM'), 10);
|
|
40
|
+
this.todayYear = parseInt(today.format('jYYYY'), 10);
|
|
41
|
+
this.setInpValue(this.inp.value);
|
|
42
|
+
this.inp.setValue = (v) => {
|
|
43
|
+
this.setInpValue(v);
|
|
44
|
+
};
|
|
45
|
+
this.inp.isValid = () => {
|
|
46
|
+
this.inp.error = null;
|
|
47
|
+
if (this.inp.required && !this.inp.value) {
|
|
48
|
+
this.inp.error = InputError.Required;
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (!this.inp.required && !this.inp.value) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
if (!moment(this.inp.value, 'jYYYY/jMM/jDD').isValid()) {
|
|
55
|
+
this.inp.error = InputError.Invalid;
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
};
|
|
60
|
+
this.inp.clear = () => {
|
|
61
|
+
if (this.inp.default){
|
|
62
|
+
this.inp.setValue(this.inp.default, false);
|
|
63
|
+
}else{
|
|
64
|
+
this.inp.value = null;
|
|
65
|
+
this.inp.search = null;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
this.inp.data = () => {
|
|
69
|
+
return this.inp.value ? moment(this.inp.value, 'jYYYY/jMM/jDD').locale('en').format('YYYY/MM/DD') : null;
|
|
70
|
+
};
|
|
71
|
+
this.inp.focus = () => {
|
|
72
|
+
this.openCalendar();
|
|
73
|
+
};
|
|
74
|
+
this.inp.focusOut = () => {
|
|
75
|
+
$(this.inputBase.nativeElement).blur();
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
setInpValue(v): void{
|
|
79
|
+
if (v === null){
|
|
80
|
+
this.inp.clear();
|
|
81
|
+
return;
|
|
82
|
+
} else if (typeof v === 'string') {
|
|
83
|
+
const d = parseInt(v.substring(6, v.length - 2), 10);
|
|
84
|
+
this.active = moment(d);
|
|
85
|
+
}else if (typeof v === 'number'){
|
|
86
|
+
this.active = moment(v);
|
|
87
|
+
}else {
|
|
88
|
+
this.active = v;
|
|
89
|
+
}
|
|
90
|
+
this.inp.value = this.active.format('jYYYY/jMM/jDD');
|
|
91
|
+
this.inp.search = this.active.format('jYYYY/jMM/jDD');
|
|
92
|
+
this.setDate();
|
|
93
|
+
}
|
|
94
|
+
setDate(): void{
|
|
95
|
+
const n = this.active.clone();
|
|
96
|
+
const countDayInMonth = n.daysInMonth();
|
|
97
|
+
const startWeek = parseInt(n.startOf('month').format('d'), 10);
|
|
98
|
+
const previousMonth = n.subtract(1, 'month');
|
|
99
|
+
const countDayInPreviousMonth = previousMonth.daysInMonth();
|
|
100
|
+
const nextMonth = n.add(2, 'month');
|
|
101
|
+
const previousDays: DayClass[] = [];
|
|
102
|
+
const nextDays = [];
|
|
103
|
+
const days = [];
|
|
104
|
+
if (startWeek !== 6){
|
|
105
|
+
for (let i = countDayInPreviousMonth - startWeek; i <= countDayInPreviousMonth; i++){
|
|
106
|
+
previousDays.push(new DayClass(i, this.isToday(previousMonth, i), false));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
for (let i = 1; i <= countDayInMonth; i++){
|
|
110
|
+
days.push(new DayClass(i, this.isToday(this.active, i), this.isSelected(this.active, i)));
|
|
111
|
+
}
|
|
112
|
+
const end = (days.length + previousDays.length) % 7;
|
|
113
|
+
if (end !== 0){
|
|
114
|
+
for (let i = 1; i <= 7 - end; i++){
|
|
115
|
+
nextDays.push(new DayClass(i, this.isToday(nextMonth, i), false));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
this.previousDays = previousDays;
|
|
119
|
+
this.nextDays = nextDays;
|
|
120
|
+
this.days = days;
|
|
121
|
+
}
|
|
122
|
+
isToday(m: moment.Moment, d: number): boolean{
|
|
123
|
+
const month = parseInt(m.format('jMM'), 10);
|
|
124
|
+
const year = parseInt(m.format('jYYYY'), 10);
|
|
125
|
+
return year === this.todayYear && month === this.todayMonth && d === this.todayDay;
|
|
126
|
+
}
|
|
127
|
+
isSelected(m: moment.Moment, d: number): boolean{
|
|
128
|
+
if (this.inp.value == null){
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
const month = parseInt(m.format('jMM'), 10);
|
|
132
|
+
const year = parseInt(m.format('jYYYY'), 10);
|
|
133
|
+
const vDay = parseInt(this.inp.value.split('/')[2], 10);
|
|
134
|
+
const vMonth = parseInt(this.inp.value.split('/')[1], 10);
|
|
135
|
+
const vYear = parseInt(this.inp.value.split('/')[0], 10);
|
|
136
|
+
return year === vYear && month === vMonth && d === vDay;
|
|
137
|
+
}
|
|
138
|
+
add(c: number): void{
|
|
139
|
+
this.active.add(c, this.state === 'day' ? 'month' : 'year');
|
|
140
|
+
this.setDate();
|
|
141
|
+
}
|
|
142
|
+
changeMonth(c: number): void{
|
|
143
|
+
this.active = moment(this.active.format('jYYYY') + '/' + ('0' + c).slice(-2) + '/' + this.active.format('jDD'), 'jYYYY/jMM/jDD');
|
|
144
|
+
this.setDate();
|
|
145
|
+
this.changeState('day');
|
|
146
|
+
}
|
|
147
|
+
changeYear(c: number): void{
|
|
148
|
+
this.active = moment(('000' + c).slice(-4) + '/' + this.active.format('jMM') + '/' + this.active.format('jDD'), 'jYYYY/jMM/jDD');
|
|
149
|
+
this.setDate();
|
|
150
|
+
this.changeState('month');
|
|
151
|
+
}
|
|
152
|
+
toggleCalendar(): void{
|
|
153
|
+
this.openCalendar();
|
|
154
|
+
}
|
|
155
|
+
openCalendar(): void {
|
|
156
|
+
this.setPosition();
|
|
157
|
+
$(this.inputBase.nativeElement).focus();
|
|
158
|
+
}
|
|
159
|
+
onKeyDown(e): void{
|
|
160
|
+
const code = e.keyCode || e.which;
|
|
161
|
+
if (code === 9 || code === 13) {
|
|
162
|
+
e.preventDefault();
|
|
163
|
+
$(this.inputDiv.nativeElement).removeClass('top');
|
|
164
|
+
this.changeIndex.emit(code === 9 ? e.shiftKey ? 'ShiftTab' : 'Tab' : e.shiftKey ? 'ShiftEnter' : 'Enter');
|
|
165
|
+
if (!this.inForm){
|
|
166
|
+
$(this.inputBase.nativeElement).blur();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
onKeyUp(e): void{
|
|
171
|
+
this.inp.error = null;
|
|
172
|
+
this.inp.value = null;
|
|
173
|
+
if (this.cSearch !== e.target.value) {
|
|
174
|
+
this.cSearch = e.target.value;
|
|
175
|
+
if (this.inp.search !== '' && this.inp.search !== null){
|
|
176
|
+
const v = moment(this.inp.search, 'jYYYY/jMM/jDD');
|
|
177
|
+
if (v.isValid() && this.inp.search.length <= 10){
|
|
178
|
+
this.active = v;
|
|
179
|
+
this.inp.value = this.active.format('jYYYY/jMM/jDD');
|
|
180
|
+
this.setDate();
|
|
181
|
+
if (this.inp.onChange){
|
|
182
|
+
this.inp.onChange(this.inp);
|
|
183
|
+
}
|
|
184
|
+
}else{
|
|
185
|
+
this.setDate();
|
|
186
|
+
}
|
|
187
|
+
} else {
|
|
188
|
+
this.setDate();
|
|
189
|
+
if (this.inp.onChange){
|
|
190
|
+
this.inp.onChange(this.inp);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
onFocusOut(): void{
|
|
196
|
+
$(this.inputDiv.nativeElement).removeClass('top');
|
|
197
|
+
this.inp.search = this.inp.value;
|
|
198
|
+
this.state = 'day';
|
|
199
|
+
}
|
|
200
|
+
setPosition(): void{
|
|
201
|
+
const rect = this.inputDiv.nativeElement.getBoundingClientRect();
|
|
202
|
+
const offsetOfBottom = window.innerHeight - rect.bottom;
|
|
203
|
+
const height = this.inputCalendarDiv.nativeElement.offsetHeight;
|
|
204
|
+
if (offsetOfBottom < height){
|
|
205
|
+
$(this.inputDiv.nativeElement).addClass('top');
|
|
206
|
+
}else{
|
|
207
|
+
$(this.inputDiv.nativeElement).removeClass('top');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
selectDate(d: DayClass): void {
|
|
211
|
+
this.inp.error = null;
|
|
212
|
+
const s = this.days.find(x => x.selected);
|
|
213
|
+
if (s){
|
|
214
|
+
s.selected = false;
|
|
215
|
+
}
|
|
216
|
+
const m = parseInt(this.active.format('jMM'), 10);
|
|
217
|
+
const y = parseInt(this.active.format('jYYYY'), 10);
|
|
218
|
+
this.setValue(y, m, d.day);
|
|
219
|
+
d.selected = true;
|
|
220
|
+
this.cSearch = this.inp.search;
|
|
221
|
+
setTimeout(() => {
|
|
222
|
+
$(this.inputDiv.nativeElement).removeClass('top');
|
|
223
|
+
this.changeIndex.emit('Tab');
|
|
224
|
+
if (!this.inForm){
|
|
225
|
+
$(this.inputBase.nativeElement).blur();
|
|
226
|
+
}
|
|
227
|
+
}, 10);
|
|
228
|
+
if (this.inp.onChange){
|
|
229
|
+
this.inp.onChange(this.inp);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
setValue(y: number, m: number, d: number): void{
|
|
233
|
+
this.inp.value = y + '/' + (m > 9 ? m : '0' + m) + '/' + (d > 9 ? d : '0' + d);
|
|
234
|
+
this.inp.search = y + '/' + (m > 9 ? m : '0' + m) + '/' + (d > 9 ? d : '0' + d);
|
|
235
|
+
}
|
|
236
|
+
changeState(s: string): void{
|
|
237
|
+
this.state = s;
|
|
238
|
+
}
|
|
239
|
+
getYears(): number[]{
|
|
240
|
+
const y = parseInt(this.active.format('jYYYY'), 10);
|
|
241
|
+
const sy = y - (y % 20);
|
|
242
|
+
return Array.from({length: 20}, (x, i) => sy + i);
|
|
243
|
+
}
|
|
244
|
+
getActiveMonth(): string{
|
|
245
|
+
return this.months[parseInt(this.active.format('jM'), 10) - 1];
|
|
246
|
+
}
|
|
247
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
.form-input-con.datetime {
|
|
2
|
+
position: relative;
|
|
3
|
+
float: right;
|
|
4
|
+
width: 100%;
|
|
5
|
+
padding: 0 15px;
|
|
6
|
+
}
|
|
7
|
+
.form-input-con.datetime .form-input {
|
|
8
|
+
position: relative;
|
|
9
|
+
float: right;
|
|
10
|
+
width: 100%;
|
|
11
|
+
}
|
|
12
|
+
.form-input-con.datetime .form-input .label {
|
|
13
|
+
float: right;
|
|
14
|
+
width: 100%;
|
|
15
|
+
height: 20px;
|
|
16
|
+
line-height: 20px;
|
|
17
|
+
padding: 0 10px;
|
|
18
|
+
font-size: 12px;
|
|
19
|
+
margin-bottom: 3px;
|
|
20
|
+
cursor: default;
|
|
21
|
+
-webkit-user-select: none;
|
|
22
|
+
-moz-user-select: none;
|
|
23
|
+
-khtml-user-select: none;
|
|
24
|
+
-ms-user-select: none;
|
|
25
|
+
direction: rtl;
|
|
26
|
+
text-align: right;
|
|
27
|
+
}
|
|
28
|
+
.form-input-con.datetime.error .form-input .label {
|
|
29
|
+
font-size: 10px;
|
|
30
|
+
color: var(--red);
|
|
31
|
+
}
|
|
32
|
+
.form-input-con.datetime .form-input .label .required-icon{
|
|
33
|
+
height: 20px;
|
|
34
|
+
width: 20px;
|
|
35
|
+
line-height: 20px;
|
|
36
|
+
font-size: 9px;
|
|
37
|
+
color: var(--red);
|
|
38
|
+
text-align: center;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.form-input-con.datetime .form-input .control {
|
|
42
|
+
display: block;
|
|
43
|
+
width: 100%;
|
|
44
|
+
height: 35px;
|
|
45
|
+
padding: 5px 35px;
|
|
46
|
+
font-family: Vazir;
|
|
47
|
+
color: var(--black);
|
|
48
|
+
background-image: none;
|
|
49
|
+
border: none;
|
|
50
|
+
border-radius: 5px;
|
|
51
|
+
text-align: center;
|
|
52
|
+
background-color: white;
|
|
53
|
+
position: relative;
|
|
54
|
+
z-index: 2;
|
|
55
|
+
font-size: 11px;
|
|
56
|
+
border: var(--border-input);
|
|
57
|
+
}
|
|
58
|
+
.form-input-con.datetime .form-input .control:focus{
|
|
59
|
+
border-radius: 5px 5px 5px 0;
|
|
60
|
+
}
|
|
61
|
+
.form-input-con.datetime.top .form-input .control:focus{
|
|
62
|
+
border-radius: 0 5px 5px 5px;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.form-input-con.datetime .form-input:hover .control, .form-input-con.datetime .form-input .control:focus {
|
|
66
|
+
border: var(--border-input-dark);
|
|
67
|
+
outline: none;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.form-input-con.datetime .form-input i.icon {
|
|
71
|
+
position: absolute;
|
|
72
|
+
font-size: 13px;
|
|
73
|
+
color: var(--comp);
|
|
74
|
+
cursor: text;
|
|
75
|
+
bottom: 0;
|
|
76
|
+
z-index: 3;
|
|
77
|
+
-webkit-transition: all .35s ease-in-out;
|
|
78
|
+
transition: all .35s ease-in-out;
|
|
79
|
+
width: 35px;
|
|
80
|
+
text-align: center;
|
|
81
|
+
height: 35px;
|
|
82
|
+
line-height: 35px;
|
|
83
|
+
left: 0;
|
|
84
|
+
}
|
|
85
|
+
.form-input-con.datetime .form-input i.clear-icon {
|
|
86
|
+
position: absolute;
|
|
87
|
+
font-size: 14px;
|
|
88
|
+
color: var(--red);
|
|
89
|
+
cursor: pointer;
|
|
90
|
+
bottom: 0;
|
|
91
|
+
z-index: 3;
|
|
92
|
+
-webkit-transition: all .35s ease-in-out;
|
|
93
|
+
transition: all .35s ease-in-out;
|
|
94
|
+
width: 35px;
|
|
95
|
+
text-align: center;
|
|
96
|
+
height: 35px;
|
|
97
|
+
line-height: 38px;
|
|
98
|
+
right: 0;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.form-input-con.datetime.disabled .form-input, .form-input-con.datetime.disabled .form-input i.icon, .form-input-con.datetime.disabled .form-input .label {
|
|
102
|
+
pointer-events: none;
|
|
103
|
+
cursor: default;
|
|
104
|
+
opacity: 0.7;
|
|
105
|
+
filter: blur(0.5px);
|
|
106
|
+
}
|
|
107
|
+
::ng-deep .form-input-con.datetime .form-input .form-input-con.date .form-input .control{
|
|
108
|
+
padding: 5px 15px 5px 35px!important;
|
|
109
|
+
}
|
|
110
|
+
::ng-deep .form-input-con.datetime .form-input .form-input-con.date .form-input .control{
|
|
111
|
+
padding: 5px 15px!important;
|
|
112
|
+
}
|
|
113
|
+
::ng-deep .form-input-con.datetime.disabled .form-input .form-input-con.date .form-input .control,
|
|
114
|
+
::ng-deep .form-input-con.datetime.disabled .form-input .form-input-con.date .form-input i.icon,
|
|
115
|
+
::ng-deep .form-input-con.datetime.disabled .form-input .form-input-con.date .form-input .label {
|
|
116
|
+
pointer-events: none;
|
|
117
|
+
cursor: default;
|
|
118
|
+
opacity: 0.7;
|
|
119
|
+
filter: blur(0.5px);
|
|
120
|
+
}
|
|
121
|
+
::ng-deep .form-input-con.datetime.disabled .form-input .form-input-con.time .form-input .control,
|
|
122
|
+
::ng-deep .form-input-con.datetime.disabled .form-input .form-input-con.time .form-input i.icon,
|
|
123
|
+
::ng-deep .form-input-con.datetime.disabled .form-input .form-input-con.time .form-input .label {
|
|
124
|
+
pointer-events: none;
|
|
125
|
+
cursor: default;
|
|
126
|
+
opacity: 0.7;
|
|
127
|
+
filter: blur(0.5px);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.form-input-con.datetime.error .form-input .control, .form-input-con.datetime.error .form-input i.icon {
|
|
131
|
+
color: var(--red-cc);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.form-input-con.datetime.error .form-input .control {
|
|
135
|
+
border: var(--border-input-red);
|
|
136
|
+
}
|
|
137
|
+
.form-input-con.datetime.error .form-input:hover .control, .form-input-con.datetime.error .form-input .control:focus {
|
|
138
|
+
border: var(--border-input-red-dark);
|
|
139
|
+
}
|
|
140
|
+
::ng-deep .form-input-con.datetime .form-input .form-input-con.date {
|
|
141
|
+
float: left;
|
|
142
|
+
width: 60%;
|
|
143
|
+
padding: 0;
|
|
144
|
+
}
|
|
145
|
+
::ng-deep .form-input-con.datetime .form-input .form-input-con.time {
|
|
146
|
+
float: right;
|
|
147
|
+
width: 40%;
|
|
148
|
+
padding: 0;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
::ng-deep .form-input-con.datetime .form-input .form-input-con.date .form-input .control{
|
|
152
|
+
border-radius: 5px 0 0 5px !important;
|
|
153
|
+
}
|
|
154
|
+
::ng-deep .form-input-con.datetime .form-input .form-input-con.time .form-input .control {
|
|
155
|
+
border-radius: 0 5px 5px 0 !important;
|
|
156
|
+
border-left: unset !important;
|
|
157
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<div [id]="inp.name + 'Input'" [style]="inp.style" [className]="inp.class + ' form-input-con datetime' + (inp.error == null ? '' : ' error') + (inp.disabled ? ' disabled' : '')">
|
|
2
|
+
<div class="form-input">
|
|
3
|
+
<div *ngIf="inp.displayLabel" (click)="this.date.focus()" class="label"><i *ngIf="inp.required" class="fas fa-star-of-life required-icon"></i>{{inp.getLabel()}}</div>
|
|
4
|
+
<div class="w-100 p-r">
|
|
5
|
+
<i (click)="this.date.focus()" *ngIf="inp.icon != null || inp.loading" #inputIcon [className]="(inp.loading ? 'fa-duotone fa-spin fa-spinner' : inp.icon) + ' icon'"></i>
|
|
6
|
+
<i *ngIf="inp.withClear && (date.value || time.value)" (click)="inp.clear()" class="fa-duotone fa-eraser clear-icon"></i>
|
|
7
|
+
<lib-form-date (changeIndex)="changeFocus('Date', $event)" [inp]="date"></lib-form-date>
|
|
8
|
+
<lib-form-time (changeIndex)="changeFocus('Time', $event)" [inp]="time"></lib-form-time>
|
|
9
|
+
</div>
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
|
|
2
|
+
import * as moment from 'jalali-moment';
|
|
3
|
+
import {InputClass} from '../../../classes/form.class';
|
|
4
|
+
import {InputError, InputType} from '../../../classes/enum.class';
|
|
5
|
+
|
|
6
|
+
@Component({
|
|
7
|
+
selector: 'lib-form-datetime',
|
|
8
|
+
templateUrl: './form.datetime.component.html',
|
|
9
|
+
styleUrls: ['./form.datetime.component.css']
|
|
10
|
+
})
|
|
11
|
+
export class FormDatetimeComponent implements OnInit{
|
|
12
|
+
@Input()
|
|
13
|
+
inp: InputClass;
|
|
14
|
+
@Input()
|
|
15
|
+
inForm: boolean;
|
|
16
|
+
@Output()
|
|
17
|
+
changeIndex = new EventEmitter<string>();
|
|
18
|
+
date: InputClass;
|
|
19
|
+
time: InputClass;
|
|
20
|
+
constructor(){
|
|
21
|
+
}
|
|
22
|
+
ngOnInit(): void{
|
|
23
|
+
this.date = new InputClass(this.inp.environment, this.inp.l, 'Date', null, InputType.Date);
|
|
24
|
+
this.time = new InputClass(this.inp.environment, this.inp.l, 'Time', null, InputType.Time);
|
|
25
|
+
this.date.displayLabel = this.time.displayLabel = false;
|
|
26
|
+
if (this.inp.value){
|
|
27
|
+
this.inp.setValue(this.inp.value, false);
|
|
28
|
+
}
|
|
29
|
+
this.inp.setValue = (v) => {
|
|
30
|
+
if (v === null){
|
|
31
|
+
this.inp.clear();
|
|
32
|
+
return;
|
|
33
|
+
} else if (typeof v === 'string') {
|
|
34
|
+
v = parseInt(v.substring(6, v.length - 2), 10);
|
|
35
|
+
}
|
|
36
|
+
const m = moment(v).locale('fa');
|
|
37
|
+
this.date.setValue(m, false);
|
|
38
|
+
this.time.setValue({Hours: m.hours(), Minutes: m.minutes()}, false);
|
|
39
|
+
};
|
|
40
|
+
this.inp.isValid = () => {
|
|
41
|
+
this.inp.value = this.getValue();
|
|
42
|
+
this.inp.error = null;
|
|
43
|
+
this.date.error = null;
|
|
44
|
+
this.time.error = null;
|
|
45
|
+
if (this.inp.required && !this.inp.value) {
|
|
46
|
+
this.inp.error = InputError.Required;
|
|
47
|
+
this.date.error = InputError.Required;
|
|
48
|
+
this.time.error = InputError.Required;
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (!this.inp.required && !this.inp.value) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
if (!moment(this.inp.value, 'jYYYY/jMM/jDD HH:mm').isValid()) {
|
|
55
|
+
this.inp.error = InputError.Invalid;
|
|
56
|
+
this.date.error = InputError.Invalid;
|
|
57
|
+
this.time.error = InputError.Invalid;
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
};
|
|
62
|
+
this.inp.clear = () => {
|
|
63
|
+
if (this.inp.default){
|
|
64
|
+
this.inp.setValue(this.inp.default, false);
|
|
65
|
+
}else{
|
|
66
|
+
this.date.clear();
|
|
67
|
+
this.time.clear();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
this.inp.data = () => {
|
|
71
|
+
return moment(this.getValue(), 'jYYYY/jMM/jDD HH:mm').locale('en').format('YYYY/MM/DD HH:mm');
|
|
72
|
+
};
|
|
73
|
+
this.inp.focus = () => {
|
|
74
|
+
this.date.focus();
|
|
75
|
+
};
|
|
76
|
+
this.inp.focusOut = () => {
|
|
77
|
+
this.date.focusOut();
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
changeFocus(p, a): void{
|
|
81
|
+
if (p === 'Date'){
|
|
82
|
+
if (a === 'Tab' || a === 'Enter'){
|
|
83
|
+
this.time.focus();
|
|
84
|
+
} else if (a === 'ShiftTab' || a === 'ShiftEnter'){
|
|
85
|
+
this.changeIndex.emit('ShiftTab');
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
if (a === 'Tab' || a === 'Enter'){
|
|
89
|
+
this.changeIndex.emit('Tab');
|
|
90
|
+
} else if (a === 'ShiftTab' || a === 'ShiftEnter'){
|
|
91
|
+
this.date.focus();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
getValue(): string{
|
|
96
|
+
return !this.date.value || !this.time.value ? null : `${this.date.value} ${this.time.value}`;
|
|
97
|
+
}
|
|
98
|
+
}
|