-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdesigner.js
executable file
·184 lines (154 loc) · 5.63 KB
/
designer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
(function(wListView) {
/*jshint multistr: true, devel: true*/
"use strict";
var studioTemplate = WAF.require('wListView/studio-template'),
options = [];
// Keep WAK8 compatibility
wListView._studioOn = wListView._studioOn || wListView.on;
wListView._addAttribute = wListView._addAttribute || wListView.addAttribute;
wListView._studioOn('Create', function(tag) {
var templateNum = tag.getAttribute('data-template').getValue(),
existingBinding = tag.getAttribute('data-variables-binding').getValue(),
optionsToUpdate = tag.getAttributeOptions('data-variables-binding', 1),
templateInfo = studioTemplate.parseTemplate(tag.getWidget()._templates.list[templateNum].template, optionsToUpdate, tag.getWidget()._templates.defaultData),
todo = false,
bindingHistory = {}; // we'll hold binding history there
if (existingBinding.length) {
bindingHistory[templateNum] = existingBinding;
bindingHistory.previousTemplate = templateNum;
}
tag.getWidget()._bindingHistory = bindingHistory;
// fullsize
setTimeout(function() {
tag.fitToParent(true);
}, 0);
// populate options with the list of templates
if (!options.length) {
tag.getWidget()._templates.list.forEach(function(template, i) {
options.push({
key: i.toString(),
value: template.description
});
});
}
// we only need to parse the template on the first creation of the widget (or when the template is changed, but this is done elsewhere)
try{
existingBinding = JSON.parse(existingBinding);
if (existingBinding.length === 0) {
todo = true;
}
} catch(e) {
todo = true;
}
studioTemplate.updateAttributesList(tag, tag.getAttribute('data-collection').getValue());
// set default binding
if (todo === true) {
studioTemplate.setVariablesBinding(tag, templateInfo.variables);
}
// set html with some default data
studioTemplate.setDesignerHtml(tag, templateInfo.defaultText);
});
// remove default data from the final html file
wListView._studioOn('Save', function() {
var node = this && this.getElementNode() || null;
if (node && node._json.childNodes) {
node._json.childNodes.length = 0;
}
});
// add Template list
//
wListView._addAttribute({
name: 'data-template',
type: 'dropdown',
options: options,
defaultValue: '0',
/**** This will be simplified in the next version ****/
onchange: function(e) {
var tag = this.data.tag,
bindingHistory = tag.getWidget()._bindingHistory,
oldId = bindingHistory.previousTemplate,
selectedId = this.data.value;
// get previous value ?
// save previous binding
bindingHistory[oldId] = tag.getAttribute('data-variables-binding').getValue();
studioTemplate.setVariablesBinding(tag, tag.getAttributeOptions('data-variables-binding', 1), bindingHistory[selectedId] || undefined);
bindingHistory.previousTemplate = selectedId;
}
});
wListView._addAttribute({
name: 'data-variables-binding',
description: 'Template Variables',
type: 'grid',
defaultValue: '[]',
reloadOnChange: true,
columns: [
{
title: 'Variable Name',
name: 'variable',
type: 'textfield',
disabled: true
},
{
title: 'Attribute',
name: 'attribute',
type: 'dropdown',
options: [""]
}
],
canDeleteRow: function() {
return false;
},
afterReady: function() {
// TODO: parse template
$('#waform-form-gridmanager-template-variables .actions button').hide();
}
});
wListView._addAttribute('data-collection', {
typeValue: 'datasource',
type: 'datasource',
onchange: function() {
studioTemplate.DSChanged(this.data.tag, this.getValue());
}
});
// since the onchange event is only sent on form change, we have to listen on DSDrop too
wListView._studioOn('DSDrop', function(data) {
var collectionName = data.source.getName(),
tag = this._tag;
studioTemplate.DSChanged(tag, collectionName);
});
// events
wListView.addEvent({
'name': 'rowHold',
'description': 'Sent upon tap hold on a row'
});
wListView.addEvent({
'name': 'rowSwapLeft',
'description': 'Sent upon left swipe on a row'
});
wListView.addEvent({
'name': 'rowSwapRight',
'description': 'Sent upon right swipe on a row'
});
wListView.addEvent({
'name': 'listUpdate',
'description': 'Sent upon collection change'
});
/* Hide not needed options from the user */
wListView.customizeProperty('start', {
sourceDisplay: false
});
wListView.customizeProperty('currentPage', {
sourceDisplay: false,
display: false
});
wListView.customizeProperty('pageSize', {
sourceDisplay: false
});
wListView.customizeProperty('navigationMode', {
sourceDisplay: false,
display: false
});
wListView.customizeProperty('start', {
display: false
});
});