(function (context) { function get() { return $('div.modal[data-visible]'); } function close() { var dialog = get(); dialog.fadeOut(200, function() { $(this).remove(); }); // $('body').unbind('keyup'); $('body').unbind('keydown'); return false; } function escCallback(e) { if (e.keyCode == 27) { close(); } } function JDialog () { this.get = get; this.close = close; this.msgTid = ''; this.escCallback = function(e) { escCallback(e); }; this.setCallback = function(formCallback, dialog) { dialog.find('form').bind('submit', function(e) { var formData = C.parseForm($(this)); formCallback(e, formData); return false; }); }; this.setTitle = function(title, dialog) { dialog.find('h3').text(title); }; this.showMsg = function(msg, dialog, timeout) { this._showMsg(msg, 'success', dialog, timeout); }; this.showErrorMsg = function(msg, dialog, timeout) { this._showMsg(msg, 'error', dialog, timeout); }; this.showLoading = function(msg, dialog) { this.showMsg(msg, dialog, 864000); }; this._showMsg = function(msg, type, dialog, timeout) { dialog.find('.alert').remove(); elem = $(''); elem.insertAfter(dialog.find('h3')); elem.find('.alert-content').html(C.htmlEncode(msg)); if (type == 'error') { elem.removeClass('success').addClass('error'); } else if (type == 'success') { elem.removeClass('error').addClass('success'); } elem.fadeIn(200); if (this.msgTid !== '') { clearTimeout(this.msgTid); } var sec = 5000; if (timeout) { sec = timeout * 1000; } this.msgTid = setTimeout(this.hideMsg, sec); }; this.hideMsg = function() { get().find('div.alert').fadeOut(200, function() { $(this).remove(); }); }; this.setSubmitText = function(text, dialog) { dialog.find('button.primary').text(text); }; this.create = function(html) { var dialog = $(html).attr('data-visible', 1); dialog.find('.modal-content').addClass('vertical-center'); dialog.find('[data-id]').each(function() { var id = $(this).attr('data-id'); $(this).attr('id', id); }); dialog.find('[data-attr-name]').each(function() { var name = $(this).attr('data-attr-name'); $(this).attr('name', name); }); $('body').append(dialog); dialog = this.bindEvent(dialog); return dialog; }; this.bindEvent = function(dialog) { dialog.fadeIn(200); dialog.find('.close').bind('click', this.close); dialog.find('[data-optype="cancel"]').bind('click', this.close); dialog.find('input').focus(UI.removeError); dialog.find('select').focus(UI.removeError); dialog.find('textarea').focus(UI.removeError); dialog.find('input:text').attr('autocomplete', 'off'); dialog.find('input:password').attr('autocomplete', 'off'); $('body').bind('keydown', this.escCallback); // 如果先设置foucus,再将dialog添加到body中,设置focus不会起作用 UI.setFocus(dialog); return dialog; }; this.show = function(html, formCallback) { var dialog = this.create(html); if (formCallback) { this.setCallback(formCallback, dialog); } return dialog; }; this.confirm = function(callback, msg) { var html = ''; var dialog = this.create(html); if (msg) { $('#confirm-msg').html(msg); } if (callback) { dialog.find('form').bind('submit', function(e) { callback(); close(); return false; }); } return dialog; }; this.alert = function(msg) { var html = ''; var dialog = this.create(html); if (msg) { $('#alert-msg').text(msg); } return dialog; }; } context.dialog = new JDialog(); })(UI); (function(context) { function JNotice() { this.show = function(msg, elem, msgstyle){ if (!msgstyle) { msgstyle ='success'; } if (!elem) { elem = $('form').eq(0); } elem.prev('[data-type="form-notice"]').remove(); var div = $(''); div.addClass(msgstyle).html(msg).insertBefore(elem).fadeIn(200); $('.main').scrollTop(0); }; this.success = function(msg, elem) { this.show(msg, elem, 'success'); }; this.error = function(msg, elem) { this.show(msg, elem, 'danger'); }; this.hide = function() { $('[data-type="form-notice"]').fadeOut(0, function() { $(this).remove(); }); }; } context.notice = new JNotice(); })(UI); (function(context) { function JMsg() { this.style = new Array('error', 'success'); this.tid = ''; this.show = function(msg, classIndex, timeout, fadeIn){ this.remove(); if (this.tid !== '') { clearTimeout(this.tid); } var div = $(''); var msgClass = this.style[classIndex]; if (typeof msgClass === 'undefined') { msgClass = this.style[1]; } div.addClass(msgClass); div.find('div').text(msg); $('div.app-body').append(div); if (typeof fadeIn == 'undefined') { fadeIn = 200; } div.fadeIn(fadeIn); var sec = 5000; //参数timeout为信息显示的时间,单位秒 if (timeout) { sec = timeout * 1000; } this.tid = setTimeout(this.hide, sec); }; this.error = function(msg, timeout) { this.show(msg, 0, timeout); }; this.hide = function() { $('div.app-body div.alert').fadeOut(200, function() { $(this).remove(); }); }; this.remove = function() { $('div.app-body div.alert').remove(); }; this.loading = function(msg, fadeIn) { if (typeof msg == 'undefined') { msg = '正在载入数据...'; } this.show(msg, 1, 864000, fadeIn); }; this.loading_show = function(msg){ this.remove(); if(this.tid !== '') { clearTimeout(this.tid); } if(typeof(msg) == 'undefined') { msg = '正在载入数据...'; } var div = $('
'); div.find('.msgText').html(msg); $('body').append(div); }; this.hideLoading = function(){ $('div.app-body div.alert').fadeOut(200, function() { $(this).remove(); }); }; } context.msg = new JMsg(); })(UI); (function(context) { var aData = [], aSearch = '', aSearchKey = '', aValueKey = 'id', aNameKey = 'uname', aFilter = [], aFilterKey = '', aFilterValueKey = '', aFilterNameKey = '', aFilterTitle = '', aTreeSetting = {}, bData = [], orderKey = 'id', nameFormatter = null, dialogElem = null, treeObj = null, title = '', bTitle = '', bItemMulti = true; function initSetting() { aData = []; aSearch = ''; aSearchKey = ''; aValueKey = 'id'; aNameKey = 'uname'; aFilter = []; aFilterKey = ''; aFilterValueKey = ''; aFilterNameKey = ''; aFilterTitle = ''; aTreeSetting = {}; bData = []; orderKey = 'id'; nameFormatter = null; dialogElem = null; treeObj = null; title = ''; bTitle = ''; bItemMulti = true; } function orderData(rows) { var data = []; for (var i in rows) { data[rows[i][orderKey] + '_' + rows[i][aValueKey]] = rows[i]; } return data; } function treeSetting() { var setting = { data: { simpleData: { enable: true, idKey: 'id', pIdKey: 'pid', rootPid: 4 }, key: { name: 'domain_name' }, keep: { parent: true } }, callback: { onClick: function(event, treeid, treeNode) { } } }; return setting; } function getViewA() { return dialogElem.find('[name="view-a"]'); } function getViewB() { return dialogElem.find('[name="view-b"]'); } function getAFliterValue() { return dialogElem.find('[name="filter-a"]').attr('data-value'); } function setAFilterName(name) { dialogElem.find('[name="filter-a"]').html(C.htmlEncode(name)); } function getViewBValues() { var elem = getViewB().find('a'); var values = []; for (var i = 0, n = elem.length; i < n; i ++) { values.push(elem.eq(i).attr('data-value')); } return values; } function aItemToB(elem) { var uqid = elem.attr('uqid'); getViewB().append(elem.parent()); bData[uqid] = aData[uqid]; aData[uqid] = null; } function bItemToA(elem) { var uqid = elem.attr('uqid'); if (String(bData[uqid][aFilterKey]) === getAFliterValue()) { getViewA().append(elem.parent()); } else { elem.parent().remove(); } aData[uqid] = bData[uqid]; bData[uqid] = null; } var MsDialog = function() {}; MsDialog.prototype.show = function(settings, events) { initSetting(); settings = settings || {}; aSearchKey = settings.aSearchKey || []; aValueKey = settings.aValueKey || 'id'; aNameKey = settings.aNameKey || 'uname'; aFilter = settings.aFilter || []; aFilterKey = settings.aFilterKey || ''; aFilterValueKey = settings.aFilterValueKey || ''; aFilterNameKey = settings.aFilterNameKey || ''; aFilterTitle = settings.aFilterTitle || ''; aTreeSetting = settings.aTreeSetting || treeSetting(); orderKey = settings.orderKey || 'id'; nameFormatter = settings.nameFormatter || null; title = settings.title || ''; bTitle = settings.bTitle || ''; if (typeof settings.bItemMulti !== 'undefined') { bItemMulti = settings.bItemMulti; } else { bItemMulti = true; } if (!settings.html) { settings.html = '\ '; } dialogElem = UI.dialog.create(settings.html); if (title) { dialogElem.find('h3').html(title); } if (aFilterTitle) { setAFilterName(aFilterTitle); } if (bTitle) { dialogElem.find('[name="btitle"]').html(C.htmlEncode(bTitle)); } var _this = this; if (aFilter.length) { _this.showAFilter(); } events = events || {}; $('form', dialogElem).submit(function() { if (events.formCallback) { events.formCallback(getViewBValues()); } return false; }); getViewA().bind('click', _this.viewAClick); getViewB().bind('click', _this.viewBClick); return dialogElem; }; MsDialog.prototype.showAFilter = function() { if (!aFilter) { return; } for (var i in aFilter) { aFilter[i]['isParent'] = true; } var _this = this; aTreeSetting.callback.onClick = function(event, treeid, treeNode) { _this.selectAFilter(treeNode.id); dialogElem.find('[name="filter-a"]').attr('data-value', treeNode.id); setAFilterName(treeNode[aTreeSetting.data.key.name]); }; treeObj = $.fn.zTree.init(dialogElem.find('div[name="ztree"]'), aTreeSetting, aFilter); // var nodes = treeObj.getNodes(); // treeObj.expandNode(nodes[0]); treeObj.expandAll(true); }; MsDialog.prototype.selectAFilter = function(value) { var res = {}; for (var i in aData) { if (!aData[i]) { continue; } if (aData[i][aFilterKey] == value) { res[i] = aData[i]; } } this.displayViewData(getViewA(), res); }; MsDialog.prototype.setAData = function(data) { aData = orderData(data); for (var i in aData) { if (bData[i]) { aData[i] = null; } } }; MsDialog.prototype.setBData = function(data) { bData = orderData(data); for (var i in aData) { if (bData[i]) { aData[i] = null; } } this.displayViewData(dialogElem.find('ul[name="view-b"]'), bData); }; MsDialog.prototype.displayViewData = function(container, data) { var html = ''; if (nameFormatter) { for (var i in data) { html += '
  • ' + C.htmlEncode(nameFormatter(data[i])) + '
  • '; } } else { for (var i in data) { html += '
  • ' + C.htmlEncode(data[i][aNameKey]) + '
  • '; } } container.empty().html(html); }; MsDialog.prototype.viewAClick = function(e) { var elem = $(e.target); if (!elem.attr('uqid')) { return false; } // B框不能多选 if (bItemMulti !== true) { var bItems = getViewB().find('*[uqid]'); for (var i = 0, n = bItems.length; i < n; i ++) { bItemToA(bItems.eq(i)); } } aItemToB(elem); return false; }; MsDialog.prototype.viewBClick = function(e) { var elem = $(e.target); if (!elem.attr('uqid')) { return false; } bItemToA(elem); return false; }; context.msDialog = new MsDialog(); })(UI); (function(UI) { var dialogElem = null, theads = ['主机名称', '主机IP', '主机帐户', '协议'], placeholder = '', title = '', treeData = [], treeValueKey = 'id', treeNameKey = 'domain_name', treeSetting = { data: { simpleData: { enable: true, idKey: 'id', pIdKey: 'pid', rootPid: 4 }, key: { name: 'domain_name' }, keep: { parent: true } }, callback: { onClick: function(event, treeid, treeNode) { } } }, curPage = 1, count = '', callback = { getData: null, showData: showAccount, event1: null }; function initSetting() { dialogElem = null; theads = ['主机名称', '主机IP', '主机帐户', '协议']; placeholder = ''; title = ''; treeData = []; treeValueKey = 'id'; treeNameKey = 'domain_name'; treeSetting = { data: { simpleData: { enable: true, idKey: 'id', pIdKey: 'pid', rootPid: 4 }, key: { name: 'domain_name' }, keep: { parent: true } }, callback: { onClick: function(event, treeid, treeNode) { } } }; curPage = 1; count = ''; callback = { getData: null, showData: showAccount, event1: null }; } function setSetting(settings) { if (settings.callback.getData) { callback.getData = settings.callback.getData; } if (settings.callback.event1) { callback.event1 = settings.callback.event1; } if (settings.treeData) { treeData = settings.treeData; } if (settings.treeSetting) { treeSetting = settings.treeSetting; } if (settings.title) { title = settings.title; } } function getData() { var params = {}; params.treeValue = getTreeValue(); params.search = C.getValue($('input[name="search"]'), dialogElem); params.offset = UI.listOffset(curPage); params.limit = UI.listLimit(); params.count = count; var msg = callback.getData(params); var table = $('table', dialogElem); callback.showData(msg[0], table); if (!msg[0].length) { UI.showEmptyMsg(table); } else { UI.removeEmptyMsg(table); } count = msg[1]; $('div[data-name="table-pagination"]').uPagination({ totalPage: UI.listTotalPage(msg[1]), curPage: curPage, callback: getDataByPage }); } function getDataByPage(pageNum) { curPage = pageNum; getData(); } function showAccount(rows, container) { var html = ''; for (var i in rows) { html += ''; html += '' + UI.checkerHtml() + ''; html += '' + C.htmlEncode(rows[i].astname) + ''; html += '' + C.htmlEncode(rows[i].ip) + ''; html += '' + C.htmlEncode(rows[i].acctname) + ''; html += '' + C.htmlEncode(rows[i].prot) + ''; html += ''; } container.find('tbody').html(html); } function getTreeValue() { var value = $('[data-name="tree-value"]', dialogElem).attr('data-value'); return value; } function setTreeValue(value, name) { $('[data-name="tree-value"]', dialogElem).attr('data-value', value).html(C.htmlEncode(name)); } var TableDialog = function() {}; TableDialog.prototype.show = function(settings) { initSetting(); setSetting(settings); if (!settings.html) { settings.html = '\ '; } dialogElem = UI.dialog.create(settings.html); if (title) { dialogElem.find('h3').html(title); } for (var i in treeData) { treeData[i]['isParent'] = true; } treeSetting.callback.onClick = function(event, treeid, treeNode) { setTreeValue(treeNode[treeValueKey], treeNode[treeNameKey]); curPage = 1; count = ''; getData(); } var treeObj = $.fn.zTree.init($('div[data-name="dialog-tree"]', dialogElem), treeSetting, treeData); var nodes = treeObj.getNodes(); treeObj.expandNode(nodes[0]); getData(); dialogElem.find('form').submit(function() { curPage = 1; count = ''; getData(); return false; }); dialogElem.find('div[data-name="optype1"]').click(function() { if (callback.event1) { var values = UI.tableCheckedValue(dialogElem.find("table")); var trs = UI.tableCheckedTr(dialogElem.find("table")); if (values.length) { callback.event1(values, trs); } } }); return dialogElem; }; UI.tDialog = new TableDialog(); })(UI); (function(UI) { var TableDialog = function(settings) { this.type = ''; this.elem = null; this.deptSelect = null; this.roleSelect = null; this.authmodeSelect = null; this.title = ''; this.enableMulti = false; //是否支持多选 this.enableRoleSelect = true; this.curPage = 1; this.count = ''; this.callback = { getData: null, showData: null, submit: null }; this.keys = { id: 'id' } this.roles = null; if (typeof settings.roles !== 'undefined') { this.roles = settings.roles; } this.data = []; this.depts = null; settings = settings || {}; if (settings.callback) { if (settings.callback.getData) { this.callback.getData = settings.callback.getData; } if (settings.callback.showData) { this.callback.showData = settings.callback.showData; } if (settings.callback.submit) { this.callback.submit = settings.callback.submit; } } if (settings.keys) { if (settings.keys.id) { this.keys.id = settings.keys.id; } } if (settings.title) { this.title = settings.title; } if (typeof settings.enableMulti !== 'undefined') { this.enableMulti = settings.enableMulti; } if (typeof settings.enableRoleSelect !== 'undefined') { this.enableRoleSelect = settings.enableRoleSelect; } if (settings.depts) { this.depts = settings.depts; } var html = ''; this.elem = UI.dialog.create(html); if ($('#_dept_status').val() !== '1') { this.elem.find('[data-name="filter-dept"]').hide(); } if (this.title) { this.elem.find('h3').html(this.title); } if (this.enableMulti) { this.elem.find('.modal-footer').remove(); } else { this.elem.find('[data-name="multi-toolbar"]').remove(); } var _this = this; function reloadData() { _this.curPage = 1; _this.count = ''; _this.getData(); } _this.deptSelect = UI.deptDropTree(_this.elem.find('[data-name="filter-dept"]'), {size: 'full', callback: reloadData, data: _this.depts}); if (_this.enableRoleSelect) { _this.roleSelect = UI.roleDropSelect(_this.elem.find('[data-name="filter-role"]'), {size: 'full', data: _this.roles, callback: reloadData}); } _this.authmodeSelect = UI.authmodeSelect(_this.elem.find('[data-name="filter-authmode"]'), {size: 'full',callback: reloadData}); _this.elem.find('[data-name="form-search-user"]').submit(function() { reloadData(); return false; }); _this.elem.find('[data-name="clear-filter"]').click(function() { _this.elem.find('[data-name="searchUser"]').val(''); _this.deptSelect = UI.deptDropTree(_this.elem.find('[data-name="filter-dept"]'), {size: 'full', callback: reloadData, data: _this.depts}); if (_this.enableRoleSelect) { _this.roleSelect = UI.roleDropSelect(_this.elem.find('[data-name="filter-role"]'), {size: 'full', data: _this.roles, callback: reloadData}); } _this.authmodeSelect = UI.authmodeSelect(_this.elem.find('[data-name="filter-authmode"]'), {size: 'full',callback: reloadData}); reloadData(); }); _this.getData(); _this.elem.find('[data-optype="submit"]').click(function() { if (_this.callback.submit) { var values = []; if (_this.enableMulti) { // 多选 values = UI.tableCheckedValue(_this.elem.find("table")); } else { // 单选 values = UI.tableRadioValue(_this.elem.find("table")); } if (values.length) { var users = []; for (var i in values) { users.push(_this.data[values[i]]); } _this.callback.submit(users); _this.close(); } else { UI.dialog.showErrorMsg('请选择用户', _this.elem); } } return false; }); }; TableDialog.prototype.getData = function() { var _this = this; var params = {}; params.search = C.getValue(_this.elem.find('[data-name="searchUser"]')); params.deptid = _this.deptSelect ? _this.deptSelect.get()[0] : ''; params.roleid = _this.roleSelect ? _this.roleSelect.get()[0] : ''; params.authmode = _this.authmodeSelect ? _this.authmodeSelect.get()[0] : ''; params.offset = UI.listOffset(_this.curPage); params.limit = UI.listLimit(); params.count = _this.count; var getData = _this.getDataDefault; if (_this.callback.getData) { getData = _this.callback.getData; } var msg = getData(params); _this.data = {}; for (var i in msg[0]) { _this.data[String(msg[0][i]['id'])] = msg[0][i]; } var table = $('table', _this.elem); if (_this.callback.showData) { _this.callback.showData(msg[0], table); UI.resetContainer(table.siblings('.toolbar')); } else { _this.showUserList(msg[0], table); UI.resetContainer(table.siblings('.toolbar')); } if (!msg[0].length) { var msg1 = '暂无用户数据'; var msg2 = '创建用户'; var url = '/index.php/user/user'; UI.showEmptyMsg(table, UI.msgFormatter(msg1, msg2, url)); } else { UI.removeEmptyMsg(table); } _this.count = msg[1]; $('[data-name="pagination"]', _this.elem).uPagination({ totalPage: UI.listTotalPage(msg[1]), curPage: _this.curPage, callback: function(pageNum) { _this.curPage = pageNum; _this.getData(); } }); }; TableDialog.prototype.getDataDefault = function(params) { var res = AC.getObjectFromUrl('/index.php/user/user/user_list_my', params, [[], 0]); return res; }; TableDialog.prototype.showUserList = function(rows, container) { var html = ''; for (var i in rows) { html += ''; if (this.enableMulti) { html += '' + UI.checkerHtml() + ''; } else { html += '' + UI.radioHtml(rows[i].id, 'tableuser') + ''; } html += '' + C.htmlEncode(rows[i].uname) + '' + C.htmlEncode(rows[i].name) + ''; html += '' + C.htmlEncode(rows[i].rolename) + ''; html += '' + AC.getUserAuthmodeNameByValue(rows[i].authmode) + ''; if ($('#_dept_status').val() === '1') { html += '' + C.htmlEncode(rows[i].deptname) + ''; } else { html += '' + C.htmlEncode(rows[i].deptname) + ''; } html += ''; } container.find('tbody').html(html); }; TableDialog.prototype.close = function() { UI.dialog.close(); }; UI.userTDialog = function(settings) { var dialog = new TableDialog(settings); return dialog; }; })(UI); (function(UI) { var AccountDialog = function(settings) { this.elem = null; this.vpcSelect = null; this.deptSelect = null; this.protSelect = null; this.protSelectData = null; this.typeSelect = null; this.title = ''; this.enableMulti = true; //是否支持多选 this.showAccoutTypeSelect = false;//是否支持帐户类型选择 this.curPage = 1; this.count = ''; this.callback = { getData: null, showData: null, submit: null }; this.keys = { id: 'id' } this.depts = null; this.data = []; settings = settings || {}; if (settings.callback) { if (settings.callback.getData) { this.callback.getData = settings.callback.getData; } if (settings.callback.showData) { this.callback.showData = settings.callback.showData; } if (settings.callback.submit) { this.callback.submit = settings.callback.submit; } } if (settings.keys) { if (settings.keys.id) { this.keys.id = settings.keys.id; } } if (settings.title) { this.title = settings.title; } if (typeof settings.enableMulti !== 'undefined') { this.enableMulti = settings.enableMulti; } if (settings.depts) { this.depts = settings.depts; } if (settings.protSelectData) { this.protSelectData = settings.protSelectData; } if (typeof settings.showAccoutTypeSelect !== 'undefined') { this.showAccoutTypeSelect = settings.showAccoutTypeSelect; } var html = ''; this.elem = UI.dialog.create(html); if ($('#_dept_status').val() !== '1') { this.elem.find('[data-name="filter-dept"]').hide(); } if (!this.showAccoutTypeSelect) { this.elem.find('[data-name="filter-type"]').hide(); } if (this.title) { this.elem.find('h3').html(this.title); } var _this = this; function reloadData() { _this.curPage = 1; _this.count = ''; _this.getData(); } if ($('#_feature_vpc').val() === '1') { _this.vpcSelect = UI.assetVpcSelect(_this.elem.find('[data-name="filter-vpc"]'), {size: 'full', callback: reloadData}); } _this.deptSelect = UI.deptDropTree(_this.elem.find('[data-name="filter-dept"]'), {size: 'full', callback: reloadData, data: _this.depts}); _this.protSelect = UI.protSelect(_this.elem.find('[data-name="filter-prot"]'), {size: 'full', protids: _this.protSelectData, callback: reloadData}); _this.typeSelect = UI.accountTypeSelect(_this.elem.find('[data-name="filter-type"]'), {size: 'full', callback: reloadData}); _this.elem.find('[data-name="form-search"]').submit(function() { reloadData(); return false; }); _this.elem.find('[data-name="clear-filter"]').click(function() { _this.elem.find('[data-name="search"]').val(''); if ($('#_feature_vpc').val() === '1') { _this.vpcSelect = UI.assetVpcSelect(_this.elem.find('[data-name="filter-vpc"]'), {size: 'full', callback: reloadData}); } _this.deptSelect = UI.deptDropTree(_this.elem.find('[data-name="filter-dept"]'), {size: 'full', callback: reloadData, data: _this.depts}); _this.protSelect = UI.protSelect(_this.elem.find('[data-name="filter-prot"]'), {size: 'full', protids: _this.protSelectData, callback: reloadData}); _this.typeSelect = UI.accountTypeSelect(_this.elem.find('[data-name="filter-type"]'), {size: 'full', callback: reloadData}); reloadData(); }); _this.getData(); _this.elem.find('[data-optype="submit"]').click(function() { if (_this.callback.submit) { var values = []; if (_this.enableMulti) { // 多选 values = UI.tableCheckedValue(_this.elem.find("table")); } else { // 单选 values = UI.tableRadioValue(_this.elem.find("table")); } if (values.length) { var selected = []; for (var i in values) { selected.push(_this.data[values[i]]); } _this.callback.submit(selected); _this.close(); } else { UI.dialog.showErrorMsg('请选择帐户', _this.elem); } } return false; }); }; AccountDialog.prototype.getData = function() { var _this = this; var params = {}; params.search = C.getValue(_this.elem.find('[data-name="search"]')); params.vpcid = _this.vpcSelect ? _this.vpcSelect.get()[0] : ''; params.deptid = _this.deptSelect ? _this.deptSelect.get()[0] : ''; params.protid = _this.protSelect ? _this.protSelect.get()[0] : ''; params.account_type = _this.typeSelect ? _this.typeSelect.get()[0] : ''; params.offset = UI.listOffset(_this.curPage); params.limit = UI.listLimit(); params.count = _this.count; var role = $('#sj89asd0z').val(); var getData = _this.getDataDefault; if (_this.callback.getData) { getData = _this.callback.getData; } var msg = getData(params); _this.data = {}; for (var i in msg[0]) { _this.data[String(msg[0][i]['id'])] = msg[0][i]; } var table = $('table', _this.elem); if (_this.callback.showData) { _this.callback.showData(msg[0], table); UI.resetContainer(table.siblings('.toolbar')); } else { _this.showAccountList(msg[0], table); UI.resetContainer(table.siblings('.toolbar')); } if (!msg[0].length) { if (role == rolesId.superAdmin || role == rolesId.departmentAdmin || role == rolesId.operatorAdmin) { var msg1 = '暂无帐户数据'; var msg2 = '创建主机及帐户'; var url = '/index.php/asset/asset'; UI.showEmptyMsg(table, UI.msgFormatter(msg1, msg2, url)); } } else { UI.removeEmptyMsg(table); } _this.count = msg[1]; $('[data-name="pagination"]', _this.elem).uPagination({ totalPage: UI.listTotalPage(msg[1]), curPage: _this.curPage, callback: function(pageNum) { _this.curPage = pageNum; _this.getData(); } }); }; // AccountDialog.prototype.getDataDefault = function(params) { // }; AccountDialog.prototype.showAccountList = function(rows, container) { var html = ''; for (var i in rows) { html += ''; if (this.enableMulti) { html += '' + UI.checkerHtml() + ''; } else { html += '' + UI.radioHtml(rows[i].id, 'tableaccount') + ''; } html += ''; html += C.htmlEncode(rows[i].ip) + '' + C.htmlEncode(rows[i].astname) + ''; if (rows[i].protid != Globals.oracleProtid) { html += '' + C.htmlEncode(rows[i].acctname); } else { html += '' + C.htmlEncode(rows[i].acctname + ' ' + rows[i].loginattr + ':' + rows[i].servicename + ' as ' + rows[i].role); } if (rows[i].account_type === 'shared') { html += '' + C.htmlEncode(rows[i].shared_name) + ''; } else { html += ''; } if (this.showAccoutTypeSelect) { if (rows[i].account_type === 'private') { html += '主机帐户'; } else if (rows[i].account_type === 'shared') { html += '共享帐户'; } else { html += ''; } } else { html += ''; } html += '' + C.htmlEncode(rows[i].prot) + ''; if ($('#_feature_vpc').val() === '1') { html += '' + C.htmlEncode(rows[i].vpcname) + ''; } if ($('#_dept_status').val() === '1') { html += '' + C.htmlEncode(rows[i].deptname) + ''; } else { html += '' + C.htmlEncode(rows[i].deptname) + ''; } html += ''; } container.find('tbody').html(html); }; AccountDialog.prototype.close = function() { UI.dialog.close(); }; UI.accountTDialog = function(settings) { var dialog = new AccountDialog(settings); return dialog; }; })(UI); (function(UI) { var TableDialog = function(settings) { this.type = 'asset'; // asset || acctgroup || app || ugroup || astgroup || sharedaccount this.elem = null; this.deptSelect = null; this.accountSelect = null; this.protSelect = null; this.osSelect = null; this.authtypeSelect = null; this.title = ''; this.enableMulti = false; //是否支持多选 this.showDept = true; this.curPage = 1; this.count = ''; this.callback = { getData: null, showData: null, submit: null }; this.keys = { id: 'id' } this.depts = null; this.vpcs = null; this.oss = null; this.data = []; settings = settings || {}; if (settings.type) { this.type = settings.type; } if (settings.callback) { if (settings.callback.getData) { this.callback.getData = settings.callback.getData; } if (settings.callback.showData) { this.callback.showData = settings.callback.showData; } if (settings.callback.submit) { this.callback.submit = settings.callback.submit; } } if (settings.keys) { if (settings.keys.id) { this.keys.id = settings.keys.id; } } // set default title if (this.type == 'asset') { this.title = '选择主机'; } else if (this.type == 'acctgroup') { this.title = '选择帐户组'; } else if (this.type == 'app') { this.title = '选择应用'; } else if (this.type == 'ugroup') { this.title = '选择用户组'; } else if (this.type == 'astgroup') { this.title = '选择主机组'; } else if (this.type == 'sharedaccount') { this.title = '选择共享帐户'; } if (settings.title) { this.title = settings.title; } if (typeof settings.enableMulti !== 'undefined') { this.enableMulti = settings.enableMulti; } if (typeof settings.showDept !== 'undefined') { this.showDept = settings.showDept; } if (settings.depts) { this.depts = settings.depts; } if (settings.vpcs) { this.vpcs = settings.vpcs; } if (settings.oss) { this.oss = settings.oss; } var html = '