Skip to content
This repository
Browse code

issue #19735: Get rid of is not ready check once and for all.

  • Loading branch information...
commit b910b44a2563631e359e66f2f8428f1e72da4a2d 1 parent edc40a0
John Rogelstad authored
1  enyo-client/application/source/models/currency.js
@@ -41,7 +41,6 @@ white:true*/
41 41
     abbreviationDidChange: function (model, value, options) {
42 42
       var that = this,
43 43
         checkOptions = {};
44  
-      if (this.isNotReady()) { return; }
45 44
 
46 45
       checkOptions.success = function (resp) {
47 46
         var err, params = {};
4  enyo-client/application/source/models/customer.js
@@ -276,7 +276,7 @@ white:true*/
276 276
     
277 277
     salesRepDidChange: function () {
278 278
       var salesRep = this.get('salesRep');
279  
-      if (!salesRep || this.isNotReady()) { return; }
  279
+      if (!salesRep) { return; }
280 280
       this.set('commission', salesRep.get('commission'));
281 281
     }
282 282
 
@@ -484,7 +484,7 @@ white:true*/
484 484
 
485 485
     salesRepDidChange: function () {
486 486
       var salesRep = this.get('salesRep');
487  
-      if (!salesRep || this.isNotReady()) { return; }
  487
+      if (!salesRep) { return; }
488 488
       this.set('commission', salesRep.get('commission'));
489 489
     }
490 490
 
1  enyo-client/application/source/models/incident.js
@@ -182,7 +182,6 @@ white:true*/
182 182
     },
183 183
 
184 184
     assignedToDidChange: function (model, value, options) {
185  
-      if (this.isNotReady()) { return; }
186 185
       if (value) { this.set('status', XM.Incident.ASSIGNED); }
187 186
     },
188 187
 
1  enyo-client/application/source/models/item.js
@@ -212,7 +212,6 @@ white:true*/
212 212
     },
213 213
 
214 214
     inventoryUnitDidChange: function (model, value, options) {
215  
-      if (this.isNotReady()) { return; }
216 215
       if (value) { this.set('priceUnit', value); }
217 216
     },
218 217
 
39  enyo-client/application/source/models/quote.js
@@ -172,8 +172,6 @@ white:true*/
172 172
         siteClass = [],
173 173
         i;
174 174
 
