-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstudio-template.js
88 lines (68 loc) · 3.11 KB
/
studio-template.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
/* This file contains helper methods that won't be needed in future version of WAF */
WAF.define('wListView/studio-template', ['wListView/behavior/template'], function(Template) {
/*global Designer*/
"use strict";
return {
parseTemplate: function(rawTemplate, options, defaultData) {
var attribute = [],
template = new Template(rawTemplate),
variablesList = template.getVariables(),
defaultText = '';
variablesList.sort().forEach(function(varName) {
attribute.push({
variable: varName,
attribute: options[0]
});
});
defaultData.items.forEach(function(item) {
defaultText += template.render(item);
});
defaultText += defaultText;
defaultText += defaultText;
return {
attributes: JSON.stringify(attribute),
defaultText: defaultText,
variables: variablesList
};
},
updateAttributesList: function(tag, collectionName) {
var ds = Designer.env.ds.catalog.getByName(collectionName),
options = tag.getAttributeOptions('data-variables-binding', 1);
if (ds) {
options.length = 0;
ds.getAttributes().forEach(function(attribute) {
// seems like local datasources do not have scope defined
if (attribute.scope === 'public' || !attribute.scope) {
options.push(attribute.name);
}
});
} else {
options.length = 0;
options.push("");
}
},
setDesignerHtml: function(tag, defaultText) {
var append = false;
tag.updateTemplate(defaultText, append);
tag.refresh();
tag.domUpdate();
setTimeout(function() { Designer.tag.refreshPanels(); }, 0);
},
setVariablesBinding: function(tag, options, previousOptions) {
var widget = tag.getWidget(),
templateNum = tag.getAttribute('data-template').getValue(),
templateInfo = this.parseTemplate(widget._templates.list[templateNum].template, options, widget._templates.defaultData);
tag.getAttribute('data-variables-binding').setValue(typeof previousOptions !== 'undefined' ? previousOptions : templateInfo.attributes);
this.setDesignerHtml(tag, templateInfo.defaultText);
// TODO: by default, every attribute is reseted => we have to set each variables to the first attribute found
$('#waform-form-gridmanager-template-variables').show();
},
DSChanged: function(tag, collectionName) {
var optionsToUpdate = tag.getAttributeOptions('data-variables-binding', 1);
// update attribute list
this.updateAttributesList(tag, collectionName);
// update variable binding object
this.setVariablesBinding(tag, optionsToUpdate);
}
};
});