add site
This commit is contained in:
397
Site/OTRConfig/js/controls.js
vendored
Normal file
397
Site/OTRConfig/js/controls.js
vendored
Normal file
@ -0,0 +1,397 @@
|
||||
/// <reference path="../../js/jquery-3.6.0.min.js" />
|
||||
/// <reference path="../../js/utility.js" />
|
||||
|
||||
$.fn.tab = function (obj) {
|
||||
return this.each(function () {
|
||||
var _this = $(this);
|
||||
_this.data('tabparam', obj);
|
||||
|
||||
function switchPage(page) {
|
||||
_this.children('.tab_page').hide();
|
||||
_this.children('#' + page).show();
|
||||
}
|
||||
|
||||
var titles = _this.children('.tab_header').children('.tab_title');
|
||||
titles.click(function (e) {
|
||||
var n_this = $(this);
|
||||
// invoke function
|
||||
function next() {
|
||||
if (typeof obj.onnext === 'function') {
|
||||
obj.onnext();
|
||||
}
|
||||
titles.removeClass('selected');
|
||||
var dfor = n_this.addClass('selected').attr('data-for');
|
||||
switchPage(dfor);
|
||||
}
|
||||
if (typeof obj.onclick === 'function') {
|
||||
obj.onclick(n_this, next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
var datafor = titles.removeClass('selected').first().addClass('selected').attr('data-for');
|
||||
switchPage(datafor);
|
||||
});
|
||||
};
|
||||
|
||||
$.fn.selectable = function (param) {
|
||||
|
||||
param = param || {};
|
||||
|
||||
function multi_click(e) {
|
||||
var target = $(e.target);
|
||||
if (!target.is('tr')) {
|
||||
target = target.parents('tr').first();
|
||||
}
|
||||
if (param.multiple) {
|
||||
if (!target.length)
|
||||
return;
|
||||
// ctrl
|
||||
if (e.ctrlKey) {
|
||||
if (target.hasClass('selected')) {
|
||||
target.removeClass('selected');
|
||||
} else {
|
||||
target.addClass('selected');
|
||||
}
|
||||
} else if (e.shiftKey) {
|
||||
target.addClass('selected');
|
||||
var first = $(this).children('tr.selected:first');
|
||||
var last = $(this).children('tr.selected:last');
|
||||
while (first.attr('uid') != last.attr('uid')) {
|
||||
first = first.next();
|
||||
if (!first.length)
|
||||
break;
|
||||
first.addClass('selected');
|
||||
}
|
||||
} else {
|
||||
$(this).children('tr').removeClass('selected');
|
||||
target.addClass('selected');
|
||||
}
|
||||
} else {
|
||||
$(this).children('tr').removeClass('selected');
|
||||
if (!target.length)
|
||||
return;
|
||||
target.addClass('selected');
|
||||
}
|
||||
}
|
||||
|
||||
function dbl_click(e) {
|
||||
if (typeof param.dblclick !== 'function')
|
||||
return;
|
||||
|
||||
var target = $(e.target);
|
||||
if (!target.is('tr')) {
|
||||
target = target.parents('tr').first();
|
||||
}
|
||||
param.dblclick.apply(this, [target]);
|
||||
}
|
||||
|
||||
return this.each(function () {
|
||||
$(this).click(multi_click).dblclick(dbl_click);
|
||||
});
|
||||
};
|
||||
|
||||
$.fn.tree = function (data, selectedValues, options) {
|
||||
|
||||
options = options || {};
|
||||
selectedValues = selectedValues || [];
|
||||
|
||||
if (!data) {
|
||||
return this;
|
||||
}
|
||||
|
||||
function changeExpand() {
|
||||
var flag = $(this).hasClass('collapse');
|
||||
if (flag) {
|
||||
$(this).removeClass('collapse').addClass('expand').parent('li').children('ul').show();
|
||||
} else {
|
||||
$(this).removeClass('expand').addClass('collapse').parent('li').children('ul').hide();
|
||||
}
|
||||
}
|
||||
|
||||
function checkSelected(data) {
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var item = data[i];
|
||||
if (selectedValues.indexOf(item.ID) >= 0) {
|
||||
return true;
|
||||
}
|
||||
if (item.SubData && item.SubData.length > 0) {
|
||||
if (checkSelected(item.SubData)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkChanged() {
|
||||
var li = $(this).parents('li:first');
|
||||
var checked = $(this).prop('checked');
|
||||
|
||||
// 如果有子节点
|
||||
var ul = li.children('ul');
|
||||
var indeter = $(this).prop('indeter');
|
||||
$(this).removeProp('indeter');
|
||||
if (checked) {
|
||||
// check all
|
||||
ul.find('input').removeProp('indeter').prop({ 'indeterminate': false, 'checked': true });
|
||||
} else {
|
||||
if (!indeter && ul.length > 0) {
|
||||
$(this).prop({
|
||||
'indeterminate': true,
|
||||
'indeter': true,
|
||||
'checked': true
|
||||
});
|
||||
} else {
|
||||
// uncheck all
|
||||
ul.find('input').removeProp('indeter').prop({ 'indeterminate': false, 'checked': false });
|
||||
}
|
||||
}
|
||||
checkUpper.apply(this);
|
||||
}
|
||||
|
||||
function checkUpper() {
|
||||
// 向上寻找父节点
|
||||
var ul = $(this).parents('ul:first');
|
||||
var inp = ul.prev('em').prev('span').children('input');
|
||||
if (inp.length > 0) {
|
||||
var chks = ul.children('li').children('span').children('input');
|
||||
var count = chks.length;
|
||||
for (var i = 0; i < chks.length; i++) {
|
||||
if (chks[i].indeterminate) {
|
||||
count = 0.5;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!chks[i].checked) {
|
||||
count--;
|
||||
}
|
||||
}
|
||||
if (count == chks.length) {
|
||||
// checked all
|
||||
inp.removeProp('indeter').prop({ 'indeterminate': false, 'checked': true });
|
||||
} else if (count == 0) {
|
||||
// unchecked all
|
||||
inp.removeProp('indeter').prop({ 'indeterminate': false, 'checked': false });
|
||||
} else {
|
||||
inp.prop({
|
||||
'indeterminate': true,
|
||||
'indeter': true,
|
||||
'checked': true
|
||||
});
|
||||
}
|
||||
// 遍历
|
||||
checkUpper.apply(inp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function fillChildren(ul, item, selected) {
|
||||
var li = $('<li></li>');
|
||||
var uid = 'li_' + Math.random().toString().substring(2);
|
||||
var chk = $('<input type="checkbox"/>').attr('id', uid).val(item.ID).change(checkChanged);
|
||||
if (selected || selectedValues.indexOf(item.ID) >= 0) {
|
||||
chk.prop('checked', true);
|
||||
selected = true;
|
||||
}
|
||||
var span = $('<span></span>');
|
||||
span.append(chk, $('<label></label>').attr('for', uid).text(item.Description));
|
||||
li.append(span);
|
||||
ul.append(li);
|
||||
// 判断是否有子节点
|
||||
if (item.SubData && item.SubData.length > 0) {
|
||||
// 判断子节点选中状态
|
||||
var ulc;
|
||||
if (selected || checkSelected(item.SubData)) {
|
||||
li.append($('<em class="icn expand"></em>').click(changeExpand));
|
||||
ulc = $('<ul></ul>');
|
||||
} else {
|
||||
li.append($('<em class="icn collapse"></em>').click(changeExpand));
|
||||
ulc = $('<ul></ul>').css('display', 'none');
|
||||
}
|
||||
var cnt = 0
|
||||
for (var i = 0; i < item.SubData.length; i++) {
|
||||
if (fillChildren(ulc, item.SubData[i], selected)) {
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
li.append(ulc);
|
||||
// 补充父节点的不定状态
|
||||
if (!selected && cnt > 0) {
|
||||
chk.prop({
|
||||
'indeterminate': true,
|
||||
'indeter': true,
|
||||
'checked': true
|
||||
});
|
||||
}
|
||||
}
|
||||
return selected;
|
||||
}
|
||||
|
||||
return this.each(function () {
|
||||
for (var i = 0 ; i < data.length; i++) {
|
||||
fillChildren($(this), data[i]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var TYPE_USER = 2;
|
||||
var TYPE_GROUP = 1;
|
||||
|
||||
$.fn.appendUserCtl = function (param) {
|
||||
param = param || {};
|
||||
|
||||
function dtquery(method, p, callback) {
|
||||
_network.request("Security/DataTablePermission.aspx", -1, method, p, callback, function (e) {
|
||||
console.log(e);
|
||||
showmaskbg(false);
|
||||
showAlert(e.statusText, 'Error');
|
||||
});
|
||||
}
|
||||
|
||||
function groupTitleClick(e) {
|
||||
if ($(this.lastChild).hasClass('collapse')) {
|
||||
$(this.lastChild).removeClass('collapse').addClass('expand');
|
||||
$(this).nextAll().show();
|
||||
} else {
|
||||
$(this.lastChild).removeClass('expand').addClass('collapse');
|
||||
$(this).nextAll().hide();
|
||||
}
|
||||
}
|
||||
|
||||
var usersul = $('<ul class="ul_menu"></ul>').attr('usertype', TYPE_USER);
|
||||
var usertitle = $('<li class="ul_header"></li>').append('<span>Users</span><em class="icn expand"></em>').click(groupTitleClick);
|
||||
usersul.append(usertitle);
|
||||
dtquery('GetUsers', '', function (data) {
|
||||
usertitle.nextAll().remove();
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var li = $('<li class="subitem"></li>')
|
||||
.attr({
|
||||
'id': data[i].IID,
|
||||
'title': data[i].ID
|
||||
})
|
||||
//.text(data[i].DisplayName)
|
||||
.append($('<span></span>').text(data[i].DisplayName), $('<i></i>').text('(' + data[i].ID + ')'))
|
||||
.data('usertype', data[i].UserType);
|
||||
li.click(param.selectUser);
|
||||
usersul.append(li);
|
||||
}
|
||||
|
||||
// default to load the first
|
||||
usertitle.next().click();
|
||||
});
|
||||
|
||||
var groupsul = $('<ul class="ul_menu"></ul>').attr('usertype', TYPE_GROUP);
|
||||
var grouptitle = $('<li class="ul_header"></li>').append('<span>User Groups</span><em class="icn expand"></em>').click(groupTitleClick);
|
||||
groupsul.append(grouptitle);
|
||||
dtquery('GetUserGroups', '', function (data) {
|
||||
grouptitle.nextAll().remove();
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var li = $('<li class="subitem"></li>').attr('id', data[i].ID).text(data[i].Name);
|
||||
li.click(param.selectUser);
|
||||
groupsul.append(li);
|
||||
}
|
||||
});
|
||||
|
||||
return this.append(usersul, groupsul);
|
||||
};
|
||||
$.fn.getUserIdType = function () {
|
||||
var li = this.find('li.selected');
|
||||
var id = li.attr('id');
|
||||
var usertype;
|
||||
if (li.parent().attr('usertype') == TYPE_GROUP) {
|
||||
usertype = TYPE_GROUP;
|
||||
} else {
|
||||
usertype = TYPE_USER;
|
||||
}
|
||||
return {
|
||||
'id': id,
|
||||
'type': usertype,
|
||||
'permission': li.data('usertype')
|
||||
};
|
||||
};
|
||||
|
||||
if (typeof Class !== 'function') {
|
||||
|
||||
// 基类实现 (空实现)
|
||||
Class = function () { };
|
||||
|
||||
/* Simple JavaScript Inheritance
|
||||
* By John Resig http://ejohn.org/
|
||||
* MIT Licensed.
|
||||
*/
|
||||
// Inspired by base2 and Prototype
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var initializing = false, fnTest = /xyz/.test(function () { xyz; }) ? /\b_super\b/ : /.*/;
|
||||
|
||||
// 创建一个继承当前调用类的子类
|
||||
Class.extend = function ext(prop) {
|
||||
var _super = this.prototype;
|
||||
|
||||
// 实例化,此时不执行构造方法 (x.prototype.constructor)
|
||||
initializing = true;
|
||||
var prototype = new this();
|
||||
initializing = false;
|
||||
|
||||
// 复制属性到新的prototype中
|
||||
for (var name in prop) {
|
||||
// 判断属性或重载方法
|
||||
prototype[name] = typeof prop[name] == "function" &&
|
||||
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
|
||||
(function (name, fn) {
|
||||
return function () {
|
||||
var tmp = this._super;
|
||||
|
||||
this._super = _super[name];
|
||||
var ret = fn.apply(this, arguments);
|
||||
this._super = tmp;
|
||||
|
||||
return ret;
|
||||
};
|
||||
})(name, prop[name]) :
|
||||
prop[name];
|
||||
}
|
||||
|
||||
// 临时构造方法
|
||||
function Class() {
|
||||
if (!initializing && this.init)
|
||||
this.init.apply(this, arguments);
|
||||
}
|
||||
|
||||
Class.prototype = prototype;
|
||||
// 修正构造方法的指向
|
||||
Class.prototype.constructor = Class;
|
||||
// 添加扩展
|
||||
Class.extend = ext; // arguments.callee;
|
||||
|
||||
return Class;
|
||||
};
|
||||
}());
|
||||
}
|
||||
if (typeof _chartType === 'undefined') {
|
||||
_chartType = {
|
||||
Gauge: 'Gauge',
|
||||
Grid: 'Grid',
|
||||
Grid3D: 'Grid3D',
|
||||
List: 'List',
|
||||
Line2D: 'Line',
|
||||
Line3D: 'Line3D',
|
||||
Column2D: 'Column',
|
||||
Column3D: 'Column3D',
|
||||
Bar2D: 'Bar',
|
||||
Bar3D: 'Bar3D',
|
||||
ColumnLine: 'ColumnLine',
|
||||
Scatter: 'ScatterPlot',
|
||||
Pie: 'Pie',
|
||||
Doughnut: 'Doughnut',
|
||||
Scorecard: 'FreeChart',
|
||||
Rss: 'RSS',
|
||||
Video: 'Video',
|
||||
Stock: 'Stock',
|
||||
Alert: 'Alert',
|
||||
Favorites: 'Favorites',
|
||||
FRPT: 'FRPT'
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user