ExtJS4 TreePanel實例

Adsitepopedomform.js代碼  收藏代碼
  1. Ext.app.AdSitePopedomForm = Ext.extend(Ext.Window,  
  2. {  
  3.     title: '網站功能授權',  
  4.     id: 'am-adsitepopedom',  
  5.     autoScroll: true,  
  6.     xtype: "window",  
  7.     width: 400,  
  8.     height: 540,  
  9.     layout: "absolute",  
  10.     modal: true,  
  11.     initComponent: function () {  
  12.         var userId = Ext.getCmp("am-usergrid").userId;  
  13.         var mytree = new Ext.tree.TreePanel({  
  14.             id: 'ppdTree',  
  15.             x: 5,  
  16.             y: 5,  
  17.             width: 378,  
  18.             height: 470,  
  19.             useArrows: true,  
  20.             autoScroll: true,  
  21.             animate: true,  
  22.             enableDD: true,  
  23.             containerScroll: true,  
  24.             store: new Ext.data.TreeStore  
  25.                         ({  
  26.                             proxy:  
  27.                             {  
  28.                                 type: 'ajax',  
  29.                                 url: 'data/User/UserPopedom.aspx?parameter=ppdTree&userId=' + userId  
  30.                             },  
  31.                             root:  
  32.                             {  
  33.                                 id: 0,  
  34.                                 text: "選擇權限",  
  35.                                 leaf: false,  
  36.                                 expandable: true,  
  37.                                 expanded: true  
  38.                             },  
  39.                             sorters: [  
  40.                             {  
  41.                                 property: 'leaf',  
  42.                                 direction: 'ASC'  
  43.                             },  
  44.                             {  
  45.                                 property: 'text',  
  46.                                 direction: 'ASC'  
  47.                             }]  
  48.                         })  
  49.         });  
  50.         mytree.on('checkchange', function (node, checked) {  
  51.             node.expand();  
  52.             node.checked = checked;  
  53.             node.eachChild(function (child) {  
  54.                 child.set('checked', checked);  
  55.                 child.fireEvent('checkchange', child, checked);  
  56.             });  
  57.         }, mytree);  
  58.   
  59.   
  60.   
  61.         this.items =  
  62.         [  
  63.            mytree,  
  64.             {  
  65.                 xtype: "textfield",  
  66.                 hidden: true,  
  67.                 name: "Id",  
  68.                 id: "Id",  
  69.                 value: userId  
  70.             }  
  71.          ];  
  72.         this.buttons =  
  73.         [  
  74.            {  
  75.                text: '確認',  
  76.                xtype: 'button',  
  77.                width: 30,  
  78.                handler: function () {  
  79.                    var b = mytree.getChecked();  
  80.                    var checkids = new Array; // 存放選中id的  數組    
  81.                    for (var i = 0; i < b.length; i++) {  
  82.                        if (b.length == 1) {  
  83.                            checkids = b[i].data.id;  
  84.                        }  
  85.                        else {  
  86.                            if (i < b.length - 1) {  
  87.                                checkids += b[i].data.id + ",";  
  88.                            }  
  89.                            if (i == b.length - 1) {  
  90.                                checkids += b[i].data.id;  
  91.                            }  
  92.                        }  
  93.   
  94.                        // checkid.push(b[i].text); // 添加id到數組    
  95.                    }  
  96.                    Ext.Ajax.request({  
  97.                        url: "data/User/UserPopedom.aspx?parameter=poped",  
  98.                        method: "POST",  
  99.                        params: { ppdIds: checkids, userId: userId }, //發送的參數  
  100.                        success: function (response, option) {  
  101.                            response = Ext.JSON.decode(response.responseText);  
  102.                            if (response.success == true) {  
  103.                                if (response.flag == true) {  
  104.                                    Ext.MessageBox.alert("提示""權限分配成功!");  
  105.   
  106.                                    //關閉當前窗體  
  107.                                    var adpoped = Ext.getCmp("am-adsitepopedom");  
  108.                                    adpoped.close();  
  109.   
  110.                                    //刷新列表  
  111.                                    var adGrid = Ext.getCmp("am-usergrid");  
  112.                                    adGrid.store.load();  
  113.                                }  
  114.                                else {  
  115.                                    Ext.MessageBox.alert("錯誤信息""權限分配失敗!");  
  116.                                }  
  117.                            }  
  118.                            else {  
  119.                                Ext.MessageBox.alert("錯誤信息", response.msg);  
  120.                            }  
  121.                        },  
  122.                        failure: function () {  
  123.                            Ext.Msg.alert("提示""權限分配<br>沒有捕獲到異常");  
  124.                        }  
  125.                    });  
  126.                }  
  127.            },  
  128.             {  
  129.                 text: '取消',  
  130.                 xtype: 'button',  
  131.                 width: 30,  
  132.                 handler: function () {  
  133.                     var windows = Ext.getCmp('am-adsitepopedom');  
  134.                     windows.close();  
  135.                 }  
  136.             }  
  137.         ];  
  138.         Ext.app.AdSitePopedomForm.superclass.initComponent.call(this);  
  139.     }  
  140. });  
 using System;
後臺代碼代碼  收藏代碼
  1. using System.Collections.Generic;  
  2. using System.Linq;  
  3. using System.Web;  
  4. using System.Web.UI;  
  5. using System.Web.UI.WebControls;  
  6. using CtManager.BLL;  
  7. using CtManager.Model;  
  8. using Newtonsoft.Json;  
  9.   
  10. public partial class Data_User_UserPopedom : System.Web.UI.Page  
  11. {  
  12.     protected void Page_Load(object sender, EventArgs e)  
  13.     {  
  14.         if (Request["parameter"] == null)  
  15.         {  
  16.             Response.Write("");  
  17.             return;  
  18.         }  
  19.   
  20.         string parameter = Request["parameter"];  
  21.         if (parameter == "ppdTree") Response.Write(AdvertisingTreePPDData());  
  22.         else if (parameter == "poped") Response.Write(DistributeAuthority());  
  23.         else Response.Write("");  
  24.     }  
  25.     /// <summary>  
  26.     /// 權限分配方法  
  27.     /// </summary>  
  28.     /// <returns></returns>  
  29.     public string DistributeAuthority()  
  30.     {  
  31.         try  
  32.         {  
  33.             if (UserInfoManager.ModifyUserInfoPopedomById(Request["ppdIds"], Request["userId"])) return "{success:true,flag:true}";  
  34.             else return "{success:true,flag:false}";  
  35.         }  
  36.         catch (Exception /*ex*/)  
  37.         {  
  38.             return "{success:true,flag:false}";  
  39.         }  
  40.     }  
  41.   
  42.     /// <summary>  
  43.     /// 廣告位 樹的Json數據源(用於授權 數據加上覆選框) 用戶權限初始化  
  44.     /// </summary>  
  45.     /// <returns></returns>  
  46.     public string AdvertisingTreePPDData()  
  47.     {  
  48.         IList<PopeDom> ppdList = UserInfoManager.CreatePopedomTree(Request["userId"]);  
  49.   
  50.         return JavaScriptConvert.SerializeObject(ppdList).Replace("Mchecked""checked");  
  51.     }  
  52. }  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章