1 /*jshint indent:2, curly:true, eqeqeq:true, immed:true, latedef:true,
2 newcap:true, noarg:true, regexp:true, undef:true, trailing:true,
3 white:true, strict:false*/
4 /*global enyo:true, XT:true, XV:true, Globalize:true, XM:true */
8 // ..........................................................
13 name: "XV.AccountCharacteristicsWidget",
14 kind: "XV.CharacteristicsWidget",
15 model: "XM.AccountCharacteristic",
19 // ..........................................................
24 name: "XV.ContactCharacteristicsWidget",
25 kind: "XV.CharacteristicsWidget",
26 model: "XM.ContactCharacteristic",
30 // ..........................................................
35 name: "XV.CustomerCharacteristicsWidget",
36 kind: "XV.CharacteristicsWidget",
37 model: "XM.CustomerCharacteristic",
41 // ..........................................................
46 name: "XV.EmployeeCharacteristicsWidget",
47 kind: "XV.CharacteristicsWidget",
48 model: "XM.EmployeeCharacteristic",
52 // ..........................................................
57 name: "XV.IncidentCharacteristicsWidget",
58 kind: "XV.CharacteristicsWidget",
59 model: "XM.IncidentCharacteristic",
63 // ..........................................................
68 name: "XV.ItemCharacteristicsWidget",
69 kind: "XV.CharacteristicsWidget",
70 model: "XM.ItemCharacteristic",
74 // ..........................................................
79 name: "XV.OpportunityCharacteristicsWidget",
80 kind: "XV.CharacteristicsWidget",
81 model: "XM.OpportunityCharacteristic",
82 which: "isOpportunities"
85 // ..........................................................
90 name: "XV.OrderCharacteristicItem",
91 kind: "XV.CharacteristicItem",
93 {kind: "XV.ComboboxWidget", name: "combobox", attr: "value"}
95 disabledChanged: function (oldValue) {
96 this.$.combobox.setDisabled(this.disabled);
99 Look at the characteristic of this model, and look at the characteristics of the item
100 to pass to the combobox not just the value that has been changed but a dropdown
101 collection that represents all of the item's characteristic values possible for this
104 valueChanged: function (inSender, inEvent) {
105 var model = this.getValue(),
106 characteristic = model.getValue("characteristic"),
107 characteristicId = characteristic.id,
108 characteristicName = characteristic.get("name"),
109 line = model.collection[this.parent.parent.parent.getParentKey()],
110 allItemCharacteristics = line.getValue("item.characteristics"),
111 // filter for only the models of the appropriate characteristic
112 // allItemCharacteristics may be "", in which case we want an empty array
113 // we can use this underscore method in backbone but it unfortunately
114 // returns an array of models instead of a collection
115 relevantArray = allItemCharacteristics ? allItemCharacteristics.filter(function (model) {
116 return model.getValue("characteristic.id") === characteristicId;
118 // so we have to make it a collection here
119 relevantItemCharacteristics = new XM.CharacteristicCollection(relevantArray);
121 // pass the backing collection to the combobox
122 this.$.combobox.setCollection(relevantItemCharacteristics);
124 // for this type of characteristic, the label is just a label and not a picker
125 this.$.combobox.setLabel(characteristicName);
127 // set the selected value of the combobox
128 this.$.combobox.setValue(model.get("value"), {silent: true});
133 name: "XV.OrderCharacteristicsWidget",
134 kind: "XV.CharacteristicsWidget",
135 model: "XM.PurchaseOrderLineCharacteristic",
140 {kind: "onyx.GroupboxHeader", content: "_characteristics".loc()},
141 {kind: "Repeater", count: 0, onSetupItem: "setupItem", components: [
142 {kind: "XV.OrderCharacteristicItem", name: "characteristicItem"}
146 Show even though we don't have a this.getWhich()
148 create: function () {
149 this.inherited(arguments);
150 // just undo the super-class function.
153 disabledChanged: function () {
154 // Over-ride: there is no "new" button here.
158 // ..........................................................
163 name: "XV.QuoteLineCharacteristicItem",
164 kind: "XV.CharacteristicItem",
166 {kind: "XV.QuoteLineCharacteristicCombobox", name: "combobox", attr: "value", showLabel: false},
169 disabledChanged: function (oldValue) {
170 this.$.combobox.setDisabled(this.disabled);
173 The price display is bound to the price attribute of the model, although we only want
174 to show it if the quote line's item isSold
176 priceChanged: function () {
177 var model = this.getValue(),
178 line = model.collection.quoteLine ? model.collection.quoteLine : model.collection.salesOrderLine,
179 itemIsSold = line.getValue("item.isSold"),
180 price = model.get("price") !== undefined ? model.get("price") : "",
181 note = itemIsSold ? Globalize.format(price, "c") : "";
183 this.$.combobox.setNote(note);
188 destroy: function () {
189 this.getValue().off("change:price", this.priceChanged, this);
190 this.inherited(arguments);
193 Look at the characteristic of this model, and look at the characteristics of the item
194 to pass to the combobox not just the value that has been changed but a dropdown
195 collection that represents all of the item's characteristic values possible for this
198 valueChanged: function (inSender, inEvent) {
199 var model = this.getValue(),
200 characteristic = model.getValue('characteristic'),
201 characteristicId = characteristic.id,
202 characteristicName = characteristic.get('name'),
203 // this could be quoteLine or a salesOrderLine
204 line = model.collection.quoteLine ? model.collection.quoteLine : model.collection.salesOrderLine,
205 allItemCharacteristics = line.getValue("item.characteristics"),
206 // filter for only the models of the appropriate characteristic
207 // allItemCharacteristics may be "", in which case we want an empty array
208 // we can use this underscore method in backbone but it unfortunately
209 // returns an array of models instead of a collection
210 relevantArray = allItemCharacteristics ? allItemCharacteristics.filter(function (model) {
211 return model.getValue("characteristic.id") === characteristicId;
213 // so we have to make it a collection here
214 relevantItemCharacteristics = new XM.CharacteristicCollection(relevantArray),
215 itemIsSold = line.getValue("item.isSold");
217 // pass the backing collection to the combobox
218 this.$.combobox.setCollection(relevantItemCharacteristics);
220 // for this type of characteristic, the label is just a label and not a picker
221 this.$.combobox.setLabel(characteristicName);
223 // set the selected value of the combobox
224 this.$.combobox.setValue(model.get('value'), {silent: true});
226 // display the price if we already have it
229 // bind the price label to the price attribute on the model
230 this.getValue().on("change:price", this.priceChanged, this);
235 name: "XV.QuoteLineCharacteristicsWidget",
236 kind: "XV.CharacteristicsWidget",
237 model: "XM.QuoteLineCharacteristic",
239 {kind: "onyx.GroupboxHeader", content: "_characteristics".loc()},
240 {kind: "Repeater", count: 0, onSetupItem: "setupItem", components: [
241 {kind: "XV.QuoteLineCharacteristicItem", name: "characteristicItem"}
245 Show even though we don't have a this.getWhich()
247 create: function () {
248 this.inherited(arguments);
249 // just undo the super-class function.
252 disabledChanged: function () {
253 // Over-ride: there is no "new" button here.
255 setValue: function (value) {
256 this.inherited(arguments);
258 // TODO: hide it if there are no characteristics to show
259 // this doesn't quite work yet
261 // && value.quoteLine
262 // && value.quoteLine.getValue("itemSite.item.characteristics")
263 // && value.quoteLine.getValue("itemSite.item.characteristics").length) {
271 // ..........................................................
276 name: "XV.SaleTypeCharacteristicsWidget",
277 kind: "XV.CharacteristicsWidget",
278 model: "XM.SaleTypeCharacteristic",
279 which: "isSalesOrders" // not a bug
282 // ..........................................................
287 name: "XV.SalesOrderCharacteristicsWidget",
288 kind: "XV.CharacteristicsWidget",
289 model: "XM.SalesOrderCharacteristic",
290 which: "isSalesOrders"