LP1823041 Angular dialogs return observables
[Evergreen.git] / Open-ILS / src / eg2 / src / app / share / fm-editor / fm-editor.component.html
1 <!-- idlObject and fieldName applied programmatically -->
2 <eg-translate #translator></eg-translate>
3
4 <ng-template #dialogContent>
5   <div class="modal-header bg-info">
6     <h4 class="modal-title" i18n>Record Editor: {{recordLabel}}</h4>
7     <button type="button" class="close" 
8       i18n-aria-label aria-label="Close" (click)="close()">
9       <span aria-hidden="true">&times;</span>
10     </button>
11   </div>
12   <div class="modal-body">
13     <form #fmEditForm="ngForm" role="form" class="form-validated common-form striped-odd">
14       <ng-container *ngIf="!record">
15         <!-- display a progress dialog while the editor 
16             fetches the needed data -->
17         <eg-progress-inline></eg-progress-inline> 
18       </ng-container>
19       <ng-container *ngIf="record">
20       <div class="form-group row" *ngFor="let field of fields">
21         <div class="col-lg-3">
22           <label for="{{idPrefix}}-{{field.name}}">{{field.label}}</label>
23         </div>
24         <div class="col-lg-7">
25
26           <ng-container [ngSwitch]="inputType(field)">
27
28             <ng-container *ngSwitchCase="'template'">
29               <ng-container
30                 *ngTemplateOutlet="field.template; context:customTemplateFieldContext(field)">
31               </ng-container> 
32             </ng-container> 
33
34             <ng-container *ngSwitchCase="'readonly'">
35               <span>{{record[field.name]()}}</span>
36             </ng-container>
37
38             <ng-container *ngSwitchCase="'readonly-money'">
39               <span>{{record[field.name]() | currency}}</span>
40             </ng-container>
41
42             <ng-container *ngSwitchCase="'readonly-list'">
43               <ng-container *ngIf="field.linkedValues">
44                 <span>{{field.linkedValues[0].label}}</span>
45               </ng-container>
46             </ng-container>
47
48             <ng-container *ngSwitchCase="'timestamp'">
49               <eg-date-select
50                 domId="{{idPrefix}}-{{field.name}}"
51                 (onChangeAsIso)="record[field.name]($event)"
52                 initialIso="{{record[field.name]()}}">
53               </eg-date-select>
54             </ng-container>
55
56             <ng-container *ngSwitchCase="'org_unit'">
57               <eg-org-select
58                 placeholder="{{field.label}}..."
59                 i18n-placeholder
60                 domId="{{idPrefix}}-{{field.name}}"
61                 [limitPerms]="modePerms[mode]"
62                 [readOnly]="field.readOnly"
63                 [applyDefault]="field.orgDefaultAllowed"
64                 [initialOrgId]="record[field.name]()"
65                 (onChange)="record[field.name]($event)">
66               </eg-org-select>
67             </ng-container>
68           
69             <ng-container *ngSwitchCase="'money'">
70               <input
71                 class="form-control"
72                 type="number" step="0.1"
73                 name="{{field.name}}"
74                 id="{{idPrefix}}-{{field.name}}"
75                 placeholder="{{field.label}}..."
76                 i18n-placeholder
77                 [readonly]="field.readOnly"
78                 [required]="field.isRequired()"
79                 [ngModel]="record[field.name]()"
80                 (ngModelChange)="record[field.name]($event)"/>
81             </ng-container>
82
83             <ng-container *ngSwitchCase="'int'">
84               <input
85                 class="form-control"
86                 type="number"
87                 name="{{field.name}}"
88                 id="{{idPrefix}}-{{field.name}}"
89                 placeholder="{{field.label}}..."
90                 i18n-placeholder
91                 [required]="field.isRequired()"
92                 [ngModel]="record[field.name]()"
93                 (ngModelChange)="record[field.name]($event)"/>
94             </ng-container>
95
96             <ng-container *ngSwitchCase="'float'">
97               <input
98                 class="form-control"
99                 type="number" step="0.1"
100                 name="{{field.name}}"
101                 id="{{idPrefix}}-{{field.name}}"
102                 placeholder="{{field.label}}..."
103                 i18n-placeholder
104                 [required]="field.isRequired()"
105                 [ngModel]="record[field.name]()"
106                 (ngModelChange)="record[field.name]($event)"/>
107             </ng-container>
108
109             <ng-container *ngSwitchCase="'text'">
110               <input
111                 class="form-control"
112                 id="{{idPrefix}}-{{field.name}}" name="{{field.name}}"
113                 type="text"
114                 placeholder="{{field.label}}..." i18n-placeholder
115                 [required]="field.isRequired()"
116                 [ngModel]="record[field.name]()"
117                 (ngModelChange)="record[field.name]($event)"/>
118             </ng-container>
119
120             <ng-container *ngSwitchCase="'bool'">
121               <input
122                 class="form-check-input"
123                 type="checkbox"
124                 name="{{field.name}}"
125                 id="{{idPrefix}}-{{field.name}}"
126                 [disabled]="field.readOnly"
127                 [ngModel]="record[field.name]()"
128                 (ngModelChange)="record[field.name]($event)"/>
129             </ng-container>
130   
131             <ng-container *ngSwitchCase="'list'">
132               <eg-combobox
133                 id="{{idPrefix}}-{{field.name}}" name="{{field.name}}"
134                 placeholder="{{field.label}}..." i18n-placeholder 
135                 [required]="field.isRequired()"
136                 [entries]="field.linkedValues"
137                 [asyncDataSource]="field.linkedValuesSource"
138                 [startId]="record[field.name]()"
139                 (onChange)="record[field.name]($event ? $event.id : null)">
140               </eg-combobox>
141             </ng-container>
142           </ng-container> <!-- switch -->
143         </div>
144         <div class="col-lg-1" *ngIf="field.i18n && !field.readOnly">
145           <a (click)="openTranslator(field.name)"
146             i18n-title title="Translate">
147             <button class="btn btn-outline-info mat-icon-in-button">
148               <span class="material-icons">translate</span>
149             </button>
150           </a>
151         </div>
152       </div>
153       </ng-container>
154     </form>
155   </div>
156   <div class="modal-footer">
157     <button type="button" class="btn btn-success" *ngIf="mode == 'view'"
158       (click)="close()" i18n>Close</button>
159     <button type="button" class="btn btn-info" 
160       [disabled]="fmEditForm.invalid" *ngIf="mode != 'view'"
161       (click)="save()" i18n>Save</button>
162     <button type="button" class="btn btn-warning ml-2" *ngIf="mode != 'view'"
163       (click)="cancel()" i18n>Cancel</button>
164   </div>
165 </ng-template>