175  
-      if (this.isNotReady()) { return this; }
176  
-
177 175
       if (customer && currency && docDate && lineItems.length) {
178 176
         // Collect data needed for freight
179 177
         for (i = 0; i < lineItems.length; i++) {
@@ -272,8 +270,6 @@ white:true*/
272 270
         dispOptions = {},
273 271
         params;
274 272
 
275  
-      if (this.isNotReady()) { return this; }
276  
-
277 273
       if (effective && currency && amount) {
278 274
         params = [taxZoneId, taxTypeId, effective, currency.id, amount];
279 275
         dispOptions.success = function (resp) {
@@ -295,8 +291,6 @@ white:true*/
295 291
       var lineItems = this.get("lineItems").models,
296 292
         scheduleDate;
297 293
 
298  
-      if (this.isNotReady()) { return this; }
299  
-
300 294
       if (lineItems.length) {
301 295
         _.each(lineItems, function (line) {
302 296
           var lineSchedDate = line.get("scheduleDate");
@@ -321,8 +315,6 @@ white:true*/
321 315
     calculateTotals: function (calcFreight) {
322 316
       var calculateFreight = this.get("calculateFreight");
323 317
 
324  
-      if (this.isNotReady()) { return this; }
325  
-
326 318
       if (calculateFreight && calcFreight !== false) {
327 319
         this.calculateFreight();
328 320
       } else {
@@ -395,8 +387,6 @@ white:true*/
395 387
         this.setReadOnly(this.shiptoAttrArray[i], isFreeFormShipto);
396 388
       }
397 389
 
398  
-      if (this.isNotReady()) { return; }
399  
-
400 390
       // Set customer default data
401 391
       if (customer) {
402 392
         billtoAttrs = {
@@ -508,7 +498,6 @@ white:true*/
508 498
       asking the question, which must be answered via the attached callback to complete the process.
509 499
     */
510 500
     freightDidChange: function () {
511  
-      if (this.isNotReady()) { return; }
512 501
       var calculateFreight = this.get("calculateFreight"),
513 502
         freight = this.get("freight"),
514 503
         that = this,
@@ -579,7 +568,7 @@ white:true*/
579 568
         options = {},
580 569
         that = this;
581 570
 
582  
-      if (this.isNotReady || !lineItems.length) { return; }
  571
+      if (!lineItems.length) { return; }
583 572
 
584 573
       options.type = XM.Model.QUESTION;
585 574
 
@@ -650,7 +639,7 @@ white:true*/
650 639
         shiptoAddress = shiptoContact ? shiptoContact.get("address") : false,
651 640
         shiptoAttrs;
652 641
 
653  
-      if (this.isNotReady() || !shipto) { return; }
  642
+      if (!shipto) { return; }
654 643
 
655 644
       shiptoAttrs = {
656 645
         shiptoName: shipto.get("name"),
@@ -692,12 +681,10 @@ white:true*/
692 681
 
693 682
     shiptoAddressDidChange: function () {
694 683
       // If the address was manually changed, then clear shipto
695  
-      if (this.isNotReady()) { return; }
696 684
       this.unset("shipto");
697 685
     },
698 686
 
699 687
     siteDidChange: function () {
700  
-      if (this.isNotReady()) { return; }
701 688
       var fob = this.getValue("site.fob") || "";
702 689
       this.set("fob", fob);
703 690
     },
@@ -977,8 +964,6 @@ white:true*/
977 964
         price = this.get("price"),
978 965
         options = {};
979 966
 
980  
-      if (this.isNotReady()) { return; }
981  
-
982 967
       options.success = function (basePrice) {
983 968
         var K = that.getClass(),
984 969
           priceMode = that.get("priceMode"),
@@ -1046,7 +1031,7 @@ white:true*/
1046 1031
         currency = parent ? parent.get("currency") :false;
1047 1032
 
1048 1033
       // If no parent, don't bother
1049  
-      if (!parent || this.isNotReady()) { return; }
  1034
+      if (!parent) { return; }
1050 1035
 
1051 1036
       // Make sure we have necessary values
1052 1037
       if (canUpdate && customer && currency &&
@@ -1085,8 +1070,6 @@ white:true*/
1085 1070
         that = this,
1086 1071
         options = {};
1087 1072
 
1088  
-      if (this.isNotReady()) { return; }
1089  
-
1090 1073
       if (price) {
1091 1074
         if (standardCost) {
1092 1075
           options.success = function (value) {
@@ -1114,7 +1097,7 @@ white:true*/
1114 1097
         params;
1115 1098
 
1116 1099
       // If no parent, don't bother
1117  
-      if (!parent || this.isNotReady()) { return; }
  1100
+      if (!parent) { return; }
1118 1101
 
1119 1102
       recordType = parent.recordType;
1120 1103
       taxZoneId = parent.getValue("taxZone.id");
@@ -1158,8 +1141,6 @@ white:true*/
1158 1141
         discounted,
1159 1142
         price;
1160 1143
 
1161  
-      if (this.isNotReady()) { return; }
1162  
-
1163 1144
       if (!customerPrice) {
1164 1145
         this.unset("discount");
1165 1146
       } else if (this._updatePrice) {
@@ -1201,8 +1182,6 @@ white:true*/
1201 1182
         item.sellingUnits(unitOptions);
1202 1183
       }
1203 1184
 
1204  
-      if (this.isNotReady()) { return; }
1205  
-
1206 1185
       // Reset values
1207 1186
       this.unset("quantityUnit");
1208 1187
       this.unset("priceUnit");
@@ -1288,8 +1267,6 @@ white:true*/
1288 1267
        lineNumber = this.get("lineNumber"),
1289 1268
        scheduleDate;
1290 1269
 
1291  
-      if (this.isNotReady()) { return; }
1292  
-
1293 1270
       // Set next line number
1294 1271
       if (parent && !lineNumber) {
1295 1272
         this.set("lineNumber", parent.get("lineItems").length);
@@ -1327,8 +1304,8 @@ white:true*/
1327 1304
         inventoryUnit = item ? this.getValue("inventoryUnit") : false,
1328 1305
         that = this,
1329 1306
         options = {};
1330  
-        
1331  
-      if (!inventoryUnit || !quantityUnit || !priceUnit || this.isNotReady()) { return; }
  1307
+    
  1308
+      if (!inventoryUnit || !quantityUnit || !priceUnit) { return; }
1332 1309
       
1333 1310
       if (inventoryUnit.id === priceUnit.id) {
1334 1311
         this.set("priceUnitRatio", 1);
@@ -1355,7 +1332,7 @@ white:true*/
1355 1332
         isFractionalCache,
1356 1333
         ratioCache;
1357 1334
 
1358  
-      if (!inventoryUnit || !quantityUnit || this.isNotReady()) { return; }
  1335
+      if (!inventoryUnit || !quantityUnit) { return; }
1359 1336
 
1360 1337
       if (quantityUnit.id === item.get("inventoryUnit").id) {
1361 1338
         this.set("quantityUnitRatio", 1);
@@ -1429,8 +1406,6 @@ white:true*/
1429 1406
         that = this,
1430 1407
         options = {};
1431 1408
 
1432  
-      if (this.isNotReady()) { return; }
1433  
-
1434 1409
       if (customer && item && scheduleDate) {
1435 1410
         options.success = function (canPurchase) {
1436 1411
           if (!canPurchase) {
1  enyo-client/application/source/models/to_do.js
@@ -106,7 +106,6 @@ white:true*/
106 106
         completeDate = this.get('completeDate'),
107 107
         K = XM.ToDo,
108 108
         attrStatus = K.NEITHER;
109  
-      if (this.isNotReady()) { return; }
110 109
 
111 110
       // Set the `status` attribute with appropriate value
112 111
       if (completeDate) {
2  enyo-client/application/source/models/user_account.js
@@ -173,8 +173,6 @@ white:true*/
173 173
         return;
174 174
       }
175 175
 
176  
-      if (this.isNotReady()) { return; }
177  
-
178 176
       // Check for conflicts
179 177
       if (this.checkConflicts && value && this.isDirty() && !this._number) {
180 178
         options.success = function (resp) {
1  lib/backbone-x/source/alarm.js
@@ -27,7 +27,6 @@ white:true*/
27 27
         qualifier,
28 28
         time,
29 29
         trigger;
30  
-      if (this.isNotReady()) { return; }
31 30
 
32 31
       // Recalculate trigger time based on alarm settings
33 32
       offset = this.get('offset');
1  lib/backbone-x/source/characteristic.js
@@ -186,7 +186,6 @@ white:true*/
186 186
     },
187 187
 
188 188
     characteristicDidChange: function (model, value, options) {
189  
-      if (this.isNotReady()) { return; }
190 189
       this.set('value', '');
191 190
     }
192 191
 
1  lib/backbone-x/source/document.js
@@ -149,7 +149,6 @@ white:true*/
149 149
       if (this.keyIsString && value && value.toUpperCase) {
150 150
         upper = upper.toUpperCase();
151 151
       }
152  
-      if (this.isNotReady()) { return; }
153 152
 
154 153
       // Handle uppercase
155 154
       if (this.enforceUpperKey && value !== upper) {
84  lib/backbone-x/source/model.js
@@ -684,7 +684,7 @@ white:true*/
684 684
       return status === K.READY_NEW || status === K.READY_DIRTY;
685 685
     },
686 686
 
687  
-        /**
  687
+    /**
688 688
       Returns true if the model is in one of the `READY` statuses
689 689
     */
690 690
     isReady: function () {
@@ -696,17 +696,6 @@ white:true*/
696 696
     },
697 697
 
698 698
     /**
699  
-      Returns true if the model is not in one of the `READY` statuses
700  
-    */
701  
-    isNotReady: function () {
702  
-      var status = this.getStatus(),
703  
-        K = XM.Model;
704  
-      return status !== K.READY_NEW &&
705  
-             status !== K.READY_CLEAN &&
706  
-             status !== K.READY_DIRTY;
707  
-    },
708  
-
709  
-    /**
710 699
       Returns true if you have the lock key, or if this model
711 700
       is not lockable. (You can enter the room if you have no
712 701
       key or if there is no lock!). When this value is true and the
@@ -1005,6 +994,46 @@ white:true*/
1005 994
       XT.log('No changes to save');
1006 995
       return false;
1007 996
     },
  997
+    
  998
+    /**
  999
+      Overload: Don't allow setting when model is in error or destroyed status, or
  1000
+      updating a `READY_CLEAN` record without update privileges.
  1001
+
  1002
+      @param {String|Object} Key
  1003
+      @param {String|Object} Value or Options
  1004
+      @param {Objecw} Options
  1005
+    */
  1006
+    set: function (key, val, options) {
  1007
+      var K = XM.Model,
  1008
+        keyIsObject = _.isObject(key),
  1009
+        status = this.getStatus(),
  1010
+        err;
  1011
+        
  1012
+      // Handle both `"key", value` and `{key: value}` -style arguments.
  1013
+      if (keyIsObject) { options = val; }
  1014
+      options = options ? options : {};
  1015
+      
  1016
+      // Don't allow editing of records that are ineligable
  1017
+      if (status === K.ERROR || (status & K.DESTROYED)) {
  1018
+        err = XT.Error.clone('xt1009', { params: { status: status } });
  1019
+      } else if (status === K.READY_CLEAN && !this.canUpdate()) {
  1020
+        err = XT.Error.clone('xt1010');
  1021
+      }
  1022
+      
  1023
+      // If we're not in a `READY` state, silence all events
  1024
+      if (!this.isReady() && !_.isBoolean(options.silent)) {
  1025
+        options.silent = true;
  1026
+      }
  1027
+      
  1028
+      if (err) {
  1029
+        this.trigger('invalid', this, options);
  1030
+        return false;
  1031
+      }
  1032
+      
  1033
+      if (keyIsObject) { val = options; }
  1034
+
  1035
+      return Backbone.RelationalModel.prototype.set.call(this, key, val, options);
  1036
+    },
1008 1037
 
1009 1038
     /**
1010 1039
       Set the entire model, or a specific model attribute to `readOnly`.<br />
@@ -1067,7 +1096,7 @@ white:true*/
1067 1096
         that = this,
1068 1097
         parent,
1069 1098
         parentRelation,
1070  
-        setOptions = { force: true };
  1099
+        dataState;
1071 1100
 
1072 1101
       // Prevent recursion
1073 1102
       if (this.isLocked() || this.status === status) { return; }
@@ -1100,15 +1129,21 @@ white:true*/
1100 1129
       }
1101 1130
 
1102 1131
       // Update data state at this level.
1103  
-      if (status === K.READY_NEW) {
1104  
-        this.set('dataState', 'create', setOptions);
1105  
-      } else if (status === K.READY_CLEAN) {
1106  
-        this.set('dataState', 'read', setOptions);
1107  
-      } else if (status === K.READY_DIRTY) {
1108  
-        this.set('dataState', 'update', setOptions);
1109  
-      } else if (status === K.DESTROYED_DIRTY) {
1110  
-        this.set('dataState', 'delete', setOptions);
  1132
+      switch (status)
  1133
+      {
  1134
+      case K.READY_NEW:
  1135
+        dataState = 'create';
  1136
+        break;
  1137
+      case K.READY_CLEAN:
  1138
+        dataState = 'read';
  1139
+        break;
  1140
+      case K.READY_DIRTY:
  1141
+        dataState = 'update';
  1142
+        break;
  1143
+      case K.DESTROYED_DIRTY:
  1144
+        dataState = 'delete';
1111 1145
       }
  1146
+      this.attributes.dataState = dataState;
1112 1147
 
1113 1148
       // Percolate changes up to parent when applicable
1114 1149
       if (parent && (this.isDirty() ||
@@ -1187,9 +1222,7 @@ white:true*/
1187 1222
       attributes = attributes || {};
1188 1223
       options = options || {};
1189 1224
       var that = this, i, result,
1190  
-        K = XM.Model,
1191 1225
         S = XT.Session,
1192  
-        status = this.getStatus(),
1193 1226
         attr, value, category, column, params = {},
1194 1227
         type = this.recordType.replace(/\w+\./i, ''),
1195 1228
         columns = XT.session.getSchema().get(type).columns,
@@ -1214,11 +1247,6 @@ white:true*/
1214 1247
           });
1215 1248
         };
1216 1249
 
1217  
-      // Don't allow editing of records that are ineligable
1218  
-      if (status === K.ERROR || status === K.EMPTY || (status & K.DESTROYED)) {
1219  
-        return XT.Error.clone('xt1009', { params: { status: this.getStatusString() } });
1220  
-      }
1221  
-
1222 1250
       // Check data type integrity
1223 1251
       for (attr in attributes) {
1224 1252
         if (attributes.hasOwnProperty(attr) &&

0 notes on commit b910b44

Please sign in to comment.
Something went wrong with that request. Please try again.