(function (window) { var _TitleName = "", ADGRSelectPopuper = function (SelectType, Result, CallBack, TitleName, Option, IsSingle) { return new ADGRSelectPopuper.Fn.init(SelectType, Result, CallBack, TitleName, Option, IsSingle); }; ADGRSelectPopuper.Fn = ADGRSelectPopuper.prototype = { // 原型鍊修正 constructor: ADGRSelectPopuper, init: function (SelectType, Result, CallBack, TitleName, Option, IsSingle) { var PopuperChangeMonitor = function () { var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver, observer = new MutationObserver( function (mutations) { mutations.forEach( function (mutation) { var $Iframe = $("#_SelectRuleCom iframe", mutation.target), $Window = null, IntervalID = 0; if (!$Iframe[0]) { return; } observer.disconnect(); $Window = $Iframe[0].contentWindow; IntervalID = setInterval( function () { if ($Window.ADGRSelect) { clearInterval(IntervalID); $Window.ADGRSelect(SelectType, Result, CallBack, Option, IsSingle, ADGRSelectPopuper.Fn, $Iframe.contents()).Call(); } } , 100); } ); } ); observer.observe(top.$("#popuper")[0], { childList: true, attributes: false, characterData: true, subtree: true }); } _TitleName = TitleName; PopuperChangeMonitor(); return this; }, /** * @description 開啟ADGRSelectPopuper * @return {ADGRSelectPopuper} */ Call: function (View) { top.$popuper.addCt({ headingText: _TitleName, contentType: 'iframe', contentData: (View == 'AuthorizedComponent' ? '/_RoleSelect/AuthorizedComponent' :'/_RoleSelect/Component' ), uuid: '_SelectRuleCom' }); return this; }, /** * @description 關閉ADGRSelectPopuper * @return {ADGRSelectPopuper} */ Close: function () { top.$popuper.rmCt(0); }, } /** * @description Ajax查詢資料 * @param {array} QueryData 要查詢的數據([{SN=1, Type='A'}]) * @param {function} CallBack Ajax回調函數 * @return {array} */ ADGRSelectPopuper.AjaxQuery = function (QueryData, CallBack) { var AjaxResult = [], DataHandle = function (Data, AjaxResult) { for (var x in Data) { switch (x) { case 'SN' : case 'Type': case 'Name': break; default : AjaxResult[0][x] = Data[x]; break; } } return AjaxResult; }, AjaxGetContent = function (Data, SN, Type, CallBack) { var AjaxRequest = null, AjaxData = { url: "", data: { Type: Type }, type: "post", cache: false, async: false, dataType: "json", success: function (ResponseData) { AjaxResult = AjaxResult.concat(ResponseData) QueryDataLength--; if (QueryDataLength == 0 && typeof (CallBack) == "function") { CallBack.call(ADGRSelectPopuper, DataHandle(Data, AjaxResult)) } } } switch (Type) { // 查詢人員 case "A": AjaxData = $.extend(AjaxData, { url: "/_RoleSelect/QueryPeople", data: { SN: SN } }); break; // 查詢單位 case "D": AjaxData = $.extend(AjaxData, { url: "/_RoleSelect/QueryDept", data: { SN: SN } }); break; // 查詢群組 case "G": AjaxData = $.extend(AjaxData, { url: "/_RoleSelect/QueryGroup", data: { SN: SN } }); break; // 查詢角色 case "R": AjaxData = $.extend(AjaxData, { url: "/_RoleSelect/QueryRole", data: { SN: SN } }); break; } AjaxRequest = $.ajax(AjaxData); }; if (typeof(QueryData) == "string") { eval("QueryData= " + QueryData + ";"); }; if ($.isArray(QueryData)) { QueryDataLength = QueryData.length; } else { QueryData = []; QueryDataLength = 0; } QueryData.forEach(function(Data) { if (!Data.SN || !Data.Type) { return; } AjaxGetContent(Data, Data.SN, Data.Type, CallBack); }) } ADGRSelectPopuper.Remark = function () { console.log('初始化ADGRSelect組件 => ADGRSelectPopuper\(要啟用的ADGRSelect類型{array}, 預設選取值{array || json\'s string}, 回調函數{function || object}, 標題文字{string}, 擴展參數{object}, 是否單選{boolean}\)\n\n開啟組件 => .Call\(\)\n\n關閉組件 => .Close\(\)\n\n取得選取值 => .Get\(\)\n\n擴展參數 => {\n\t//自訂頁簽\n\tCPTag: [\n\t\t{\n\t\t\tType: "類型代號",\n\t\t\tTitle: "頁簽名稱",\n\t\t\tClass: "頁簽ICON樣式",\n\t\t\tData: [\n\t\t\t\t{Type: "類型代號", Name: "資料名稱", SN: "資料SN" },\n\t\t\t\t{Type: "類型代號1", Name: "資料名稱1", SN: "資料SN1" },\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\tType: "類型代號1",\n\t\t\tTitle: "頁簽名稱1",\n\t\t\tClass: "頁簽ICON樣式1",\n\t\t\tData: [\n\t\t\t\t{Type: "類型代號", Name: "資料名稱", SN: "資料SN" },\n\t\t\t\t{Type: "類型代號1", Name: "資料名稱1", SN: "資料SN1" },\n\t\t\t]\n\t\t}\n\t]\n}') } ADGRSelectPopuper.toIcon = function (Context, AttrValue) { var InsertHtml = "", $Context = $(Context), $Authorize = null; if (typeof(AttrValue) == "string") { eval("var Data = " + AttrValue + ";"); } else { Data = AttrValue; } if (typeof(Data) == "object" && $(Context)[0]) { $Authoriz = $Context.siblings("div.cp.selecter.authorize"); $Authoriz = $Authoriz[0] ? $Authoriz : $("
"); $Authoriz.empty(); for (var x in Data) { if (Data[x]["SN"]==0) continue; switch (Data[x]["Type"]) { case "A": InsertHtml += "
"; break; case "D": InsertHtml += "
"; break; case "G": InsertHtml += "
"; break; case "R": InsertHtml += "
"; break; case "System": InsertHtml += "
"; break; default: InsertHtml += "
"; break; } if (Data[x]["Link"]) { Data[x]["LinkTitle"] = Data[x]["LinkTitle"] || ""; Data[x]["CallBack"] = Data[x]["CallBack"] || ""; if (Data[x]["LinkMode"] > 0) { InsertHtml += '' + Data[x]["Name"] + '
'; } else { InsertHtml += '' + Data[x]["Name"] + '
'; } } else { InsertHtml += '' + Data[x]["Name"] + '
'; } } $Authoriz.html(InsertHtml); $(Context).hide().after($Authoriz); } } // 原型鍊傳遞 ADGRSelectPopuper.Fn.init.prototype = ADGRSelectPopuper.Fn; window.ADGRSelectPopuper = ADGRSelectPopuper; })(window);