1 /** 2 * @fileOverview 3 * @author <a href="https://www.labkey.org">LabKey</a> (<a href="mailto:info@labkey.com">info@labkey.com</a>) 4 * @license Copyright (c) 2012-2019 LabKey Corporation 5 * <p/> 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * <p/> 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * <p/> 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * <p/> 18 */ 19 20 Ext.namespace("LABKEY", "LABKEY.ext"); 21 22 /* NOTE: This has been updated for Ext 3.1.1 23 * and required many changes from the Ext 2.0 version. 24 * Because it relies on overriding non-public 25 * member functions, this is likely to break in 26 * future versions of Ext. 27 */ 28 29 LABKEY.ext.ExtendedJsonReader = Ext.extend(Ext.data.JsonReader, { 30 /* Overridden to add .value to the id accessor */ 31 buildExtractors : function() { 32 if(this.ef){ 33 return; 34 } 35 var s = this.meta, Record = this.recordType, 36 f = Record.prototype.fields, fi = f.items, fl = f.length; 37 38 if(s.totalProperty) { 39 this.getTotal = this.createAccessor(s.totalProperty); 40 } 41 if(s.successProperty) { 42 this.getSuccess = this.createAccessor(s.successProperty); 43 } 44 if (s.messageProperty) { 45 this.getMessage = this.createAccessor(s.messageProperty); 46 } 47 this.getRoot = s.root ? this.createAccessor(s.root) : function(p){return p;}; 48 if (s.id || s.idProperty) { 49 var g = this.createAccessor((s.id || s.idProperty) + ".value"); //MODIFIED: id column value is in .value property 50 this.getId = function(rec) { 51 var r = g(rec); 52 return (r === undefined || r === '') ? null : r; 53 }; 54 } else { 55 this.getId = function(){return null;}; 56 } 57 var ef = []; 58 for(var i = 0; i < fl; i++){ 59 f = fi[i]; 60 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name; 61 ef.push(this.createAccessor(map)); 62 } 63 this.ef = ef; 64 }, 65 /** 66 * Overridden to handle the new extended format 67 * type-casts a single row of raw-data from server 68 * @param {Object} data 69 * @param {Array} items 70 * @param {Integer} len 71 * @private 72 */ 73 extractValues : function(data, items, len) { 74 var f, values = {}; 75 for(var j = 0; j < len; j++){ 76 f = items[j]; 77 if (this.ef[j]) //MODIFIED: silently ignore cases where this is no accessor--securityAdmin.js creates new fields for sorting 78 { 79 var v = this.ef[j](data); 80 var value = undefined === v ? undefined : v.value; //MODIFIED: column value is in .value property 81 if (value == null) 82 { 83 // Don't let Ext transforms null values to the "default" primitive values - 0, false, etc 84 values[f.name] = value; 85 } 86 else 87 { 88 values[f.name] = f.convert((value !== undefined) ? value : f.defaultValue, data); 89 } 90 } 91 } 92 return values; 93 } 94 95 }); 96