PageRenderTime 62ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/releases/extjs/myext/pagelist.js.php

http://toan-friendly-ch4n.googlecode.com/
PHP | 372 lines | 322 code | 13 blank | 37 comment | 12 complexity | ad9177388d4b6e3cf02348df0fbd0b8c MD5 | raw file
Possible License(s): AGPL-3.0
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. // Application instance for showing user-feedback messages.
  8. //var App = new Ext.App({});
  9. var fm = Ext.form;
  10. var base_url = '<?php echo base64_decode($_GET['baseUrl']);?>';
  11. var total_row = 20;
  12. <?php
  13. // Lay noi dung trong thu muc dua vao mot mang
  14. $dir = '../../application/views/front/';
  15. $fileList = scandir($dir) or die ("Not a directory");
  16. // In ra ten va kich thuoc tap tin
  17. $templateList = array();
  18. foreach ($fileList as $file) {
  19. if (is_file("$dir/$file") && $file != '.' && $file != '..') {
  20. $file = substr($file, 0, strpos($file, '.'));
  21. $templateList[]=array($file,$file);
  22. }
  23. }
  24. ?>
  25. var templateList = <?php echo json_encode($templateList);?>;
  26. <?php
  27. $langList = unserialize(base64_decode($_GET['langList']));
  28. $langFilter = array();
  29. foreach($langList as $k=>$v){
  30. $langFilter[]=array($k,$v);
  31. }
  32. $langFilter = json_encode($langFilter);
  33. $langList = json_encode($langList);
  34. ?>
  35. var langFilter = <?php echo $langFilter;?>;
  36. var langList = <?php echo $langList;?>;
  37. <?php
  38. $actionList = unserialize(base64_decode($_GET['actionList']));
  39. $actionFilter = array();
  40. foreach($actionList as $k=>$v){
  41. $actionFilter[]=array($k,$v);
  42. }
  43. $actionFilter = json_encode($actionFilter);
  44. $actionList = json_encode($actionList);
  45. ?>
  46. var actionList = <?php echo $actionList;?>;
  47. var actionFilter = <?php echo $actionFilter;?>;
  48. var proxy = new Ext.data.ScriptTagProxy({
  49. api: {
  50. read : base_url+'admin/page_management/page_grid.html',
  51. create : base_url+'admin/page_management/add_page.html',
  52. update: base_url+'admin/page_management/add_page.html',
  53. destroy: base_url+'admin/page_management/delete_page.html'
  54. }
  55. });
  56. /*proxy.addListener('beforeload', function(scriptProxy,params){
  57. offset = params.start;
  58. });*/
  59. // The new DataWriter component.
  60. var writer = new Ext.data.JsonWriter({
  61. encode: true // <-- don't return encoded JSON -- causes Ext.Ajax#request to send data using jsonData config rather than HTTP params
  62. });
  63. // Typical Store collecting the Proxy, Reader and Writer together.
  64. var store = new Ext.data.JsonStore({
  65. //id: 'id',
  66. //restful: true, // <-- This Store is RESTful
  67. start : 'start',
  68. remoteSort: true,
  69. totalProperty: 'total',
  70. proxy: proxy,
  71. root: 'data',
  72. fields : [
  73. {name: 'id'},
  74. {name: 'title', type: 'string', allowBlank: false},
  75. {name: 'link_title', type: 'string'},
  76. {name: 'page_heading', type: 'string'},
  77. {name: 'description', type: 'string'},
  78. {name: 'url', type: 'string'},
  79. {name: 'action',type: 'string', allowBlank: false},
  80. {name: 'language',type: 'string', allowBlank: false},
  81. {name: 'template',type: 'string', allowBlank: false},
  82. {name: 'edit',type: 'string'},
  83. {name: 'home',type: 'bool'},
  84. {name: 'error',type: 'bool'}
  85. ],
  86. listeners: {
  87. save: function(s, b, d) {
  88. store.save();
  89. }
  90. },
  91. writer: writer // <-- plug a DataWriter into the store just as you would a Reader
  92. });
  93. // load the store immeditately
  94. //store.load();
  95. var filters = new Ext.ux.grid.GridFilters({
  96. // encode and local configuration options defined previously for easier reuse
  97. encode: true, // json encode the filter query
  98. local: true, // defaults to false (remote filtering)
  99. filters: [{
  100. type: 'numeric',
  101. dataIndex: 'id'
  102. }, {
  103. type: 'string',
  104. dataIndex: 'title'
  105. }, {
  106. type: 'string',
  107. dataIndex: 'link_title'
  108. }, {
  109. type: 'string',
  110. dataIndex: 'page_heading'
  111. }, {
  112. type: 'string',
  113. dataIndex: 'description',
  114. disabled: true
  115. }, {
  116. type: 'string',
  117. dataIndex: 'url'
  118. }, {
  119. type: 'list',
  120. dataIndex: 'action',
  121. options: actionFilter,
  122. phpMode: true
  123. }, {
  124. type: 'list',
  125. dataIndex: 'language',
  126. options: langFilter,
  127. phpMode: true
  128. }, {
  129. type: 'list',
  130. dataIndex: 'template',
  131. options: templateList,
  132. phpMode: true
  133. }, {
  134. type: 'string',
  135. dataIndex: 'edit',
  136. disabled: true
  137. }, {
  138. type: 'boolean',
  139. dataIndex: 'home'
  140. }, {
  141. type: 'boolean',
  142. dataIndex: 'error'
  143. }]
  144. });
  145. var createColModel = function (finish, start) {
  146. var columns = [{header: "ID",
  147. width: 30,
  148. sortable: true,
  149. sort: 'id',
  150. dataIndex: 'id'
  151. },{
  152. header: "Title",
  153. //width: 100,
  154. sortable: true,
  155. sort: 'title',
  156. dataIndex: 'title',
  157. editor: new Ext.form.TextField({})
  158. },{
  159. header: "Link Title",
  160. //width: 100,
  161. sortable: true,
  162. sort: 'link_title',
  163. dataIndex: 'link_title',
  164. editor: new Ext.form.TextField({})
  165. },{
  166. header: "Page Heading",
  167. //width: 100,
  168. sortable: true,
  169. sort: 'page_heading',
  170. dataIndex: 'page_heading',
  171. editor: new Ext.form.TextField({})
  172. },{
  173. header: "Description",
  174. //width: 100,
  175. sortable: false,
  176. dataIndex: 'description',
  177. editor: new Ext.form.TextArea()
  178. },{
  179. header: "Url",
  180. //width: 100,
  181. sortable: true,
  182. sort: 'url',
  183. dataIndex: 'url',
  184. editor: new Ext.form.TextField({})
  185. },{
  186. header: "Action",
  187. renderer: formatAction,
  188. //width: 50,
  189. sortable: true,
  190. dataIndex: 'action',
  191. editor: new fm.ComboBox({
  192. editable: false,
  193. typeAhead: true,
  194. triggerAction: 'all',
  195. lazyRender:true,
  196. mode: 'local',
  197. store: new Ext.data.ArrayStore({
  198. id: 0,
  199. fields: [
  200. 'value',
  201. 'displayText'
  202. ],
  203. data: actionFilter
  204. }),
  205. valueField: 'value',
  206. displayField: 'displayText',
  207. listClass: 'x-combo-list-small'
  208. })
  209. },{
  210. header: "Language",
  211. renderer: formatLanguage,
  212. //width: 50,
  213. sortable: true,
  214. dataIndex: 'language',
  215. editor: new fm.ComboBox({
  216. editable: false,
  217. typeAhead: true,
  218. triggerAction: 'all',
  219. lazyRender:true,
  220. mode: 'local',
  221. store: new Ext.data.ArrayStore({
  222. id: 0,
  223. fields: [
  224. 'value',
  225. 'displayText'
  226. ],
  227. data: langFilter
  228. }),
  229. valueField: 'value',
  230. displayField: 'displayText',
  231. listClass: 'x-combo-list-small'
  232. })
  233. },{
  234. header: "Template",
  235. //width: 50,
  236. sortable: true,
  237. dataIndex: 'template',
  238. editor: new fm.ComboBox({
  239. editable: false,
  240. typeAhead: true,
  241. triggerAction: 'all',
  242. lazyRender:true,
  243. mode: 'local',
  244. store: new Ext.data.ArrayStore({
  245. id: 0,
  246. fields: [
  247. 'value',
  248. 'displayText'
  249. ],
  250. data: templateList
  251. }),
  252. valueField: 'value',
  253. displayField: 'displayText',
  254. listClass: 'x-combo-list-small'
  255. })
  256. },{
  257. header: "Edit",
  258. width: 20,
  259. sortable: true,
  260. sort: 'id',
  261. dataIndex: 'edit'
  262. },{
  263. xtype: 'checkcolumn',
  264. header: 'Home',
  265. dataIndex: 'home',
  266. width: 20
  267. },{
  268. xtype: 'checkcolumn',
  269. header: 'Error',
  270. dataIndex: 'error',
  271. width: 20
  272. }
  273. ];
  274. return new Ext.grid.ColumnModel({
  275. columns: columns.slice(start || 0, finish),
  276. defaults: {
  277. sortable: true
  278. }
  279. });
  280. };
  281. Ext.onReady(function() {
  282. Ext.QuickTips.init();
  283. // use RowEditor for editing
  284. var editor = new Ext.ux.grid.RowEditor({
  285. saveText: 'Update'
  286. });
  287. // Create a typical GridPanel with RowEditor plugin
  288. var pageGrid = new Ext.grid.GridPanel({
  289. renderTo: 'page-grid',
  290. iconCls: 'icon-grid',
  291. frame: true,
  292. height: 300,
  293. store: store,
  294. plugins: [editor,filters],
  295. colModel: createColModel(12),
  296. listeners: {
  297. render: {
  298. fn: function(){
  299. store.load({
  300. params: {
  301. start: 0,
  302. limit: total_row
  303. }
  304. });
  305. }
  306. }
  307. },
  308. tbar: [{
  309. text: 'Add',
  310. iconCls: 'silk-add',
  311. handler: onAdd
  312. }, '-', {
  313. text: 'Delete',
  314. iconCls: 'silk-delete',
  315. handler: onDelete
  316. }, '-'],
  317. bbar: new Ext.PagingToolbar({
  318. store: store,
  319. pageSize: total_row,
  320. plugins: [filters]
  321. }),
  322. viewConfig: {
  323. forceFit: true
  324. }
  325. });
  326. /**
  327. * onAdd
  328. */
  329. function onAdd(btn, ev) {
  330. var u = new pageGrid.store.recordType({});
  331. editor.stopEditing();
  332. pageGrid.store.insert(0, u);
  333. editor.startEditing(0);
  334. }
  335. /**
  336. * onDelete
  337. */
  338. function onDelete() {
  339. var recs = pageGrid.getSelectionModel().getSelections() ;
  340. if (!recs) {
  341. return false;
  342. }
  343. for(var i in recs)
  344. {
  345. pageGrid.store.remove(recs[i]);
  346. }
  347. }
  348. //store.on();
  349. });
  350. function formatAction(value){
  351. if(value!='')
  352. return eval('actionList.'+value);
  353. else return '';
  354. }
  355. function formatLanguage(value){
  356. if(value!='')
  357. return eval('langList.'+value);
  358. else return '';
  359. }