用Ext做的后台操作(包括,增,删,改,查)和一个异步加载的Ext树

用Ext做的后台操作(包括,增,删,改,查)和一个异步加载的Ext树
  1.     
  2. function createField(fieldLabel, id, name1, value) {   
  3.   
  4.     var field = new Ext.form.TextField({   
  5.         fieldLabel : fieldLabel,   
  6.         width : 380,   
  7.         itemCls : 'all-field',   
  8.         clearCls : 'allow-float',   
  9.         allowBlank : false,   
  10.         name : name1,   
  11.         value : value   
  12.     });   
  13.   
  14.     return field;   
  15.   
  16. }   
  17. function saveHandler(win, requestUrl, node, formPanel, isUpdate) {   
  18.     /*  
  19.      * Ext.MessageBox.show({ title:'请稍候', msg:'保存中,请稍后...', progress:true,  
  20.      * buttons: {cancel:'取消'} });  
  21.      */  
  22.   
  23.     var form = formPanel.getForm();   
  24.     form.submit({   
  25.         url : requestUrl,   
  26.         waitMsg : '保存中,请稍候...',   
  27.         params : {},   
  28.         success : function(response, request) {   
  29.             if (!isUpdate) {   
  30.                 Ext.MessageBox.confirm("状态""保存成功,继续添加吗?", function(btn) {   
  31.                     if (btn != 'yes') {   
  32.                         win.close();   
  33.                     }   
  34.   
  35.                 });   
  36.             } else {   
  37.                 Ext.MessageBox.alert('状态''保存成功!');   
  38.                 win.close();   
  39.             }   
  40.   
  41.             if (node.isLeaf()) {   
  42.                 var root = node.getOwnerTree().root;   
  43.                 root.reload();   
  44.                 root.expand(truetrue);   
  45.             } else {   
  46.                 var root = node.getOwnerTree().root;   
  47.                 root.reload();   
  48.                 root.expand(truetrue);   
  49.             }   
  50.         },   
  51.         failure : function() {   
  52.             Ext.MessageBox.alert('状态''保存失败!');   
  53.             if (node.isLeaf()) {   
  54.                 var root = node.getOwnerTree().root;   
  55.                 root.reload();   
  56.                 root.expand(truetrue);   
  57.             } else {   
  58.                 var root = node.getOwnerTree().root;   
  59.                 root.reload();   
  60.                 root.expand(truetrue);   
  61.             }   
  62.         }   
  63.   
  64.     });   
  65. }   
  66. // 修改form   
  67. function updateForm(node, id, title, win, requestUrl, value, isUpdate) {   
  68.     var form0 = new Ext.FormPanel({   
  69.         id : id,   
  70.         labelWidth : 75// label settings here cascade unless overridden   
  71.         frame : true,   
  72.         title : title,   
  73.         bodyStyle : 'padding:5px 5px 0',   
  74.         width : 350,   
  75.         defaults : {   
  76.             width : 230  
  77.         }   
  78.   
  79.     });   
  80.     var nameField = createField('章节名称''createItemText' + id + node.id,   
  81.             'name', value);   
  82.   
  83.     form0.add(nameField);   
  84.     form0.addButton({   
  85.         text : '保存',   
  86.         handler : function() {   
  87.             saveHandler(win, requestUrl, node, form0, isUpdate);   
  88.         }   
  89.     });   
  90.     return form0;   
  91. }   
  92. // 创建form   
  93. function createForm(node, id, title, win, requestUrl, value, isUpdate) {   
  94.     var form0 = new Ext.FormPanel({   
  95.         id : id,   
  96.         labelWidth : 75// label settings here cascade unless overridden   
  97.         frame : true,   
  98.         title : title,   
  99.         bodyStyle : 'padding:5px 5px 0',   
  100.         width : 500  
  101.             // defaults : {   
  102.             // width : 230   
  103.             // }   
  104.   
  105.     });   
  106.     var nameField = createField('章节名称''createItemText' + id + node.id,   
  107.             'name', value);   
  108.     var unitField = createField('组织名称''createItemText' + id + node.id,   
  109.             'unit', value);   
  110.     var areaField = new Ext.form.TextArea({   
  111.         fieldLabel : '章节编辑',   
  112.         // width:980,   
  113.         // x:400,   
  114.         // y:400,   
  115.         // itemCls:'all-field',   
  116.         // clearCls:'allow-float',   
  117.         // allowBlank:true,   
  118.         // style:"width:100px;height:60px;",   
  119.         // autocomplete: "off",   
  120.         // height:400,   
  121.         height : 400,   
  122.         width : 500,   
  123.         grow : false,   
  124.         name : 'sectionText'  
  125.     });   
  126.     form0.add(nameField);   
  127.     form0.add(unitField);   
  128.     form0.add(areaField);   
  129.     form0.addButton({   
  130.         text : '保存',   
  131.         handler : function() {   
  132.             saveHandler(win, requestUrl, node, form0, isUpdate);   
  133.         }   
  134.     });   
  135.     return form0;   
  136. }   
  137. // 编辑form   
  138. function editorForm(node, id, title, win, requestUrl, value, isUpdate) {   
  139.     var form0 = new Ext.FormPanel({   
  140.         id : id,   
  141.         labelWidth : 75// label settings here cascade unless overridden   
  142.         frame : true,   
  143.         title : title,   
  144.         bodyStyle : 'padding:5px 5px 0',   
  145.         width : 500,   
  146.         // defaults : {   
  147.         // width : 1230   
  148.         // },   
  149.         reader : new Ext.data.JsonReader({   
  150.             root : 'list',   
  151.             fields : [{   
  152.                 name : 'sectionText'  
  153.             }]   
  154.         })   
  155.   
  156.     });   
  157.     // var   
  158.     // nameField=createField('章节名称','createItemText'+id+node.id,'sectionText',value   
  159.     // );   
  160.     var nameField = new Ext.form.TextArea({   
  161.         fieldLabel : '章节编辑',   
  162.         grow : false,   
  163.         // inputType : 'textarea',   
  164.         height : 450,   
  165.         width : 500,   
  166.         // labelWidth : 1000,   
  167.         // growMin : 5,   
  168.         // labelStyle : 'width:1000px;height:1000px',   
  169.         // growMax:true,   
  170.         // width:980,   
  171.         // x:400,   
  172.         // y:400,   
  173.         // itemCls:'all-field',   
  174.         // clearCls:'allow-float',   
  175.         // allowBlank:false,   
  176.   
  177.         // style:"width:300px;overflow-y:visible",   
  178.         name : 'sectionText'  
  179.     });   
  180.     form0.add(nameField);   
  181.     form0.addButton({   
  182.         text : '保存',   
  183.         handler : function() {   
  184.             saveHandler(win, requestUrl, node, form0, isUpdate);   
  185.         }   
  186.     });   
  187.     var id = node.id;   
  188.     form0.getForm().load({   
  189.         url : '/getSectionText/?id=' + id,   
  190.         waitMsg : 'Loading'  
  191.     });   
  192.     return form0;   
  193. }   
  194.   
  195. // 2 创建 tab panel   
  196. function createTabPanel(node, e, type, win) {   
  197.   
  198.     var createUrl = '/createSection/?id=' + node.attributes.id;   
  199.     var updateUrl = '/updateSection/?id=' + node.attributes.id;   
  200.     var editorUrl = '/editorSection/?id=' + node.attributes.id;   
  201.   
  202.     var panel = new Ext.TabPanel({   
  203.         // el: 'hello-tabs',   
  204.         autoTabs : true,   
  205.         activeTab : 0,   
  206.         deferredRender : false,   
  207.         border : false  
  208.     });   
  209.   
  210.     var form0 = createForm(node, 'form0' + node.id, '新建子章节', win, createUrl,   
  211.             ''false);   
  212.     var form1 = updateForm(node, 'form1' + node.id, '修改章节名称', win, updateUrl,   
  213.             node.text, true);   
  214.     var form2 = editorForm(node, 'form2' + node.id, '章节编辑', win, editorUrl, '',   
  215.             true);   
  216.     panel.add(form2);   
  217.     panel.add(form0);   
  218.     panel.add(form1);   
  219.   
  220.     return panel;   
  221. }   
  222. // 组装   
  223. function itemManage(node, e) {   
  224.     var type = "电子书章节管理"  
  225.     // create the window on the first click and reuse on subsequent clicks   
  226.     var win = Ext.getCmp('win' + type + node.id);   
  227.     if (!win) {   
  228.         win = new Ext.Window({   
  229.             title : type,   
  230.             id : 'win' + type + node.id,   
  231.             layout : 'fit',   
  232.             maximizable : true,// 最大化   
  233.             collapsible : true,// 可折叠   
  234.             width : 800,   
  235.             height : 600,   
  236.             // closeAction:'hide',   
  237.             plain : true  
  238.         });   
  239.         var tab = createTabPanel(node, e, type, win);   
  240.         win.add(tab);   
  241.     }   
  242.     win.show();   
  243.   
  244. }   
  245.   
  246. // grid.addListener('rowdbclick',function(){   
  247. // alert("123");   
  248. // });   
  249. Ext.ux.makeMenu = function(node, event, title, requestUrl) {   
  250.     var rightClick = new Ext.menu.Menu({   
  251.         id : 'rightClickCont' + node.id,   
  252.         items : [{   
  253.             id : node.id + "menu",   
  254.             text : title,   
  255.             // 增加菜单点击事件   
  256.             handler : function() {   
  257.                 Ext.Ajax.request({   
  258.                     url : requestUrl,   
  259.                     params : {   
  260.   
  261.                     },   
  262.                     success : function(response, request) {   
  263.                         Ext.MessageBox.alert("状态""删除成功", function() {   
  264.                         });   
  265.                         if (node.isLeaf()) {   
  266.                             var root = node.getOwnerTree().root;   
  267.                             root.reload();   
  268.                             root.expand(truetrue);   
  269.                         } else {   
  270.                             var root = node.getOwnerTree().root;   
  271.                             root.reload();   
  272.                             root.expand(truetrue);   
  273.                         }   
  274.                     },   
  275.                     failure : function() {   
  276.                         // Ext.MessageBox.hide();   
  277.                         Ext.MessageBox.alert('状态''删除失败!');   
  278.                         if (node.isLeaf()) {   
  279.                             var root = node.getOwnerTree().root;   
  280.                             root.reload();   
  281.                             root.expand(truetrue);   
  282.                         } else {   
  283.                             var root = node.getOwnerTree().root;   
  284.                             root.reload();   
  285.                             root.expand(truetrue);   
  286.                         }   
  287.                     }   
  288.                 });   
  289.             }   
  290.         }]   
  291.     });   
  292.     event.preventDefault();   
  293.     rightClick.showAt(event.getXY());// 取得鼠标点击坐标,展示菜单   
  294.   
  295. };  

你可能感兴趣的:(用Ext做的后台操作(包括,增,删,改,查)和一个异步加载的Ext树)