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(),
26 collection: "XM.ContactRelationCollection",
27 list: "XV.ContactList",
29 nameAttribute: "jobTitle",
30 descripAttribute: "phone",
35 {controlClasses: 'enyo-inline', components: [
36 {name: "label", classes: "xv-label"},
37 {kind: "onyx.InputDecorator", name: "decorator", classes: "xv-icon-decorator", components: [
38 {name: "input", kind: "onyx.Input",
39 onkeyup: "keyUp", onkeydown: "keyDown", onblur: "receiveBlur",
40 onfocus: "receiveFocus"},
41 {kind: "onyx.MenuDecorator", components: [
42 {kind: "onyx.IconButton", classes: "icon-folder-open-alt"},
43 {kind: "onyx.Menu", name: 'popupMenu', floating: true, components: [
44 {kind: "XV.MenuItem", name: "searchItem", content: "_search".loc()},
45 {kind: "XV.MenuItem", name: "openItem", content: "_open".loc(), disabled: true},
46 {kind: "XV.MenuItem", name: "newItem", content: "_new".loc(), disabled: true}
49 {name: "completer", kind: "XV.Completer"}
52 {name: 'descriptionContainer', components: [
53 {name: "jobTitleRow", controlClasses: "enyo-inline", showing: false, components: [
54 {classes: 'xv-description', name: "name"}
56 {name: "phoneRow", controlClasses: "enyo-inline", showing: false, components: [
57 {classes: "xv-description hyperlink", target: '_blank', name: "description"}
59 {name: "alternateRow", controlClasses: "enyo-inline", showing: false, components: [
60 {classes: "xv-description hyperlink", target: "_blank", name: "alternate"}
62 {name: "faxRow", controlClasses: "enyo-inline", showing: false, components: [
63 {classes: "xv-description hyperlink", target: "_blank", name: "fax"}
65 {name: "emailRow", controlClasses: "enyo-inline", showing: false, components: [
66 {classes: 'xv-description hyperlink', target: "_blank", name: "email"}
68 {name: "webAddressRow", controlClasses: "enyo-inline", showing: false, components: [
69 {classes: 'xv-description hyperlink', target: "_blank", name: "webAddress"}
71 {name: "addressRow", controlClasses: "enyo-inline", showing: false, components: [
72 {classes: "xv-description", name: "address", allowHtml: true}
76 setValue: function (value, options) {
77 this.inherited(arguments);
79 if (value && !value.get) {
80 // the value of the widget is still being fetched asyncronously.
81 // when the value is fetched, this function will be run again,
82 // so for now we can just stop here.
86 var jobTitle = value ? value.get("jobTitle") : "",
87 phone = value ? value.get("phone") : "",
88 alternate = value ? value.get("alternate") : "",
89 fax = value ? value.get("fax") : "",
90 primaryEmail = value ? value.get("primaryEmail") : "",
91 webAddress = value ? value.get("webAddress") : "",
92 address = value ? XM.Address.format(value.get("address")) : "",
93 showAddress = this.getShowAddress();
95 this.$.jobTitleRow.setShowing(!!jobTitle);
96 this.$.name.setContent(jobTitle);
98 this.$.phoneRow.setShowing(!!phone);
99 this.$.description.setContent(phone);
100 this.$.description.setAttribute('href', 'tel://' + phone);
102 this.$.alternateRow.setShowing(!!alternate);
103 this.$.alternate.setContent(alternate);
104 this.$.alternate.setAttribute('href', 'tel://' + alternate);
106 this.$.faxRow.setShowing(!!fax);
107 this.$.fax.setContent(fax);
108 this.$.fax.setAttribute('href', 'tel://' + fax);
110 this.$.emailRow.setShowing(!!primaryEmail);
111 this.$.email.setContent(primaryEmail);
112 this.$.email.setAttribute('href', 'mailto:' + primaryEmail);
114 this.$.webAddressRow.setShowing(!!webAddress);
115 this.$.webAddress.setContent(webAddress);
116 this.$.webAddress.setAttribute('href', '//' + alternate);
118 this.$.addressRow.setShowing(address && showAddress);
119 this.$.address.setContent(address);
121 openWindow: function () {
122 var address = this.value ? this.value.get("webAddress") : null;
123 if (address) { window.open("http://" + address); }
126 callPhone: function () {
127 var phoneNumber = this.value ? this.value.get("phone") : null,
130 win = window.open("tel://" + phoneNumber);
135 sendMail: function () {
136 var email = this.value ? this.value.get("primaryEmail") : null,
139 win = window.open("mailto:" + email);
146 // ..........................................................
151 name: "XV.CustomerWidget",
152 kind: "XV.RelationWidget",
153 collection: "XM.CustomerRelationCollection",
154 list: "XV.CustomerList"
158 name: "XV.BillingCustomerWidget",
159 kind: "XV.RelationWidget",
160 collection: "XM.BillingCustomerCollection",
161 query: { parameters: [{attribute: "isActive", value: true}]},
162 list: "XV.CustomerList"
166 name: "XV.SalesCustomerWidget",
167 kind: "XV.RelationWidget",
168 collection: "XM.SalesCustomerCollection",
169 list: "XV.CustomerList"
172 // ..........................................................
176 name: "XV.CustomerGroupWidget",
177 kind: "XV.RelationWidget",
178 collection: "XM.CustomerGroupCollection",
179 keyAttribute: "name",
180 list: "XV.CustomerGroupList"
183 // ..........................................................
188 name: "XV.CustomerProspectWidget",
189 kind: "XV.RelationWidget",
190 collection: "XM.CustomerProspectRelationCollection",
191 list: "XV.CustomerProspectList",
192 create: function () {
193 var ret = this.inherited(arguments);
194 this.createComponent({
196 name: "customerOrProspectPopup",
201 onShow: "popupShown",
202 onHide: "popupHidden",
204 {content: "_customerOrProspect".loc()},
206 {kind: "onyx.Button", name: "customerButton", content: "_customer".loc(), ontap: "popupTapped",
207 classes: "onyx-blue xv-popup-button"},
208 {kind: "onyx.Button", name: "prospectButton", content: "_prospect".loc(), ontap: "popupTapped",
209 classes: "onyx-blue xv-popup-button"}
212 this.$.newItem.setDisabled(false);
217 this overrides the menuItemSelected function of RelationWidget to
218 account for the different types of models presented by the widget.
220 menuItemSelected: function (inSender, inEvent) {
222 menuItem = inEvent.originator,
223 list = this.getList(),
224 model = this.getValue(),
225 K, status, id, workspace,
228 switch (menuItem.name)
231 callback = function (value) {
232 that.setValue(value);
236 searchText: this.$.input.getValue(),
241 K = model.getClass();
242 status = model.get("status");
243 id = model ? model.id : null;
244 workspace = status === K.PROSPECT_STATUS ? "XV.ProspectWorkspace" : "XV.CustomerWorkspace";
247 workspace: workspace,
253 this.$.customerOrProspectPopup.show();
256 popupTapped: function (inSender, inEvent) {
258 callback = function (model) {
259 if (!model) { return; }
260 var Model = that._collection.model,
264 options.success = function () {
265 that.setValue(value);
267 attrs[Model.prototype.idAttribute] = model.id;
268 value = Model.findOrCreate(attrs);
269 value.fetch(options);
272 this.$.customerOrProspectPopup.hide();
275 workspace: inEvent.originator.name === "customerButton" ?
276 "XV.CustomerWorkspace" : "XV.ProspectWorkspace",
282 // ..........................................................
287 name: "XV.CustomerShiptoWidget",
288 kind: "XV.RelationWidget",
289 collection: "XM.CustomerShiptoRelationCollection",
290 list: "XV.CustomerShiptoList"
293 // ..........................................................
298 name: "XV.DepartmentWidget",
299 kind: "XV.RelationWidget",
300 collection: "XM.DepartmentCollection",
301 list: "XV.DepartmentList"
304 // ..........................................................
309 name: "XV.EmployeeWidget",
310 kind: "XV.RelationWidget",
311 collection: "XM.EmployeeRelationCollection",
312 list: "XV.EmployeeList",
316 // ..........................................................
321 name: "XV.ExpenseCategoryWidget",
322 kind: "XV.RelationWidget",
323 collection: "XM.ExpenseCategoryCollection",
324 list: "XV.ExpenseCategoryList",
328 // ..........................................................
333 name: "XV.IncidentWidget",
334 kind: "XV.RelationWidget",
335 collection: "XM.IncidentRelationCollection",
336 list: "XV.IncidentList",
337 nameAttribute: "description"
340 // ..........................................................
345 name: "XV.ItemWidget",
346 kind: "XV.RelationWidget",
347 collection: "XM.ItemRelationCollection",
349 nameAttribute: "description1",
350 descripAttribute: "description2"
353 // ..........................................................
358 name: "XV.LedgerAccountWidget",
359 kind: "XV.RelationWidget",
360 collection: "XM.LedgerAccountRelationCollection",
361 list: "XV.LedgerAccountList",
362 keyAttribute: "name",
363 nameAttribute: "description"
366 // ..........................................................
371 name: "XV.OpportunityWidget",
372 kind: "XV.RelationWidget",
373 collection: "XM.OpportunityRelationCollection",
374 keyAttribute: "name",
375 list: "XV.OpportunityList"
378 // ..........................................................
383 name: "XV.ProjectWidget",
384 kind: "XV.RelationWidget",
385 collection: "XM.ProjectRelationCollection",
386 list: "XV.ProjectList",
387 create: function () {
388 this.inherited(arguments);
389 this.setShowing(XT.session.settings.get("UseProjects"));
391 setShowing: function (showing) {
392 if (!showing || showing && XT.session.settings.get("UseProjects")) {
393 this.inherited(arguments);
398 // ..........................................................
403 name: "XV.PurchaseOrderWidget",
404 kind: "XV.RelationWidget",
405 collection: "XM.PurchaseOrderRelationCollection",
406 keyAttribute: "number",
407 list: "XV.PurchaseOrderList"
410 // ..........................................................
415 name: "XV.SalesOrderWidget",
416 kind: "XV.RelationWidget",
417 collection: "XM.SalesOrderRelationCollection",
418 keyAttribute: "number",
419 list: "XV.SalesOrderList"
422 // ..........................................................
427 name: "XV.ShiftWidget",
428 kind: "XV.RelationWidget",
429 collection: "XM.ShiftCollection",
433 // ..........................................................
438 name: "XV.UserAccountWidget",
439 classes: "xv-useraccount-widget",
440 kind: "XV.RelationWidget",
441 collection: "XM.UserAccountRelationCollection",
442 list: "XV.UserAccountList",
443 keyAttribute: "username",
444 nameAttribute: "properName"
447 // ..........................................................
452 name: "XV.VendorWidget",
453 kind: "XV.RelationWidget",
454 collection: "XM.VendorRelationCollection",
455 keyAttribute: "number",
456 list: "XV.VendorList"