-
Notifications
You must be signed in to change notification settings - Fork 8
/
SizesField.js
138 lines (123 loc) · 3.92 KB
/
SizesField.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
Ext.define('SizesField', {
extend: 'Ext.form.field.Base',
alias: 'widget.sizesfield',
requires: [
'Rally.ui.Button'
],
fieldSubTpl: '<div id="{id}"></div>',
cls: 'sizes',
config: {
/**
* @cfg {Object}
*
* The size settings value for this field
*/
value: undefined
},
onDestroy: function() {
if (this._sizesContainer) {
this._sizesContainer.destroy();
delete this._sizesContainer;
}
this.callParent(arguments);
},
onRender: function() {
this.callParent(arguments);
this._sizesContainer = Ext.create('Ext.Container', {
renderTo: this.inputEl,
cls: 'sizes-container',
items: this._buildRows()
});
},
/**
* When a form asks for the data this field represents,
* give it the name of this field and the ref of the selected project (or an empty string).
* Used when persisting the value of this field.
* @return {Object}
*/
getSubmitData: function() {
var data = {};
data[this.name] = Ext.JSON.encode(_.map(Ext.ComponentQuery.query('container', this._sizesContainer), function(row) {
var labelTextBox = Ext.ComponentQuery.query('rallytextfield', row)[0],
valueTextBox = Ext.ComponentQuery.query('rallynumberfield', row)[0];
return {
text: labelTextBox.getValue(),
value: valueTextBox.getValue()
};
}));
return data;
},
_buildRows: function() {
return [{
xtype: 'component',
margin: '0 0 5px 0',
html: '<span class="label-header">Name</span><span class="plan-est-header">Plan Est</span>'
}].concat(_.map(Ext.JSON.decode(this._value), function(value) {
return this._buildRow(value);
}, this));
},
_buildRow: function(value) {
return {
xtype: 'container',
layout: 'hbox',
items: [
{
xtype: 'rallybutton',
border: false,
frame: false,
cls: 'row-btn plus',
disabled: false,
itemId: 'plusButton',
iconCls: 'icon-plus',
listeners: {
click: this._addRow,
scope: this
}
},
{
xtype: 'rallybutton',
border: false,
cls: 'row-btn minus',
frame: false,
iconCls: 'icon-minus',
itemId: 'minusButton',
listeners: {
click: this._removeRow,
scope: this
}
},
{
xtype: 'rallytextfield',
width: 100,
value: value && value.text
},
{
xtype: 'rallynumberfield',
width: 50,
margin: '0 0 0 10px',
value: value && value.value
}
]
};
},
_addRow: function(button) {
var container = button.up();
var sizesContainer = container.up();
var index = sizesContainer.items.indexOf(container);
sizesContainer.insert(index + 1, this._buildRow());
this._adjustSize();
},
_removeRow: function(button) {
button.up().destroy();
this._adjustSize();
},
_adjustSize: function() {
//little hack- force app settings resize
var appSettings = this.up('rallyappsettings');
appSettings.fireEvent('appsettingsready', appSettings);
},
setValue: function(value) {
this.callParent(arguments);
this._value = value;
}
});