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 */
3 /*global XT:true, XM:true, enyo:true, _:true, XV:true */
8 name: "XV.AccountRoleCheckboxWidget",
9 kind: "XV.CheckboxWidget",
21 this.inherited(arguments);
22 this.$.input.setChecked(false);
24 inputChanged: function (inSender, inEvent) {
25 var isNotRelation = !this.isRelation(),
26 input = this.$.input.getValue(),
27 value = isNotRelation && input ? 1 : null;
30 isRelation: function () {
31 if (this._isRelation !== undefined) { return this._isRelation; }
32 var model = this.getOwner().getValue(),
35 // Relation is true if it is not a number based attribute
37 attr = this.getAttr();
38 this._isRelation = _.isObject(model.getRelation(attr));
40 return this._isRelation;
42 setDisabled: function (isDisabled) {
43 this.$.input.setDisabled(isDisabled || this.getLinkEnabled());
45 setValue: function (value, options) {
46 this.inherited(arguments);
47 options = options || {};
48 var isRelation = this.isRelation(),
52 input = this.$.input.getValue(),
65 // Turn on label link if applicable
66 if (this.getValue() && isRelation) {
70 this.$.label.setStyle("color: " + color);
71 this.setLinkEnabled(enabled);
72 this.setDisabled(enabled);
74 // Automatically open a workspace to set up a record for this role if necessary
75 if (input && isRelation && !value && !options.silent) {
76 model = this.getOwner().getValue();
77 relation = model.getRelation(this.getAttr());
78 recordType = relation.relatedModel.prototype.recordType;
79 Klass = XT.getObjectByName(recordType);
81 // If it has an editable model it must be an XM.Info model
82 if (Klass.prototype.editableModel) {
83 Klass = XT.getObjectByName(Klass.prototype.editableModel);
84 documentKey = Klass.prototype.documentKey;
85 map = Klass.prototype.conversionMap;
87 documentKey = relation.relatedModel.prototype.documentKey;
88 map = relation.relatedModel.prototype.conversionMap;
90 // Most account docs will make this upper again, but needs to be lower for user account
91 attrs[documentKey] = model.get("number");
92 // Map other attribute candidates
93 _.each(map, function (value, key) {
94 attrs[value] = model.get(key);
97 // Init function for new workspace. Makes sure the workspace understands
98 // The account is already "converted".
99 success = function () {
100 this.getValue().checkConflicts = false;
103 // Callback to handle result of new role
104 callback = function (model) {
106 that.getOwner().requery();
108 that.$.input.setChecked(false);
112 // Only open the workspace if `valid` is true
113 openWorkspace = function (valid) {
116 workspace: XV.getWorkspace(recordType),
123 that.$.input.setChecked(false);
127 // Must have committed all changes before proceeding
128 if (model.isDirty()) {
130 callback: openWorkspace
137 tapped: function (inSender, inEvent) {
139 if (inEvent.originator.name === "label" &&
140 this.getLinkEnabled()) {
141 value = this.getValue();
143 workspace: XV.getWorkspace(value.recordType),