1 /*jshint node:true, indent:2, curly:true, eqeqeq:true, immed:true, latedef:true, newcap:true, noarg:true,
2 regexp:true, undef:true, trailing:true, white:true, strict:false */
3 /*global XT:true, XV:true, XM:true, Backbone:true, window:true, enyo:true, _:true */
7 // ..........................................................
12 name: "XV.AccountWidget",
13 kind: "XV.RelationWidget",
14 collection: "XM.AccountRelationCollection",
15 list: "XV.AccountList"
18 // ..........................................................
23 name: "XV.ContactWidget",
24 kind: "XV.RelationWidget",
25 label: "_contact".loc(),
27 nameAttribute: "jobTitle",
28 descripAttribute: "phone",
29 collection: "XM.ContactRelationCollection",
30 list: "XV.ContactList",
34 descriptionComponents: [
35 {name: "jobTitleRow", controlClasses: "enyo-inline", showing: false, components: [
36 {classes: 'xv-description', name: "name"}
38 {name: "phoneRow", controlClasses: "enyo-inline", showing: false, components: [
39 {classes: "xv-description hyperlink", target: '_blank', name: "description"}
41 {name: "alternateRow", controlClasses: "enyo-inline", showing: false, components: [
42 {classes: "xv-description hyperlink", target: "_blank", name: "alternate"}
44 {name: "faxRow", controlClasses: "enyo-inline", showing: false, components: [
45 {classes: "xv-description hyperlink", target: "_blank", name: "fax"}
47 {name: "emailRow", controlClasses: "enyo-inline", showing: false, components: [
48 {classes: 'xv-description hyperlink', target: "_blank", name: "email"}
50 {name: "webAddressRow", controlClasses: "enyo-inline", showing: false, components: [
51 {classes: 'xv-description hyperlink', target: "_blank", name: "webAddress"}
53 {name: "addressRow", controlClasses: "enyo-inline", showing: false, components: [
54 {classes: "xv-description", name: "address", allowHtml: true}
57 setValue: function (value, options) {
58 this.inherited(arguments);
60 if (value && !value.get) {
61 // the value of the widget is still being fetched asyncronously.
62 // when the value is fetched, this function will be run again,
63 // so for now we can just stop here.
67 // The rows are here because sometimes the values needs labels
68 // to go with the values.
69 var jobTitle = value ? value.get("jobTitle") : "",
70 phone = value ? value.get("phone") : "",
71 alternate = value ? value.get("alternate") : "",
72 fax = value ? value.get("fax") : "",
73 primaryEmail = value ? value.get("primaryEmail") : "",
74 webAddress = value ? value.get("webAddress") : "",
75 address = value ? XM.Address.format(value.get("address")) : "",
76 showAddress = this.getShowAddress();
78 this.$.jobTitleRow.setShowing(!!jobTitle);
79 this.$.name.setContent(jobTitle);
81 this.$.phoneRow.setShowing(!!phone);
82 this.$.description.setContent(phone);
83 this.$.description.setAttribute('href', 'tel://' + phone);
85 this.$.alternateRow.setShowing(!!alternate);
86 this.$.alternate.setContent(alternate);
87 this.$.alternate.setAttribute('href', 'tel://' + alternate);
89 this.$.faxRow.setShowing(!!fax);
90 this.$.fax.setContent(fax);
91 this.$.fax.setAttribute('href', 'tel://' + fax);
93 this.$.emailRow.setShowing(!!primaryEmail);
94 this.$.email.setContent(primaryEmail);
95 this.$.email.setAttribute('href', 'mailto:' + primaryEmail);
97 this.$.webAddressRow.setShowing(!!webAddress);
98 this.$.webAddress.setContent(webAddress);
99 this.$.webAddress.setAttribute('href', '//' + alternate);
101 this.$.addressRow.setShowing(address && showAddress);
102 this.$.address.setContent(address);
104 openWindow: function () {
105 var address = this.value ? this.value.get("webAddress") : null;
106 if (address) { window.open("http://" + address); }
109 callPhone: function () {
110 var phoneNumber = this.value ? this.value.get("phone") : null,
113 win = window.open("tel://" + phoneNumber);
118 sendMail: function () {
119 var email = this.value ? this.value.get("primaryEmail") : null,
122 win = window.open("mailto:" + email);
129 // ..........................................................
134 name: "XV.CustomerWidget",
135 kind: "XV.RelationWidget",
136 collection: "XM.CustomerRelationCollection",
137 list: "XV.CustomerList"
141 name: "XV.BillingCustomerWidget",
142 kind: "XV.RelationWidget",
143 collection: "XM.BillingCustomerCollection",
144 query: { parameters: [{attribute: "isActive", value: true}]},
145 list: "XV.CustomerList"
149 name: "XV.SalesCustomerWidget",
150 kind: "XV.RelationWidget",
151 collection: "XM.SalesCustomerCollection",
152 list: "XV.CustomerList"
155 // ..........................................................
159 name: "XV.CustomerGroupWidget",
160 kind: "XV.RelationWidget",
161 collection: "XM.CustomerGroupCollection",
162 keyAttribute: "name",
163 list: "XV.CustomerGroupList"
166 // ..........................................................
171 name: "XV.CustomerProspectWidget",
172 kind: "XV.RelationWidget",
173 collection: "XM.CustomerProspectRelationCollection",
174 list: "XV.CustomerProspectList",
175 create: function () {
176 var ret = this.inherited(arguments);
177 this.createComponent({
179 name: "customerOrProspectPopup",
184 onShow: "popupShown",
185 onHide: "popupHidden",
187 {content: "_customerOrProspect".loc()},
189 {kind: "onyx.Button", name: "customerButton", content: "_customer".loc(), ontap: "popupTapped",
190 classes: "onyx-blue xv-popup-button"},
191 {kind: "onyx.Button", name: "prospectButton", content: "_prospect".loc(), ontap: "popupTapped",
192 classes: "onyx-blue xv-popup-button"}
195 this.$.newItem.setDisabled(false);
200 this overrides the menuItemSelected function of RelationWidget to
201 account for the different types of models presented by the widget.
203 menuItemSelected: function (inSender, inEvent) {
205 menuItem = inEvent.originator,
206 list = this.getList(),
207 model = this.getValue(),
208 K, status, id, workspace,
211 switch (menuItem.name)
214 callback = function (value) {
215 that.setValue(value);
219 searchText: this.$.input.getValue(),
224 K = model.getClass();
225 status = model.get("status");
226 id = model ? model.id : null;
227 workspace = status === K.PROSPECT_STATUS ? "XV.ProspectWorkspace" : "XV.CustomerWorkspace";
230 workspace: workspace,
236 this.$.customerOrProspectPopup.show();
239 popupTapped: function (inSender, inEvent) {
241 callback = function (model) {
242 if (!model) { return; }
243 var Model = that._collection.model,
247 options.success = function () {
248 that.setValue(value);
250 attrs[Model.prototype.idAttribute] = model.id;
251 value = Model.findOrCreate(attrs);
252 value.fetch(options);
255 this.$.customerOrProspectPopup.hide();
258 workspace: inEvent.originator.name === "customerButton" ?
259 "XV.CustomerWorkspace" : "XV.ProspectWorkspace",
265 // ..........................................................
270 name: "XV.CustomerShiptoWidget",
271 kind: "XV.RelationWidget",
272 collection: "XM.CustomerShiptoRelationCollection",
273 list: "XV.CustomerShiptoList"
276 // ..........................................................
281 name: "XV.DepartmentWidget",
282 kind: "XV.RelationWidget",
283 collection: "XM.DepartmentCollection",
284 list: "XV.DepartmentList"
287 // ..........................................................
292 name: "XV.EmployeeWidget",
293 kind: "XV.RelationWidget",
294 collection: "XM.EmployeeRelationCollection",
295 list: "XV.EmployeeList",
299 // ..........................................................
304 name: "XV.ExpenseCategoryWidget",
305 kind: "XV.RelationWidget",
306 collection: "XM.ExpenseCategoryCollection",
307 list: "XV.ExpenseCategoryList",
311 // ..........................................................
316 name: "XV.IncidentWidget",
317 kind: "XV.RelationWidget",
318 collection: "XM.IncidentRelationCollection",
319 list: "XV.IncidentList",
320 nameAttribute: "description"
323 // ..........................................................
328 name: "XV.ItemWidget",
329 kind: "XV.RelationWidget",
330 collection: "XM.ItemRelationCollection",
332 nameAttribute: "description1",
333 descripAttribute: "description2"
336 // ..........................................................
341 name: "XV.LedgerAccountWidget",
342 kind: "XV.RelationWidget",
343 collection: "XM.LedgerAccountRelationCollection",
344 list: "XV.LedgerAccountList",
345 keyAttribute: "name",
346 nameAttribute: "description"
349 // ..........................................................
354 name: "XV.OpportunityWidget",
355 kind: "XV.RelationWidget",
356 collection: "XM.OpportunityRelationCollection",
357 keyAttribute: "name",
358 list: "XV.OpportunityList"
361 // ..........................................................
366 name: "XV.ProjectWidget",
367 kind: "XV.RelationWidget",
368 collection: "XM.ProjectRelationCollection",
369 list: "XV.ProjectList",
370 create: function () {
371 this.inherited(arguments);
372 this.setShowing(XT.session.settings.get("UseProjects"));
374 setShowing: function (showing) {
375 if (!showing || showing && XT.session.settings.get("UseProjects")) {
376 this.inherited(arguments);
381 // ..........................................................
386 name: "XV.PurchaseOrderWidget",
387 kind: "XV.RelationWidget",
388 collection: "XM.PurchaseOrderRelationCollection",
389 keyAttribute: "number",
390 list: "XV.PurchaseOrderList"
393 // ..........................................................
398 name: "XV.SalesOrderWidget",
399 kind: "XV.RelationWidget",
400 collection: "XM.SalesOrderRelationCollection",
401 keyAttribute: "number",
402 list: "XV.SalesOrderList"
405 // ..........................................................
410 name: "XV.ShiftWidget",
411 kind: "XV.RelationWidget",
412 collection: "XM.ShiftCollection",
416 // ..........................................................
421 name: "XV.UserAccountWidget",
422 classes: "xv-useraccount-widget",
423 kind: "XV.RelationWidget",
424 collection: "XM.UserAccountRelationCollection",
425 list: "XV.UserAccountList",
426 keyAttribute: "username",
427 nameAttribute: "properName"
430 // ..........................................................
435 name: "XV.VendorWidget",
436 kind: "XV.RelationWidget",
437 collection: "XM.VendorRelationCollection",
438 keyAttribute: "number",
439 list: "XV.VendorList"