yafowil.widget.array 2.0.0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,282 @@
1
+ var yafowil_array = (function (exports, $) {
2
+ 'use strict';
3
+
4
+ class ArrayBase {
5
+ constructor(wrapper) {
6
+ wrapper.data('yafowil-array', this);
7
+ this.wrapper = wrapper;
8
+ let table = $('> table', wrapper),
9
+ head_actions = $('> thead .array_actions', table),
10
+ add_handle = this.add_first_handle.bind(this);
11
+ this.table = table;
12
+ $('a.array_row_add', head_actions).off().on('click', add_handle);
13
+ this.bind_actions();
14
+ }
15
+ bind_actions() {
16
+ let actions_sel = '> tbody > tr > td.actions .array_actions',
17
+ row_actions = $(actions_sel, this.table),
18
+ add_handle = this.add_handle.bind(this),
19
+ remove_handle = this.remove_handle.bind(this),
20
+ up_handle = this.up_handle.bind(this),
21
+ down_handle = this.down_handle.bind(this);
22
+ this.mark_disabled(row_actions);
23
+ $('a.array_row_add', row_actions).off().on('click', add_handle);
24
+ $('a.array_row_remove', row_actions).off().on('click', remove_handle);
25
+ $('a.array_row_up', row_actions).off().on('click', up_handle);
26
+ $('a.array_row_down', row_actions).off().on('click', down_handle);
27
+ }
28
+ mark_disabled(row_actions) {
29
+ $('a.array_row_up', row_actions)
30
+ .removeClass('array_row_up_disabled')
31
+ .first()
32
+ .addClass('array_row_up_disabled');
33
+ $('a.array_row_down', row_actions)
34
+ .removeClass('array_row_down_disabled')
35
+ .last()
36
+ .addClass('array_row_down_disabled');
37
+ }
38
+ create_row() {
39
+ let css = this.wrapper.attr('class');
40
+ let row = '';
41
+ row += '<tr>';
42
+ row += '<td class="widget">';
43
+ row += '</td>';
44
+ if (css.indexOf('array-static') === -1) {
45
+ row += '<td class="actions">';
46
+ row += '<div class="array_actions">';
47
+ if (css.indexOf('array-add') > -1) {
48
+ row += '<a class="array_row_add" href="#">';
49
+ row += `<span class="${this.icon_add}"> </span>`;
50
+ row += '</a>';
51
+ }
52
+ if (css.indexOf('array-remove') > -1) {
53
+ row += '<a class="array_row_remove" href="#">';
54
+ row += `<span class="${this.icon_remove}"> </span>`;
55
+ row += '</a>';
56
+ }
57
+ if (css.indexOf('array-sort') > -1) {
58
+ row += '<a class="array_row_up" href="#">';
59
+ row += `<span class="${this.icon_up}"> </span>`;
60
+ row += '</a>';
61
+ row += '<a class="array_row_down" href="#">';
62
+ row += `<span class="${this.icon_down}"> </span>`;
63
+ row += '</a>';
64
+ }
65
+ row += '</div>';
66
+ row += '</td>';
67
+ }
68
+ row += '</tr>';
69
+ row = $(row);
70
+ let template = $('> .arraytemplate', this.wrapper).clone();
71
+ $('.widget', row).append(template.children());
72
+ return row;
73
+ }
74
+ get_row(action) {
75
+ return $(action).parent().parent().parent();
76
+ }
77
+ get base_id() {
78
+ let id = this.wrapper.attr('id');
79
+ return id.substring(6, id.length);
80
+ }
81
+ trigger(event, ...args) {
82
+ let event_hooks = this.hooks[event.substring(3, event.length)];
83
+ if (Object.entries(event_hooks).length) {
84
+ console.log(
85
+ 'Array hooks are deprecated. Use ``on_array_event`` instead.'
86
+ );
87
+ for (let hook_name in event_hooks) {
88
+ console.log(` - ${hook_name}`);
89
+ event_hooks[hook_name].apply(null, args);
90
+ }
91
+ }
92
+ args.splice(0, 0, this);
93
+ for (let subscriber of this._array_subscribers[event]) {
94
+ subscriber.apply(null, args);
95
+ }
96
+ }
97
+ reset_indices(context) {
98
+ let index = 0,
99
+ base_id = this.base_id,
100
+ that = this,
101
+ row;
102
+ context.children().each(function() {
103
+ row = $(this);
104
+ that.set_row_index(row, base_id, index);
105
+ that.trigger('on_index', row, index);
106
+ index++;
107
+ });
108
+ this.bind_actions();
109
+ }
110
+ set_row_index(node, base_id, index) {
111
+ let base_name = base_id.replace(/\-/g, '.'),
112
+ set_index = this.set_attr_index.bind(this),
113
+ that = this,
114
+ child;
115
+ node.children().each(function() {
116
+ child = $(this);
117
+ set_index(child, 'id', base_id, index, '-');
118
+ set_index(child, 'for', base_id, index, '-');
119
+ set_index(child, 'name', base_name, index, '.');
120
+ that.set_row_index(child, base_id, index);
121
+ });
122
+ }
123
+ set_attr_index(node, attr, base, index, delim) {
124
+ let value = node.attr(attr);
125
+ if (value && value.indexOf(base) > -1) {
126
+ node.attr(
127
+ attr,
128
+ this.set_value_index(value, base, index, delim)
129
+ );
130
+ }
131
+ }
132
+ set_value_index(value, base, index, delim) {
133
+ let idx_0 = value.indexOf(base) + base.length + 1,
134
+ idx_1 = value.indexOf(delim, idx_0),
135
+ pre = value.substring(0, idx_0),
136
+ post = '';
137
+ if (idx_1 > -1) {
138
+ post = value.substring(idx_1, value.length);
139
+ }
140
+ return pre + index + post;
141
+ }
142
+ init_row(container, row) {
143
+ this.reset_indices(container);
144
+ this.array_widget.initialize(row);
145
+ this.trigger('on_add', row);
146
+ }
147
+ add_first_handle(evt) {
148
+ evt.preventDefault();
149
+ let new_row = this.create_row(),
150
+ container = $('> tbody', this.table);
151
+ this.trigger('on_before_add', new_row, container);
152
+ container.prepend(new_row);
153
+ this.init_row(container, new_row);
154
+ }
155
+ add_handle(evt) {
156
+ evt.preventDefault();
157
+ let row = this.get_row(evt.currentTarget),
158
+ new_row = this.create_row(),
159
+ container = row.parent();
160
+ this.trigger('on_before_add', new_row, container);
161
+ row.after(new_row);
162
+ this.init_row(container, new_row);
163
+ }
164
+ remove_handle(evt) {
165
+ evt.preventDefault();
166
+ let row = this.get_row(evt.currentTarget);
167
+ this.trigger('on_remove', row);
168
+ let container = row.parent();
169
+ row.remove();
170
+ this.reset_indices(container);
171
+ }
172
+ up_handle(evt) {
173
+ evt.preventDefault();
174
+ let row = this.get_row(evt.currentTarget);
175
+ this.trigger('on_before_up', row);
176
+ row.insertBefore(row.prev());
177
+ this.reset_indices(row.parent());
178
+ this.trigger('on_up', row);
179
+ }
180
+ down_handle(evt) {
181
+ evt.preventDefault();
182
+ let row = this.get_row(evt.currentTarget);
183
+ this.trigger('on_before_down', row);
184
+ row.insertAfter(row.next());
185
+ this.reset_indices(row.parent());
186
+ this.trigger('on_down', row);
187
+ }
188
+ }
189
+
190
+ let hooks = {
191
+ before_add: {},
192
+ add: {},
193
+ remove: {},
194
+ before_up: {},
195
+ up: {},
196
+ before_down: {},
197
+ down: {},
198
+ index: {}
199
+ };
200
+ let _array_subscribers = {
201
+ on_before_add: [],
202
+ on_add: [],
203
+ on_remove: [],
204
+ on_before_up: [],
205
+ on_up: [],
206
+ on_before_down: [],
207
+ on_down: [],
208
+ on_index: []
209
+ };
210
+ function on_array_event(event, subscriber) {
211
+ _array_subscribers[event].push(subscriber);
212
+ }
213
+ function inside_template(elem) {
214
+ return elem.parents('.arraytemplate').length > 0;
215
+ }
216
+ class ArrayWidget extends ArrayBase {
217
+ static initialize(context) {
218
+ $('div.array', context).each(function() {
219
+ let wrapper = $(this);
220
+ if (wrapper.attr('id').indexOf('-TEMPLATE') === -1) {
221
+ new ArrayWidget(wrapper);
222
+ }
223
+ });
224
+ }
225
+ constructor(wrapper) {
226
+ super(wrapper);
227
+ this.hooks = hooks;
228
+ this._array_subscribers = _array_subscribers;
229
+ this.array_widget = ArrayWidget;
230
+ this.icon_add = 'bi-plus-circle-fill';
231
+ this.icon_remove = 'bi-dash-circle-fill';
232
+ this.icon_up = 'bi-arrow-up-circle-fill';
233
+ this.icon_down = 'bi-arrow-down-circle-fill';
234
+ }
235
+ up_handle(evt) {
236
+ super.up_handle(evt);
237
+ const row = this.get_row(evt.currentTarget);
238
+ this.highlight(row);
239
+ }
240
+ down_handle(evt) {
241
+ super.down_handle(evt);
242
+ const row = this.get_row(evt.currentTarget);
243
+ this.highlight(row);
244
+ }
245
+ create_row() {
246
+ const row = super.create_row();
247
+ this.highlight(row);
248
+ return row;
249
+ }
250
+ highlight(row) {
251
+ row.addClass('row-moved');
252
+ setTimeout(() => {
253
+ row.removeClass('row-moved');
254
+ }, 1000);
255
+ }
256
+ }
257
+
258
+ $(function() {
259
+ if (window.ts !== undefined) {
260
+ ts.ajax.register(ArrayWidget.initialize, true);
261
+ } else if (window.bdajax !== undefined) {
262
+ bdajax.register(ArrayWidget.initialize, true);
263
+ } else {
264
+ ArrayWidget.initialize();
265
+ }
266
+ });
267
+
268
+ exports.ArrayWidget = ArrayWidget;
269
+ exports.hooks = hooks;
270
+ exports.inside_template = inside_template;
271
+ exports.on_array_event = on_array_event;
272
+
273
+ Object.defineProperty(exports, '__esModule', { value: true });
274
+
275
+
276
+ window.yafowil = window.yafowil || {};
277
+ window.yafowil.array = exports;
278
+
279
+
280
+ return exports;
281
+
282
+ })({}, jQuery);
@@ -0,0 +1 @@
1
+ .arraytemplate{display:none}.array.is-valid{border-color:var(--bs-form-valid-border-color)}.array.is-invalid{border-color:var(--bs-form-invalid-border-color)}.array table{margin-bottom:0}.array table td.widget{padding:6px 0 10px 10px}.array table td.widget .form-group{margin:0}.array table tr:last-of-type>td{border:0}.array table th{background:none;vertical-align:middle}.array table td{background:none}.array table thead{background-color:rgba(0,128,255,.102);height:30px}.array table thead tr th{border:0;padding-left:10px}.array table td.actions,.array table th.head_actions{width:5.5em}.array table .field~.field{margin-top:10px}.array .array_actions{display:inline-block;width:5.5em}.array .array_actions>a{background:none;float:right;margin-left:2px}.array .array_actions>a.array_row_down_disabled,.array .array_actions>a.array_row_up_disabled{filter:alpha(opacity=40);opacity:.4}.array .array_actions span{color:var(--yafowil-accent-color,#0d6efd)}@keyframes boxShadowAnimation{30%{background:rgba(0,128,255,.102)}}.row-moved{animation:boxShadowAnimation 1s}
@@ -0,0 +1 @@
1
+ var yafowil_array=function(e,r){"use strict";class t{constructor(e){e.data("yafowil-array",this),this.wrapper=e;let t=r("> table",e),i=r("> thead .array_actions",t),a=this.add_first_handle.bind(this);this.table=t,r("a.array_row_add",i).off().on("click",a),this.bind_actions()}bind_actions(){let e=r("> tbody > tr > td.actions .array_actions",this.table),t=this.add_handle.bind(this),i=this.remove_handle.bind(this),a=this.up_handle.bind(this),s=this.down_handle.bind(this);this.mark_disabled(e),r("a.array_row_add",e).off().on("click",t),r("a.array_row_remove",e).off().on("click",i),r("a.array_row_up",e).off().on("click",a),r("a.array_row_down",e).off().on("click",s)}mark_disabled(e){r("a.array_row_up",e).removeClass("array_row_up_disabled").first().addClass("array_row_up_disabled"),r("a.array_row_down",e).removeClass("array_row_down_disabled").last().addClass("array_row_down_disabled")}create_row(){let e=this.wrapper.attr("class"),t="";t+="<tr>",t+='<td class="widget">',t+="</td>",-1===e.indexOf("array-static")&&(t+='<td class="actions">',t+='<div class="array_actions">',e.indexOf("array-add")>-1&&(t+='<a class="array_row_add" href="#">',t+=`<span class="${this.icon_add}"> </span>`,t+="</a>"),e.indexOf("array-remove")>-1&&(t+='<a class="array_row_remove" href="#">',t+=`<span class="${this.icon_remove}"> </span>`,t+="</a>"),e.indexOf("array-sort")>-1&&(t+='<a class="array_row_up" href="#">',t+=`<span class="${this.icon_up}"> </span>`,t+="</a>",t+='<a class="array_row_down" href="#">',t+=`<span class="${this.icon_down}"> </span>`,t+="</a>"),t+="</div>",t+="</td>"),t+="</tr>",t=r(t);let i=r("> .arraytemplate",this.wrapper).clone();return r(".widget",t).append(i.children()),t}get_row(e){return r(e).parent().parent().parent()}get base_id(){let e=this.wrapper.attr("id");return e.substring(6,e.length)}trigger(e,...r){let t=this.hooks[e.substring(3,e.length)];if(Object.entries(t).length){console.log("Array hooks are deprecated. Use ``on_array_event`` instead.");for(let e in t)console.log(` - ${e}`),t[e].apply(null,r)}r.splice(0,0,this);for(let t of this._array_subscribers[e])t.apply(null,r)}reset_indices(e){let t,i=0,a=this.base_id,s=this;e.children().each(function(){t=r(this),s.set_row_index(t,a,i),s.trigger("on_index",t,i),i++}),this.bind_actions()}set_row_index(e,t,i){let a,s=t.replace(/\-/g,"."),n=this.set_attr_index.bind(this),o=this;e.children().each(function(){a=r(this),n(a,"id",t,i,"-"),n(a,"for",t,i,"-"),n(a,"name",s,i,"."),o.set_row_index(a,t,i)})}set_attr_index(e,r,t,i,a){let s=e.attr(r);s&&s.indexOf(t)>-1&&e.attr(r,this.set_value_index(s,t,i,a))}set_value_index(e,r,t,i){let a=e.indexOf(r)+r.length+1,s=e.indexOf(i,a),n=e.substring(0,a),o="";return s>-1&&(o=e.substring(s,e.length)),n+t+o}init_row(e,r){this.reset_indices(e),this.array_widget.initialize(r),this.trigger("on_add",r)}add_first_handle(e){e.preventDefault();let t=this.create_row(),i=r("> tbody",this.table);this.trigger("on_before_add",t,i),i.prepend(t),this.init_row(i,t)}add_handle(e){e.preventDefault();let r=this.get_row(e.currentTarget),t=this.create_row(),i=r.parent();this.trigger("on_before_add",t,i),r.after(t),this.init_row(i,t)}remove_handle(e){e.preventDefault();let r=this.get_row(e.currentTarget);this.trigger("on_remove",r);let t=r.parent();r.remove(),this.reset_indices(t)}up_handle(e){e.preventDefault();let r=this.get_row(e.currentTarget);this.trigger("on_before_up",r),r.insertBefore(r.prev()),this.reset_indices(r.parent()),this.trigger("on_up",r)}down_handle(e){e.preventDefault();let r=this.get_row(e.currentTarget);this.trigger("on_before_down",r),r.insertAfter(r.next()),this.reset_indices(r.parent()),this.trigger("on_down",r)}}let i={before_add:{},add:{},remove:{},before_up:{},up:{},before_down:{},down:{},index:{}},a={on_before_add:[],on_add:[],on_remove:[],on_before_up:[],on_up:[],on_before_down:[],on_down:[],on_index:[]};class s extends t{static initialize(e){r("div.array",e).each(function(){let e=r(this);-1===e.attr("id").indexOf("-TEMPLATE")&&new s(e)})}constructor(e){super(e),this.hooks=i,this._array_subscribers=a,this.array_widget=s,this.icon_add="bi-plus-circle-fill",this.icon_remove="bi-dash-circle-fill",this.icon_up="bi-arrow-up-circle-fill",this.icon_down="bi-arrow-down-circle-fill"}up_handle(e){super.up_handle(e);const r=this.get_row(e.currentTarget);this.highlight(r)}down_handle(e){super.down_handle(e);const r=this.get_row(e.currentTarget);this.highlight(r)}create_row(){const e=super.create_row();return this.highlight(e),e}highlight(e){e.addClass("row-moved"),setTimeout(()=>{e.removeClass("row-moved")},1e3)}}return r(function(){void 0!==window.ts?ts.ajax.register(s.initialize,!0):void 0!==window.bdajax?bdajax.register(s.initialize,!0):s.initialize()}),e.ArrayWidget=s,e.hooks=i,e.inside_template=function(e){return e.parents(".arraytemplate").length>0},e.on_array_event=function(e,r){a[e].push(r)},Object.defineProperty(e,"__esModule",{value:!0}),window.yafowil=window.yafowil||{},window.yafowil.array=e,e}({},jQuery);
@@ -0,0 +1,261 @@
1
+ var yafowil_array = (function (exports, $) {
2
+ 'use strict';
3
+
4
+ class ArrayBase {
5
+ constructor(wrapper) {
6
+ wrapper.data('yafowil-array', this);
7
+ this.wrapper = wrapper;
8
+ let table = $('> table', wrapper),
9
+ head_actions = $('> thead .array_actions', table),
10
+ add_handle = this.add_first_handle.bind(this);
11
+ this.table = table;
12
+ $('a.array_row_add', head_actions).off().on('click', add_handle);
13
+ this.bind_actions();
14
+ }
15
+ bind_actions() {
16
+ let actions_sel = '> tbody > tr > td.actions .array_actions',
17
+ row_actions = $(actions_sel, this.table),
18
+ add_handle = this.add_handle.bind(this),
19
+ remove_handle = this.remove_handle.bind(this),
20
+ up_handle = this.up_handle.bind(this),
21
+ down_handle = this.down_handle.bind(this);
22
+ this.mark_disabled(row_actions);
23
+ $('a.array_row_add', row_actions).off().on('click', add_handle);
24
+ $('a.array_row_remove', row_actions).off().on('click', remove_handle);
25
+ $('a.array_row_up', row_actions).off().on('click', up_handle);
26
+ $('a.array_row_down', row_actions).off().on('click', down_handle);
27
+ }
28
+ mark_disabled(row_actions) {
29
+ $('a.array_row_up', row_actions)
30
+ .removeClass('array_row_up_disabled')
31
+ .first()
32
+ .addClass('array_row_up_disabled');
33
+ $('a.array_row_down', row_actions)
34
+ .removeClass('array_row_down_disabled')
35
+ .last()
36
+ .addClass('array_row_down_disabled');
37
+ }
38
+ create_row() {
39
+ let css = this.wrapper.attr('class');
40
+ let row = '';
41
+ row += '<tr>';
42
+ row += '<td class="widget">';
43
+ row += '</td>';
44
+ if (css.indexOf('array-static') === -1) {
45
+ row += '<td class="actions">';
46
+ row += '<div class="array_actions">';
47
+ if (css.indexOf('array-add') > -1) {
48
+ row += '<a class="array_row_add" href="#">';
49
+ row += `<span class="${this.icon_add}"> </span>`;
50
+ row += '</a>';
51
+ }
52
+ if (css.indexOf('array-remove') > -1) {
53
+ row += '<a class="array_row_remove" href="#">';
54
+ row += `<span class="${this.icon_remove}"> </span>`;
55
+ row += '</a>';
56
+ }
57
+ if (css.indexOf('array-sort') > -1) {
58
+ row += '<a class="array_row_up" href="#">';
59
+ row += `<span class="${this.icon_up}"> </span>`;
60
+ row += '</a>';
61
+ row += '<a class="array_row_down" href="#">';
62
+ row += `<span class="${this.icon_down}"> </span>`;
63
+ row += '</a>';
64
+ }
65
+ row += '</div>';
66
+ row += '</td>';
67
+ }
68
+ row += '</tr>';
69
+ row = $(row);
70
+ let template = $('> .arraytemplate', this.wrapper).clone();
71
+ $('.widget', row).append(template.children());
72
+ return row;
73
+ }
74
+ get_row(action) {
75
+ return $(action).parent().parent().parent();
76
+ }
77
+ get base_id() {
78
+ let id = this.wrapper.attr('id');
79
+ return id.substring(6, id.length);
80
+ }
81
+ trigger(event, ...args) {
82
+ let event_hooks = this.hooks[event.substring(3, event.length)];
83
+ if (Object.entries(event_hooks).length) {
84
+ console.log(
85
+ 'Array hooks are deprecated. Use ``on_array_event`` instead.'
86
+ );
87
+ for (let hook_name in event_hooks) {
88
+ console.log(` - ${hook_name}`);
89
+ event_hooks[hook_name].apply(null, args);
90
+ }
91
+ }
92
+ args.splice(0, 0, this);
93
+ for (let subscriber of this._array_subscribers[event]) {
94
+ subscriber.apply(null, args);
95
+ }
96
+ }
97
+ reset_indices(context) {
98
+ let index = 0,
99
+ base_id = this.base_id,
100
+ that = this,
101
+ row;
102
+ context.children().each(function() {
103
+ row = $(this);
104
+ that.set_row_index(row, base_id, index);
105
+ that.trigger('on_index', row, index);
106
+ index++;
107
+ });
108
+ this.bind_actions();
109
+ }
110
+ set_row_index(node, base_id, index) {
111
+ let base_name = base_id.replace(/\-/g, '.'),
112
+ set_index = this.set_attr_index.bind(this),
113
+ that = this,
114
+ child;
115
+ node.children().each(function() {
116
+ child = $(this);
117
+ set_index(child, 'id', base_id, index, '-');
118
+ set_index(child, 'for', base_id, index, '-');
119
+ set_index(child, 'name', base_name, index, '.');
120
+ that.set_row_index(child, base_id, index);
121
+ });
122
+ }
123
+ set_attr_index(node, attr, base, index, delim) {
124
+ let value = node.attr(attr);
125
+ if (value && value.indexOf(base) > -1) {
126
+ node.attr(
127
+ attr,
128
+ this.set_value_index(value, base, index, delim)
129
+ );
130
+ }
131
+ }
132
+ set_value_index(value, base, index, delim) {
133
+ let idx_0 = value.indexOf(base) + base.length + 1,
134
+ idx_1 = value.indexOf(delim, idx_0),
135
+ pre = value.substring(0, idx_0),
136
+ post = '';
137
+ if (idx_1 > -1) {
138
+ post = value.substring(idx_1, value.length);
139
+ }
140
+ return pre + index + post;
141
+ }
142
+ init_row(container, row) {
143
+ this.reset_indices(container);
144
+ this.array_widget.initialize(row);
145
+ this.trigger('on_add', row);
146
+ }
147
+ add_first_handle(evt) {
148
+ evt.preventDefault();
149
+ let new_row = this.create_row(),
150
+ container = $('> tbody', this.table);
151
+ this.trigger('on_before_add', new_row, container);
152
+ container.prepend(new_row);
153
+ this.init_row(container, new_row);
154
+ }
155
+ add_handle(evt) {
156
+ evt.preventDefault();
157
+ let row = this.get_row(evt.currentTarget),
158
+ new_row = this.create_row(),
159
+ container = row.parent();
160
+ this.trigger('on_before_add', new_row, container);
161
+ row.after(new_row);
162
+ this.init_row(container, new_row);
163
+ }
164
+ remove_handle(evt) {
165
+ evt.preventDefault();
166
+ let row = this.get_row(evt.currentTarget);
167
+ this.trigger('on_remove', row);
168
+ let container = row.parent();
169
+ row.remove();
170
+ this.reset_indices(container);
171
+ }
172
+ up_handle(evt) {
173
+ evt.preventDefault();
174
+ let row = this.get_row(evt.currentTarget);
175
+ this.trigger('on_before_up', row);
176
+ row.insertBefore(row.prev());
177
+ this.reset_indices(row.parent());
178
+ this.trigger('on_up', row);
179
+ }
180
+ down_handle(evt) {
181
+ evt.preventDefault();
182
+ let row = this.get_row(evt.currentTarget);
183
+ this.trigger('on_before_down', row);
184
+ row.insertAfter(row.next());
185
+ this.reset_indices(row.parent());
186
+ this.trigger('on_down', row);
187
+ }
188
+ }
189
+
190
+ let hooks = {
191
+ before_add: {},
192
+ add: {},
193
+ remove: {},
194
+ before_up: {},
195
+ up: {},
196
+ before_down: {},
197
+ down: {},
198
+ index: {}
199
+ };
200
+ let _array_subscribers = {
201
+ on_before_add: [],
202
+ on_add: [],
203
+ on_remove: [],
204
+ on_before_up: [],
205
+ on_up: [],
206
+ on_before_down: [],
207
+ on_down: [],
208
+ on_index: []
209
+ };
210
+ function on_array_event(event, subscriber) {
211
+ _array_subscribers[event].push(subscriber);
212
+ }
213
+ function inside_template(elem) {
214
+ return elem.parents('.arraytemplate').length > 0;
215
+ }
216
+ class ArrayWidget extends ArrayBase {
217
+ static initialize(context) {
218
+ $('div.array', context).each(function() {
219
+ let wrapper = $(this);
220
+ if (wrapper.attr('id').indexOf('-TEMPLATE') === -1) {
221
+ new ArrayWidget(wrapper);
222
+ }
223
+ });
224
+ }
225
+ constructor(wrapper) {
226
+ super(wrapper);
227
+ this.hooks = hooks;
228
+ this._array_subscribers = _array_subscribers;
229
+ this.array_widget = ArrayWidget;
230
+ this.icon_add = 'icon-plus-sign';
231
+ this.icon_remove = 'icon-minus-sign';
232
+ this.icon_up = 'icon-circle-arrow-up';
233
+ this.icon_down = 'icon-circle-arrow-down';
234
+ }
235
+ }
236
+
237
+ $(function() {
238
+ if (window.ts !== undefined) {
239
+ ts.ajax.register(ArrayWidget.initialize, true);
240
+ } else if (window.bdajax !== undefined) {
241
+ bdajax.register(ArrayWidget.initialize, true);
242
+ } else {
243
+ ArrayWidget.initialize();
244
+ }
245
+ });
246
+
247
+ exports.ArrayWidget = ArrayWidget;
248
+ exports.hooks = hooks;
249
+ exports.inside_template = inside_template;
250
+ exports.on_array_event = on_array_event;
251
+
252
+ Object.defineProperty(exports, '__esModule', { value: true });
253
+
254
+
255
+ window.yafowil = window.yafowil || {};
256
+ window.yafowil.array = exports;
257
+
258
+
259
+ return exports;
260
+
261
+ })({}, jQuery);
@@ -0,0 +1 @@
1
+ .arraytemplate{display:none}.icon-circle-arrow-down:before,.icon-circle-arrow-up:before,.icon-minus-sign:before,.icon-plus-sign:before{content:" "}.array table{border-collapse:collapse;border-left:1px solid #ccc;border-right:1px solid #ccc;border-top:1px solid #ccc;margin-bottom:.5em}.array table th{background-color:#ccc;color:#333}.array table tr{border-bottom:1px solid #ccc}.array table td.actions{vertical-align:top}.errormessage{color:red;font-size:11px;padding-bottom:2px}.array_actions span{color:var(--yafowil-accent-color,#0d6efd)}.array_actions a{background:none;border:none!important;float:right;font-size:16px;line-height:16px;margin-top:1px;padding-left:16px;text-decoration:none}.array_actions a.array_row_add{background:url(images/icon_add.png) 50% 50% no-repeat}.array_actions a.array_row_remove{background:url(images/icon_remove.png) 50% 50% no-repeat}.array_actions a.array_row_up{background:url(images/icon_up.png) 50% 50% no-repeat}.array_actions a.array_row_up_disabled{background:url(images/icon_up_disabled.png) 50% 50% no-repeat!important}.array_actions a.array_row_down{background:url(images/icon_down.png) 50% 50% no-repeat}.array_actions a.array_row_down_disabled{background:url(images/icon_down_disabled.png) 50% 50% no-repeat!important}
@@ -0,0 +1 @@
1
+ var yafowil_array=function(e,r){"use strict";class t{constructor(e){e.data("yafowil-array",this),this.wrapper=e;let t=r("> table",e),a=r("> thead .array_actions",t),i=this.add_first_handle.bind(this);this.table=t,r("a.array_row_add",a).off().on("click",i),this.bind_actions()}bind_actions(){let e=r("> tbody > tr > td.actions .array_actions",this.table),t=this.add_handle.bind(this),a=this.remove_handle.bind(this),i=this.up_handle.bind(this),n=this.down_handle.bind(this);this.mark_disabled(e),r("a.array_row_add",e).off().on("click",t),r("a.array_row_remove",e).off().on("click",a),r("a.array_row_up",e).off().on("click",i),r("a.array_row_down",e).off().on("click",n)}mark_disabled(e){r("a.array_row_up",e).removeClass("array_row_up_disabled").first().addClass("array_row_up_disabled"),r("a.array_row_down",e).removeClass("array_row_down_disabled").last().addClass("array_row_down_disabled")}create_row(){let e=this.wrapper.attr("class"),t="";t+="<tr>",t+='<td class="widget">',t+="</td>",-1===e.indexOf("array-static")&&(t+='<td class="actions">',t+='<div class="array_actions">',e.indexOf("array-add")>-1&&(t+='<a class="array_row_add" href="#">',t+=`<span class="${this.icon_add}"> </span>`,t+="</a>"),e.indexOf("array-remove")>-1&&(t+='<a class="array_row_remove" href="#">',t+=`<span class="${this.icon_remove}"> </span>`,t+="</a>"),e.indexOf("array-sort")>-1&&(t+='<a class="array_row_up" href="#">',t+=`<span class="${this.icon_up}"> </span>`,t+="</a>",t+='<a class="array_row_down" href="#">',t+=`<span class="${this.icon_down}"> </span>`,t+="</a>"),t+="</div>",t+="</td>"),t+="</tr>",t=r(t);let a=r("> .arraytemplate",this.wrapper).clone();return r(".widget",t).append(a.children()),t}get_row(e){return r(e).parent().parent().parent()}get base_id(){let e=this.wrapper.attr("id");return e.substring(6,e.length)}trigger(e,...r){let t=this.hooks[e.substring(3,e.length)];if(Object.entries(t).length){console.log("Array hooks are deprecated. Use ``on_array_event`` instead.");for(let e in t)console.log(` - ${e}`),t[e].apply(null,r)}r.splice(0,0,this);for(let t of this._array_subscribers[e])t.apply(null,r)}reset_indices(e){let t,a=0,i=this.base_id,n=this;e.children().each(function(){t=r(this),n.set_row_index(t,i,a),n.trigger("on_index",t,a),a++}),this.bind_actions()}set_row_index(e,t,a){let i,n=t.replace(/\-/g,"."),s=this.set_attr_index.bind(this),o=this;e.children().each(function(){i=r(this),s(i,"id",t,a,"-"),s(i,"for",t,a,"-"),s(i,"name",n,a,"."),o.set_row_index(i,t,a)})}set_attr_index(e,r,t,a,i){let n=e.attr(r);n&&n.indexOf(t)>-1&&e.attr(r,this.set_value_index(n,t,a,i))}set_value_index(e,r,t,a){let i=e.indexOf(r)+r.length+1,n=e.indexOf(a,i),s=e.substring(0,i),o="";return n>-1&&(o=e.substring(n,e.length)),s+t+o}init_row(e,r){this.reset_indices(e),this.array_widget.initialize(r),this.trigger("on_add",r)}add_first_handle(e){e.preventDefault();let t=this.create_row(),a=r("> tbody",this.table);this.trigger("on_before_add",t,a),a.prepend(t),this.init_row(a,t)}add_handle(e){e.preventDefault();let r=this.get_row(e.currentTarget),t=this.create_row(),a=r.parent();this.trigger("on_before_add",t,a),r.after(t),this.init_row(a,t)}remove_handle(e){e.preventDefault();let r=this.get_row(e.currentTarget);this.trigger("on_remove",r);let t=r.parent();r.remove(),this.reset_indices(t)}up_handle(e){e.preventDefault();let r=this.get_row(e.currentTarget);this.trigger("on_before_up",r),r.insertBefore(r.prev()),this.reset_indices(r.parent()),this.trigger("on_up",r)}down_handle(e){e.preventDefault();let r=this.get_row(e.currentTarget);this.trigger("on_before_down",r),r.insertAfter(r.next()),this.reset_indices(r.parent()),this.trigger("on_down",r)}}let a={before_add:{},add:{},remove:{},before_up:{},up:{},before_down:{},down:{},index:{}},i={on_before_add:[],on_add:[],on_remove:[],on_before_up:[],on_up:[],on_before_down:[],on_down:[],on_index:[]};class n extends t{static initialize(e){r("div.array",e).each(function(){let e=r(this);-1===e.attr("id").indexOf("-TEMPLATE")&&new n(e)})}constructor(e){super(e),this.hooks=a,this._array_subscribers=i,this.array_widget=n,this.icon_add="icon-plus-sign",this.icon_remove="icon-minus-sign",this.icon_up="icon-circle-arrow-up",this.icon_down="icon-circle-arrow-down"}}return r(function(){void 0!==window.ts?ts.ajax.register(n.initialize,!0):void 0!==window.bdajax?bdajax.register(n.initialize,!0):n.initialize()}),e.ArrayWidget=n,e.hooks=a,e.inside_template=function(e){return e.parents(".arraytemplate").length>0},e.on_array_event=function(e,r){i[e].push(r)},Object.defineProperty(e,"__esModule",{value:!0}),window.yafowil=window.yafowil||{},window.yafowil.array=e,e}({},jQuery);
@@ -0,0 +1 @@
1
+ .arraytemplate{display:none}.array .icon-circle-arrow-down,.array .icon-circle-arrow-up,.array .icon-minus-sign,.array .icon-plus-sign{speak:none;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;display:inline-block;font-family:yafowil-fontello;font-style:normal;font-variant:normal;font-weight:400;line-height:1em;margin-left:2px;margin-right:2px;position:relative;text-align:center;text-decoration:none;text-transform:none;top:1px;width:1em}.array .icon-plus-sign:before{content:"";font-family:yafowil-fontello}.array .icon-minus-sign:before{content:"";font-family:yafowil-fontello}.array .icon-circle-arrow-up:before{content:"";font-family:yafowil-fontello}.array .icon-circle-arrow-down:before{content:"";font-family:yafowil-fontello}.array .field{margin-bottom:0;padding-top:.5em}.array td.widget{padding:0}.array td.widget .form-group{margin:0}.array th{vertical-align:middle}.array td.actions,.array th.head_actions{width:6.5em}.array table{background:transparent;border:none;margin-bottom:0}.array table td,.array table tr{border:none}.array table th{border:none;border-bottom:2px solid #ddd}.array table table{border-right:1px solid #ddd;margin-top:10px}.array table table th{padding-left:0}.array_actions{display:inline-block;margin-top:.6em;padding-right:.45em;width:6.5em}.array_actions a{float:right}.array_actions a.array_row_down_disabled,.array_actions a.array_row_up_disabled{filter:alpha(opacity=40);opacity:.4}.array_actions span{color:var(--yafowil-accent-color,#0d6efd)}