patcher.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. ///////////////////////////////////////////////////////////
  2. // 1.Ext.data.JsonReader
  3. ///////////////////////////////////////////////////////////
  4. Ext.override(Ext.data.JsonReader, {
  5. getJsonAccessor: function(){
  6. var re = /[\[\.]/;
  7. return function(expr) {
  8. try {
  9. // from here
  10. /*
  11. return(re.test(expr))
  12. ? new Function("rec", "defaultValue", "try{with (rec) return " + expr +
  13. " || defaultValue;}catch(e){return defaultValue;}")
  14. : function(rec, defaultValue){
  15. try {
  16. return rec[expr] || defaultValue;
  17. } catch (e) {
  18. return defaultValue;
  19. }
  20. };
  21. */
  22. // to here
  23. return(re.test(expr))
  24. ? new Function("rec", "defaultValue", "try{with (rec) if (" + expr + " !== 0) {return " + expr +
  25. " || defaultValue;} else {return 0;}}catch(e){return defaultValue;}")
  26. : function(rec, defaultValue){
  27. try {
  28. if (rec[expr] !== 0) {
  29. return rec[expr] || defaultValue;
  30. } else {
  31. return 0;
  32. }
  33. } catch (e) {
  34. return defaultValue;
  35. }
  36. };
  37. } catch(e){}
  38. return Ext.emptyFn;
  39. };
  40. }(),
  41. /**
  42. * Create a data block containing Ext.data.Records from an XML document.
  43. * @param {Object} o An object which contains an Array of row objects in the property specified
  44. * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
  45. * which contains the total size of the dataset.
  46. * @return {Object} data A data block which is used by an Ext.data.Store object as
  47. * a cache of Ext.data.Records.
  48. */
  49. readRecords : function(o){
  50. /**
  51. * After any data loads, the raw JSON data is available for further custom processing.
  52. * @type Object
  53. */
  54. this.jsonData = o;
  55. var s = this.meta, Record = this.recordType,
  56. f = Record.prototype.fields, fi = f.items, fl = f.length;
  57. // Generate extraction functions for the totalProperty, the root, the id, and for each field
  58. if (!this.ef) {
  59. if(s.totalProperty) {
  60. this.getTotal = this.getJsonAccessor(s.totalProperty);
  61. }
  62. if(s.successProperty) {
  63. this.getSuccess = this.getJsonAccessor(s.successProperty);
  64. }
  65. this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
  66. if (s.id) {
  67. var g = this.getJsonAccessor(s.id);
  68. this.getId = function(rec) {
  69. var r = g(rec);
  70. return (r === undefined || r === "") ? null : r;
  71. };
  72. } else {
  73. this.getId = function(){return null;};
  74. }
  75. this.ef = [];
  76. for(var i = 0; i < fl; i++){
  77. f = fi[i];
  78. var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
  79. this.ef[i] = this.getJsonAccessor(map);
  80. }
  81. }
  82. var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
  83. if(s.totalProperty){
  84. var v = parseInt(this.getTotal(o), 10);
  85. if(!isNaN(v)){
  86. totalRecords = v;
  87. }
  88. }
  89. if(s.successProperty){
  90. var v = this.getSuccess(o);
  91. if(v === false || v === 'false'){
  92. success = false;
  93. }
  94. }
  95. var records = [];
  96. for(var i = 0; i < c; i++){
  97. var n = root[i];
  98. var values = {};
  99. var id = this.getId(n);
  100. for(var j = 0; j < fl; j++){
  101. f = fi[j];
  102. // from here
  103. var v = this.ef[j](n, f.defaultValue);
  104. values[f.name] = f.convert(v);
  105. // to here
  106. }
  107. var record = new Record(values, id);
  108. record.json = n;
  109. records[i] = record;
  110. }
  111. return {
  112. success : success,
  113. records : records,
  114. totalRecords : totalRecords
  115. };
  116. }
  117. });
  118. ///////////////////////////////////////////////////////////
  119. // 2.Ext.menu.Adapter Ext.Toolbar.MenuButton
  120. ///////////////////////////////////////////////////////////
  121. if (Ext.version == '3.0') {
  122. Ext.menu.Adapter = Ext.menu.Menu;
  123. Ext.Toolbar.MenuButton = Ext.SplitButton;
  124. }
  125. ///////////////////////////////////////////////////////////
  126. // 3.Ext.Container
  127. ///////////////////////////////////////////////////////////
  128. if (typeof Ext.Container.prototype.removeAll == 'undefined') {
  129. Ext.override(Ext.Container, {
  130. removeAll: function() {
  131. var item = null;
  132. while ((item = this.items.last())) {
  133. this.remove(item, true);
  134. }
  135. }
  136. });
  137. }
  138. ///////////////////////////////////////////////////////////
  139. // 4.Ext.TreeField
  140. ///////////////////////////////////////////////////////////
  141. Ext.override(Ext.menu.DateMenu,{
  142. render : function(){
  143. Ext.menu.DateMenu.superclass.render.call(this);
  144. if(Ext.isGecko){
  145. this.picker.el.dom.childNodes[0].style.width = '178px';
  146. this.picker.el.dom.style.width = '178px';
  147. }
  148. }
  149. });