PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/releases/extjs/myext/products_list.js.php

http://toan-friendly-ch4n.googlecode.com/
PHP | 180 lines | 165 code | 14 blank | 1 comment | 6 complexity | 9ab46c4d1a38cb1c54cf660905ad660b MD5 | raw file
Possible License(s): AGPL-3.0
  1. var fm = Ext.form;
  2. var base_url = '<?php echo base64_decode($_GET['baseUrl']);?>';
  3. var total_row = 20;
  4. var proxy = new Ext.data.ScriptTagProxy({
  5. api: {
  6. read : base_url+'admin/products/grid.html',
  7. create : base_url+'admin/products/add.html',
  8. update: base_url+'admin/products/add.html',
  9. destroy: base_url+'admin/products/delete.html'
  10. }
  11. });
  12. var writer = new Ext.data.JsonWriter({
  13. encode: true
  14. });
  15. var store = new Ext.data.JsonStore({
  16. start : 'start',
  17. remoteSort: true,
  18. totalProperty: 'total',
  19. proxy: proxy,
  20. root: 'data',
  21. fields : [
  22. {name: 'id'},
  23. {name: 'name'},
  24. {name: 'product_code'},
  25. {name: 'thumb',type: 'string'},
  26. {name: 'edit',type: 'string'},
  27. {name: 'onhome',type: 'bool'},
  28. {name: 'showtype',type: 'bool'},
  29. {name: 'is_no_sale',type: 'bool'},
  30. {name: 'hot_item',type: 'bool'}
  31. ],
  32. listeners: {
  33. save: function(s, b, d) {
  34. store.save();
  35. }
  36. },
  37. writer: writer
  38. });
  39. var filters = new Ext.ux.grid.GridFilters({
  40. // encode and local configuration options defined previously for easier reuse
  41. encode: true, // json encode the filter query
  42. local: true, // defaults to false (remote filtering)
  43. filters: [
  44. {type: 'string',dataIndex: 'name'},
  45. {type: 'string',dataIndex: 'product_code'},
  46. ]
  47. });
  48. var createColModel = function () {
  49. var columns = [
  50. {header: 'ID',sort: 'id',dataIndex: 'id'},
  51. {header: 'Name',sortable: true,sort: 'name',dataIndex: 'name'},
  52. {header: 'Product Code',sortable: true,sort: 'product_code',dataIndex: 'product_code'},
  53. {header: 'Image',dataIndex: 'thumb',sortable: false},
  54. {header: 'On Home',dataIndex: 'onhome',sortable: false,xtype:'checkcolumn'},
  55. {header: 'La TBSan Xuat',dataIndex: 'is_no_sale',sortable: false,xtype:'checkcolumn'},
  56. {header: 'Show Type',dataIndex: 'showtype',sortable: false,xtype:'checkcolumn'},
  57. {header: 'Hot Item',dataIndex: 'hot_item',sortable: false,xtype:'checkcolumn'},
  58. {header: 'Edit',dataIndex: 'edit',sortable: false}
  59. ];
  60. return new Ext.grid.ColumnModel({
  61. columns: columns,
  62. defaults: {
  63. sortable: true
  64. }
  65. });
  66. };
  67. pagingBar = new Ext.PagingToolbar({
  68. store: store,
  69. pageSize: total_row,
  70. displayInfo: true,
  71. displayMsg: 'Displaying item {0} - {1} of {2}',
  72. emptyMsg: "No item to display",
  73. plugins: new Ext.ux.ProgressBarPager()
  74. });
  75. Ext.onReady(function() {
  76. Ext.QuickTips.init();
  77. var newsGrid = new Ext.grid.GridPanel({
  78. renderTo: 'news-grid',
  79. iconCls: 'icon-grid',
  80. frame: true,
  81. height: eval(Ext.getBody().getViewSize().height - 280),
  82. store: store,
  83. plugins: [filters],
  84. colModel: createColModel(),
  85. listeners: {
  86. render: {
  87. fn: function(){
  88. store.load({
  89. params: {
  90. start: 0,
  91. limit: total_row
  92. }
  93. });
  94. }
  95. }
  96. },
  97. tbar: [new Ext.form.ComboBox({
  98. triggerAction: 'all',
  99. lazyRender:false,
  100. width:40,
  101. mode: 'local',
  102. store: new Ext.data.ArrayStore({
  103. fields: [
  104. 'id',
  105. 'value'
  106. ],
  107. data: [[10,'10'],[20,'20'],[50,'50'],[100,'100']]
  108. }),
  109. valueField: 'id',
  110. displayField: 'value',
  111. listeners:{
  112. 'select': function(combo,record ,index){
  113. total_row = combo.getValue();
  114. store.reload({params:{start:0, limit:total_row}});
  115. pagingBar.pageSize = total_row;
  116. pagingBar.render();
  117. }
  118. }
  119. })
  120. ,'-',{
  121. text: 'Add',
  122. iconCls: 'silk-add',
  123. handler: onAdd
  124. }, '-', {
  125. text: 'Delete',
  126. iconCls: 'silk-delete',
  127. handler: onDelete
  128. }, '-'],
  129. bbar: pagingBar,
  130. viewConfig: {
  131. forceFit: true
  132. }
  133. });
  134. function onAdd(btn, ev) {
  135. window.location.href = base_url+'admin/products/edit';
  136. }
  137. function onDelete() {
  138. Ext.MessageBox.show({
  139. title:'Delete item',
  140. msg: 'Do you really want to delete this item ?',
  141. buttons: Ext.MessageBox.YESNO,
  142. animEl: 'samplebutton',
  143. icon: Ext.MessageBox.QUESTION,
  144. fn:function(buttonId){
  145. if (buttonId == 'yes'){
  146. var recs = newsGrid.getSelectionModel().getSelections() ;
  147. if (!recs) {
  148. return false;
  149. }
  150. for(var i in recs)
  151. {
  152. newsGrid.store.remove(recs[i]);
  153. }
  154. }
  155. }
  156. });
  157. }
  158. });
  159. function formatDate(value){
  160. return value ? value.dateFormat('d-m-Y') : '';
  161. }
  162. function formatLanguage(value){
  163. if(value!='')
  164. return eval('langList.'+value);
  165. else return '';
  166. }