js封装包
(function () {
//check the class name , it will be replaced when existed
if (window.IQCBase) {
//return window.IQCBase;
//window._IQCBase = window.IQCBase;
}
//constructor
window.IQCBase = function (param) {
param = param instanceof Object ? param : {};
this.cfg = param.cfg || {};
$.fn.editable = function (config) {
$(this).each(function (i, t) {
$(t).change(function () {
var me = $(this);
var $select2 = null;
me.find('.customerval').remove();
if (-999 == me.val()) {
var ed = $("<input type=\"text\" />");
if (config) {
$select2 = me.prev(config.className).hide();
}
me.after(ed).hide();
ed.blur(function () {
var v = ed.val();
if (null === v || v.length == 0) {
ed.remove(); me.val(null).show();
} else {
me.append("<option value=\"" + v + "\" class=\"customerval\" selected>" + v + "</option>").show();
ed.remove();
}
if ($select2 && $select2.length > 0) {
me.select2();
}
}).focus();
} });
});
};
$.fn.dataTable.Api.register('table().fnAjaxLoadData()', function (config) {
var table = this;
var params = IQCBase.getQueryParams('#' + config.form, config.formPerfix).param;
$.post(config.url, params, function (response) {
if (response) {
IQCBase.addRows(table, response.data, true);
if (config.success) { config.success(response); }
}
});
});
} //share property & method
var pt = IQCBase.prototype;
pt.UEConfig = { toolbars: [['bold', 'justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', 'inserttable', 'subscript', 'superscript', 'fontfamily']] };
pt.UEConfigDisable = { toolbars: [], wordCount: false, readonly: false };
pt.DateTimePickerCfg = {
language: 'zh-CN',
weekStart: 1,
minView: 2,
todayBtn: 1,
autoclose: 1,
todayHighlight: 1,
startView: 2,
forceParse: 1,
showMeridian: 1
};
pt.DateTimePickerCfg2 = {
language: 'zh-CN',
weekStart: 1,
minView: 0,
todayBtn: 1,
autoclose: 1,
todayHighlight: 1,
startView: 2,
forceParse: 1,
showMeridian: 1
};
//格式化日期
//expl: formatDate("2010-04-30", "yyyy-MM-dd HH:mm:ss")
pt.formatDate = function formatDate(date, format) {
if (!date) return;
if (!format) format = "yyyy-MM-dd";
switch (typeof date) {
case "string":
date = new Date(date.replace(/-/, "/"));
break;
case "number":
date = new Date(date);
break;
}
if (!date instanceof Date) return;
var dict = {
"yyyy": date.getFullYear(),
"M": date.getMonth() + 1,
"d": date.getDate(),
"H": date.getHours(),
"m": date.getMinutes(),
"s": date.getSeconds(),
"MM": ("" + (date.getMonth() + 101)).substr(1),
"dd": ("" + (date.getDate() + 100)).substr(1),
"HH": ("" + (date.getHours() + 100)).substr(1),
"mm": ("" + (date.getMinutes() + 100)).substr(1),
"ss": ("" + (date.getSeconds() + 100)).substr(1)
};
return format.replace(/(yyyy|MM?|dd?|HH?|ss?|mm?)/g, function () {
return dict[arguments[0]];
});
}
pt.format = function (format) {
var args = pt.toArray(arguments, 1);
return format.replace(/\{(\d+)\}/g, function (m, i) {
return args[i];
});
};
pt.toArray = function (iterable, start, end) {
if (!iterable || !iterable.length) { return []; }
var array = [], i;
start = start || 0;
end = end ? ((end < 0) ? iterable.length + end : end) : iterable.length;
for (i = start; i < end; i++) {
array.push(iterable[i]);
}
return array;
};
pt.htmlEncode = function (value) {
var entities = {
'&': '&',
'>': '>',
'<': '<',
'"': '"'
}, keys = [], p, regex; for (p in entities) {
keys.push(p);
} regex = new RegExp('(' + keys.join('|') + ')', 'g'); return (!value) ? value : String(value).replace(regex, function (match, capture) {
return entities[capture];
});
};
pt.getDate = function (val) {
var date = eval("new " + val.substr(1, val.length - 2));
return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
};
pt._radomNum = {};
pt.getRadomNum = function () {
var b;
while (true) {
b = Math.random().toString().substr(2, 7) / 100;
if (b.toString().length === 8 && pt._radomNum[b] === undefined) {
return pt._radomNum[b] = b;
}
}
};
pt.parseFloat = function (v) {
var pre = parseFloat(v).toPrecision(14);
return parseFloat(pre);
};
pt.max = function (array) {
var max = array[0], i, ln, item;
for (i = 0, ln = array.length; i < ln; i++) {
item = array[i];
if (item > max) { max = item; }
}
return max;
};
pt.min = function (array) {
var min = array[0], i, ln, item;
for (i = 0, ln = array.length; i < ln; i++) {
item = array[i];
if (item < min) {
min = item;
}
}
return min;
};
pt.getMaxMin = function () {
var max = pt.max(arguments),
min = pt.min(arguments);
return [max, min];
};
pt.supportsSort = (function () {
var a = [1, 2, 3, 4, 5].sort(function () { return 0; });
return a[0] === 1 && a[1] === 2 && a[2] === 3 && a[3] === 4 && a[4] === 5;
}());
pt.sort = function (array, sortFn) {
var length = array.length, i = 0, comparison, j, min, tmp;
for (; i < length; i++) {
min = i;
for (j = i + 1; j < length; j++) {
if (sortFn) {
comparison = sortFn(array[j], array[min]);
if (comparison < 0) { min = j; }
}
else if (array[j] < array[min]) { min = j; }
}
if (min !== i) {
tmp = array[i];
array[i] = array[min];
array[min] = tmp;
}
}
return array;
};
pt.avg = function () {
var arr = arguments, len = arguments.length, sum = 0;
for (var i = 0; i < len; i++) {
if ($.isNumeric(arr[i])) { sum += parseFloat(arr[i]); }
}
return IQCBase.parseFloat(sum / 2);
};
pt.isNull = function () {
var arr = arguments, result = true;
for (var i = 0; i < arr.length; i++) {
var v = arr[i];
result &= pt.isEmpty(v);
}
return result;
};
pt.isEmpty = function (value) {
return (value === null) || (value === undefined) || (value === '');
};
pt.isNumeric = function () {
var arr = arguments, result = true;
for (var i = 0; i < arr.length; i++) {
result &= $.isNumeric(arr[i]);
}
return result;
}; pt.getUrlParam = function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
};
pt.leftPad = function (string, size, character) {
var result = String(string);
character = character || " ";
while (result.length < size) {
result = character + result;
}
return result;
};
pt.now = function () {
var date = new Date();
return date.getFullYear() + "-"
+ pt.leftPad(date.getMonth() + 1, 2, '0') + "-"
+ pt.leftPad(date.getDate(), 2, '0') + " "
+ pt.leftPad(date.getHours(), 2, '0') + ":"
+ pt.leftPad(date.getMinutes(), 2, '0') + ":"
+ pt.leftPad(date.getSeconds(), 2, '0');
};
pt.appendValue = function (obj, val, splitChar) {
var spChar = splitChar || ',';
var currentVal = obj.val(), currentArray = [];
if (currentVal && currentVal.length > 0)
currentArray = currentVal.split(',');
if (currentVal.indexOf(val) == -1)
currentArray.push(val);
obj.val(currentArray.join(','));
};
pt.getDateFormat = function (value, rec) {
return eval("new " + value.substr(1, value.length - 2)).toLocaleDateString();
}; //提示信息
pt.confirm = function (text, cb) {
var initTemplate = function () {
if ($('#IQCBase_ConfirmModal').length == 1)
return true;
$('body').append(' \
<div id="IQCBase_ConfirmModal" class="modal fade" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true"> \
<div class="modal-dialog">\
<div class="modal-content">\
<div class="modal-header">\
<a class="close" id="close" data-dismiss="modal">×</a>\
<h3 class="modal-title">系统提示</h3>\
</div>\
<div class="modal-body">\
<p style="font-size:1.2em"></p>\
</div>\
<div class="modal-footer">\
<button class="btn btn-primary" data-dismiss="modal" aria-hidden="true" data-keyup="enter">确定</button> \
<button class="btn btn-danger" data-dismiss="modal" aria-hidden="true">取消</button> \
</div>\
</div>\
</div>\
</div>');
}
var bootStrapConfirm = function () {
if (!$.fn.modal.Constructor)
return false; $('body').off('click', '#IQCBase_ConfirmModal .btn-primary');
$('body').off('click', '#IQCBase_ConfirmModal .btn-danger'); function confirm() { cb(true); }
function deny() { cb(false); } $('body').on('click', '#IQCBase_ConfirmModal .btn-primary', confirm);
$('body').on('click', '#IQCBase_ConfirmModal .btn-danger', deny); return true;
}
initTemplate()
if (bootStrapConfirm()) {
$('#IQCBase_ConfirmModal .modal-body p').text(text);
$('#IQCBase_ConfirmModal').modal();
} else {
alert('bootstrap was not found');
}
};
pt.showMsg = function (content, title, cb) {
if (!$.fn.modal.Constructor) {
alert('bootstrap was not found');
return false;
}
var initTemplate = function () {
if ($('#IQCBase_AlertModal').length == 1)
return true;
$('body').append(' \
<div id="IQCBase_AlertModal" class="modal fade" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true">\
<div class="modal-dialog">\
<div class="modal-content">\
<div class="modal-header">\
<a class="close" id="close" data-dismiss="modal">×</a>\
<h3 class="modal-title">提示</h3>\
</div>\
<div class="modal-body">\
<p style="font-size:1.2em"></p>\
</div>\
<div class="modal-footer">\
<button class="btn btn-primary" data-keyup="enter" data-dismiss="modal">确认</button>\
</div>\
</div>\
</div>\
</div>');
}
var bindCallBack = function () {
$('body').off('click', '#IQCBase_AlertModal .btn-primary');
if (cb) {
$('body').on('click', '#IQCBase_AlertModal .btn-primary', cb);
}
}
initTemplate();
var modal = $('#IQCBase_AlertModal');
modal.find('.modal-body p').html(content);
if (title) {
modal.find('.modal-title').text(title);
}
if (cb) {
var btn = modal.find('.btn-primary');
btn.on('click', cb);
}
modal.modal('show');
};
//datatables checkbox
pt.checkAllItem = function (table, checked) {
var tableID = table.settings()[0].sTableId;
var args = arguments[2],
checkedItems = $("#" + tableID+ ' input[name="checkvalue"]'),
tableID = table.settings()[0].sTableId;
if (args && args.length > 1) {
checkedItems.each(function (i, o) {
$(o)[0].checked = checked;
var data = table.row(i).data();
if (checked == true) {
pt.appendSelecteValue(tableID, data, args);
} else {
pt.removeSelecteValue(tableID, data, args);
}
});
} else {
checkedItems.each(function (i, o) { $(o)[0].checked = checked; });
}
};
pt.bindMultipleSelect = function (table) {
var tableID = table.settings()[0].sTableId;
var __table = $("#" + tableID);
var checkAll = $(table.table().header()).find("input[name='checkAll']");
checkAll.click(function () { pt.checkAllItem(table, $(this)[0].checked); });
__table.on('click', 'tr', function (a) {
var row = $(this);
var checkBox = row.find("input[name='checkvalue']"),
selected = row.hasClass('selected');
__table.find('tr.selected').removeClass('selected');
if (checkBox.length > 0) {
if (a.target.name != 'checkvalue') { checkBox[0].checked = !checkBox[0].checked; }
var isAll = __table.find('input[name="checkvalue"]:checked').length == __table.find("tr").length - 1;
checkAll[0].checked = isAll;
}
if (!selected) { row.addClass('selected'); }
});
};
pt.bindSingleSelect = function (table, modalID, id, val, desc) {
var tableID = table.settings()[0].sTableId;
$(table.table().body()).on('click', 'tr', function () {
var row = $(this);
var data = table.row(this.rowIndex - 1).data();
var checkBox = row.find("input[name='checkvalue']");
var selected = row.hasClass('selected');
if (checkBox.length > 0) {
//pt.checkAllItem(table, false);
checkBox[0].checked = !selected;
}
if (selected) {
row.removeClass('selected');
pt.clearSelectorParams(tableID);
}
else {
table.$('tr.selected').removeClass('selected');
row.addClass('selected');
pt.SELECTOR_ID[tableID] = data[id];
if (val) pt.SELECTOR_VAL[tableID] = data[val];
if (desc) pt.SELECTOR_DESC[tableID] = data[desc];
}
});
$(table.table().body()).on('dblclick', 'tr', function () {
var data = table.row(this.rowIndex - 1).data();
pt.SELECTOR_ID[tableID] = data[id];
if (val) pt.SELECTOR_VAL[tableID] = data[val];
if (desc) pt.SELECTOR_DESC[tableID] = data[desc];
var modal = $('#' + modalID);
modal[0].title = 'OK';
modal.modal('hide');
});
};
pt.removeSelecteValue = function (tableID, data, args) {
var replace1 = ',', replace2 = '#SP#', len = args.length;
if (len > 1) {
var val = data[args[1]];
if (val != 'null' && val != '') {
pt.SELECTOR_ID[tableID] = pt.SELECTOR_ID[tableID].replace(replace1 + val + replace1, '');
}
}
if (len > 2) {
var val = data[args[2]];
if (val != 'null' && val != '') {
pt.SELECTOR_VAL[tableID] = pt.SELECTOR_VAL[tableID].replace(replace2 + data[args[2]] + replace2, '');
}
}
if (len > 3) {
var val = data[args[3]];
if (val != 'null' && val != '') {
pt.SELECTOR_DESC[tableID] = pt.SELECTOR_DESC[tableID].replace(replace2 + data[args[3]] + replace2, '');
}
}
}; pt.bindCheckNotUse = function (setting) {
/// <summary>datatables checkbox 不适用</summary>
var args = arguments;
var table = setting.table;
var btn = setting.btn;
var p = setting.p;
$(table.table().header()).on('click', 'input.checkboxes', function (o) {
var checkedOfAll = this.checked;
$(table.table().body()).find('input[name=checkvalue]:checkbox').prop('checked', checkedOfAll);
var strChecked = checkedOfAll ? 'Y' : null;
if (p) {
$(table.table().data()).each(function (i, d) {
if (d[p]) {
d[p] = strChecked;
table.row(i).data(d);
}
});
}
if (btn) {
$('#' + btn).prop('disabled', false);
}
}); $(table.table().body()).on("click", "input.checkboxes", function (o) {
var $self = $(this);
var $tHeader = $(table.table().header());
var $tBody = $(table.table().body());
if ($tBody.find('input[name=checkvalue]:checked').length == $tBody.find('input[name=checkvalue]').length) {
$tHeader.find('input[name=checkAll]').prop('checked', true);
} else {
$tHeader.find('input[name=checkAll]').prop('checked', false);
}
var id = $self.data('id');
var strChecked = $self.prop('checked') ? 'Y' : null;
if (p) {
$(table.table().data()).each(function (i, d) {
if (d[p]) {
d[p] = strChecked;
table.row(i).data(d);
}
});
}
if (btn) {
$('#' + btn).prop('disabled', false);
}
});
};
pt.getUrlParamsVal = function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substring(1).match(reg);
if (r != null) return (r[2]); return null;
};
pt.getUrlParams = function (urlParams) {
/// <summary>将字符串反序列化对象 与jQuery.param 相反</summary>
/// <param name="urlParams" type="string"> url参数 类似于 a=1&b=2这种</param>
/// <returns type="object" />
var args = new Object();
var query = urlParams || location.search.substring(1);
var pairs = query.split("&");
for (var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('=');
if (pos === -1) continue;
var argname = pairs[i].substring(0, pos);
var value = pairs[i].substring(pos + 1);
args[argname] = unescape(value);
}
return args;
};
pt.getAttachmentLinkCell = function (row, params, text) {
var link = '<a class="link" name="attachment" href="javascript:void(0)" data-row={0} data-params="{2}">{1}</a>';
return pt.format(link, row, text || '<i class="icon-file"></i> ', params);
};
pt.bindAttachment = function (options) {
/// <summary>datatables Attachment click</summary>
var args = arguments;
var table = options.table; $(table.table().body()).on('click', 'a[name=attachment]', function (e) {
var $self = $(this);
var rowIndex = $self.data('row');
var rowData = table.row(rowIndex).data();
var paramString = $self.data('params');
var params = pt.getUrlParams(paramString);
var options = { 'modalID': 'attachment', 'params': params };
pt.showAttachmentModal(options);
});
};
pt.showAttachmentModal = function (options) {
/// <summary>Attachment modal</summary>
var args = arguments;
var modalID = (options.modalID || '') + '_modal';
var modalTitle = options.modalTitle || '附件上传';
var $modal = $('#' + modalID);
var uploadID = modalID + '_uploader';
var uploadHiddenID = modalID + '_uploaderHidden';
var tableID = modalID + '_table';
var $table = $('#' + tableID); var initTemplate = function () {
if ($modal.length > 0) { $modal.remove(); }
var html = ' \
<div id="{0}" class="modal fade" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true"> \
<div class="modal-dialog">\
<div class="modal-content">\
<div class="modal-header">\
<a class="close" id="close" data-dismiss="modal">×</a>\
<h3 class="modal-title">{1}</h3>\
</div>\
<div class="modal-body">\
<div class="message-box alert alert-danger" style="display:none"><ul></ul></div>\
<div class="panel panel-default" style="margin-bottom: 0px;">\
<div class="panel-body" style="padding:0px;overflow:auto;height:100%">\
<div class="form-inline">\
<div class="form-group"">\
<div class="col-md-12">\
<!-- /paras is here -->\
{5}\
<!-- /webUploader is here -->\
<div id="{2}"></div>\
<input type="hidden" name="{3}" id="{3}" />\
</div>\
</div>\
</div>\
<div class="table-responsive">\
<table id="{4}" class="table table-striped table-bordered table-hover dataTable tableh" cellspacing="0" style="overflow:auto;height:100%;"></table>\
</div>\
</div>\
</div>\
<div style="clear:both;"></div>\
</div>\
<div class="modal-footer">\
<button type="button" class="btn btn-danger" data-dismiss="modal" aria-hidden="true">关闭</button> \
</div>\
</div>\
</div>\
</div>';
var dyElement = '';
for (var i in options.params) {
dyElement += pt.format('<input type="hidden" name="{0}" value="{1}" />', modalID + i, options.params[i]);
} $('body').append(pt.format(html, modalID, modalTitle, uploadID, uploadHiddenID, tableID, dyElement));
};
initTemplate();
$modal = $('#' + modalID); // datatableAPI
var table = IQCBase.initAutoDT({
queryPanel: $modal,
queryObjectPerfix: modalID,
tableID: tableID,
target: 'FileService',
scrollX: true,
scrollY: '100%',
columns: [
$.extend({}, IQCBase.checkColumn, { width: 15 }),
$.extend(IQCBase.snColumn, { width: 25 }),
{ data: 'FILE_NAME', title: '文件名称', className: 'text-center', xtype: 'downFile', key: ['ID'] },
{
data: 'FILE_SIZE', title: '文件大小', className: 'text-center', render: function (data, type, full, meta) {
var display = WebUploader.Base.formatSize((data || 0) * 1024, '0', ['B', 'KB', 'MB']);
return display;
}
},
{ data: 'DATETIME_CREATED', title: '上传时间', className: 'text-center', xtype: 'cut', len: 24 },
{ data: 'SOURCE_USER', title: '上传人', width: 50, className: 'text-center', xtype: 'cut', len: 8 }
],
onDraw: function (e, settings, json) {
$table.find('tbody tr').on('click', 'a[data-params]', function () {
var lnk = $(this);
var paramString = lnk.attr('data-params'), iRow = lnk.attr('data-row');
});
},
onInit: function () { }
}); $modal.off("show.bs.modal").on("show.bs.modal", function (callback) {
if ($.isFunction(options.onShow)) {
var callback = options.onShow;
callback();
}
});
$modal.off("shown.bs.modal").on("shown.bs.modal", function (callback) {
$('#' + uploadID).webUploader({
hiddenInputId: uploadHiddenID,
PostbackHold: true,
ShowDownload: false,
showBtnDel: true,
extParams: options.params,
table: table,
tableID: tableID
});
IQCBase.bindMultipleSelect(table);
table.ajax.url('/Common/FileService/GetFiles').load(); if ($.isFunction(options.onShown)) {
var callback = options.onShown;
callback();
}
}); if ($.isFunction(options.onHide)) {
$modal.off("hide.bs.modal").on("hide.bs.modal", options.onHide);
}
if ($.isFunction(options.onHidden)) {
$modal.off("hidden.bs.modal").on("hidden.bs.modal", options.onHidden);
}
$modal.modal('show');
}; // get/set element value
pt.setForm = function (parent, data, formParentPerfix, fieldPerfix) {
fieldPerfix = fieldPerfix || 'txt';
$.each(data, function (key, val) {
var obj = parent.find('[name="' + fieldPerfix + key + '"]');
if (obj && obj.length > 0) {
if (obj.length == 1) {
if (obj.is('input')) { obj.val(val); }
else if (obj.is('select')) {
obj.find("option[value='" + val + "']").prop("selected", true);
}
else if (obj.is('textarea')) {
//is UEditor
if (!obj.attr('data-notset')) {
var objDisplay = obj.css("display");
if (objDisplay == 'none') {
var _name = obj.attr('name');
var _prop = _name.replace('txt', '');
var editor = UE.getEditor(formParentPerfix + _name);
if (editor) {
editor.addListener("ready", function () {
this.setContent(data[_prop]);
this.removeListener("ready");
});
}
} else {
obj.val(val);
}
}
}
} else {
obj.each(function (i, e) {
if (!IQCBase.isEmpty(val) && val.indexOf($(e).val()) > -1) {
$(e).prop('checked', 'checked');
} else {
$(e).removeAttr('checked');
}
}); }
}
});
};
pt.getQueryParams = function (parent, queryObjectPerfix, d, ableOrder) {
var returnParam = { param: {}, paramIsNull: false },
formTextData = $(parent).find("[name^='" + queryObjectPerfix + "'][type!='checkbox'][type!='radio']"),
formCheckData = $(parent).find("input[name^='" + queryObjectPerfix + "']:checked");
if (d) {
if (!ableOrder) returnParam.param = { start: d.start, length: d.length };
else returnParam.param = { start: d.start, length: d.length, order: d.order, columns: d.columns };
}
for (var i = 0; i < formTextData.length; i++) {
var e = formTextData[i];
var val = $(e).val();
if (val) {
returnParam.param[e.name.replace(queryObjectPerfix, '')] = val.toString();
returnParam.paramIsNull |= val.toString().length > 0;
}
}
//处理Checkbox
var checkboxNames = [];
formCheckData.each(function (i, e) {
var name = e.name.replace(queryObjectPerfix, '');
if (!returnParam.param[name]) {
returnParam.param[name] = [];
checkboxNames.push(name);
}
returnParam.param[name].push($(e).val());
});
$.each(checkboxNames, function (i, name) {
returnParam.param[name] = returnParam.param[name].join(',');
}); return returnParam;
};
pt.getSubmitData = function (parent) {
var param = {};
var formData = parent.find("input[type!='checkbox'][type!='radio'][name^='txt']");
for (var i = 0; i < formData.length; i++) {
var e = formData[i]; var oe = $(e);
var required = oe.attr('data-required');
if (required && oe.val().length < 1) {
pt.showMsg(required);
return null;
}
param[e.name.replace('txt', '')] = $(e).val();
}
//处理Checkbox
var formCheckData = parent.find("input[type='checkbox'][name^='txt']:checked");
var checkboxNames = [];
formCheckData.each(function (i, e) {
var name = e.name.replace('txt', '');
if (!param[name]) {
param[name] = [];
checkboxNames.push(name);
}
param[name].push($(e).val());
});
$.each(checkboxNames, function (i, name) {
param[name] = param[name].join(',');
});
//处理Radio
var formRadioData = parent.find("input[type='radio'][name^='txt']:checked");
formRadioData.each(function (i, e) {
var name = e.name.replace('txt', '');
param[name] = $(e).val();
});
//处理select
var formSelectData = parent.find("select[name^='txt']");
for (var i = 0; i < formSelectData.length; i++) {
var e = formSelectData[i]; var oe = $(e);
var required = oe.attr('data-required');
if (required && oe.val().length < 1) {
pt.showMsg(required);
return null;
}
var name = e.name.replace('txt', '');
param[name] = $(e).val();
}
//处理textarea
var formTextareaData = parent.find("textarea[name^='txt']:not([data-notset])");
for (var i = 0; i < formTextareaData.length; i++) {
var e = formTextareaData[i]; var oe = $(e);
var required = oe.attr('data-required');
if (required && oe.val().length < 1) {
pt.showMsg(required);
return null;
}
param[e.name.replace('txt', '')] = $(e).val();
}
//处理UEditor
//var formTextareaData = parent.find("textarea[name^='txt'][data-notset]");
//for (var i = 0; i < formTextareaData.length; i++) {
// var e = formTextareaData[i]; var oe = $(e);
// console.log(e);
// var required = oe.attr('data-required');
// if (required && oe.val().length < 1) {
// pt.showMsg(required);
// return null;
// }
// var name = e.name.replace('txt', '');
// param[name] = $(e).val();
//}
return param;
}; //datatables默认配置
pt.pageSelector = [[20, 50, 100], [20, 50, 100]];
pt.tablesDom = '<"top"f>rt<"bottom"pli><"clear">';
pt.tablesLanguage = {
lengthMenu: " _MENU_ ",
processing: "载入中",
paginate: { previous: "前一页", next: "后一页", first: "首页", last: "尾页" },
zeroRecords: "没有内容",
info: "共 <kbd>_TOTAL_</kbd> 条",
infoEmpty: "没有检索出结果",
infoFiltered: ""
}; //值变更方法
pt.selectSetChangeEvent = function (thisObj, tableID, iRow, name) {
result = thisObj.val();
if (!thisObj.is('input')) {
result = thisObj.find("option:selected").val();
}
var data = $('#' + tableID).DataTable().rows(iRow).data()[0];
data[name] = result;
$('#' + tableID).dataTable().fnUpdate(data, iRow);
};
pt.defaultSetChangeEvent = function (thisObj, tableID, iRow, name) {
result = thisObj.val();
var data = $('#' + tableID).DataTable().rows(iRow).data()[0];
data[name] = result;
$('#' + tableID).dataTable().fnUpdate(data, iRow);
};
pt.changeEvent = {
"INSPECTION_RESULT": function (thisObj, tableID, iRow, name) { pt.selectSetChangeEvent(thisObj, tableID, iRow, name); },
"PROCESSING_RESULT": function (thisObj, tableID, iRow, name) { pt.defaultSetChangeEvent(thisObj, tableID, iRow, name); },
"DUTY_DEPARTMENT": function (thisObj, tableID, iRow, name) { pt.defaultSetChangeEvent(thisObj, tableID, iRow, name); },
"FAIL_DESC": function (thisObj, tableID, iRow, name) { pt.defaultSetChangeEvent(thisObj, tableID, iRow, name); }
};
//注册表格控件值变更事件 需要控件加入data-name,data-row属性,data-name属性值为pt.changeEvent中的function name
//colNames为监控的字段,Array类型,可null
//callBackFun回调方法,可null
pt.registerTableChange = function (tableID, colNames, callBackFun) {
var objects = $('#' + tableID + ' tbody tr [data-name]');
objects.off('change');
objects.on('change', function () {
var thisObj = $(this);
var name = thisObj.attr('data-name'),
iRow = parseInt(thisObj.attr('data-row'));
var func = pt.changeEvent[name];
if (func) { func(thisObj, tableID, iRow, name); }
else if(colNames && $.inArray(name,colNames)>-1)
{
if(this.nodeName=="INPUT" && this.type!="checkbox")
pt.defaultSetChangeEvent(thisObj, tableID, iRow, name);
else if(this.nodeName=="SELECT")
pt.selectSetChangeEvent(thisObj, tableID, iRow, name);
}
if (callBackFun)
callBackFun(this);
});
}; //删除datatables数据
pt.deleteChecked = function (table, url, keys, msgTarget) {
var checkboxes = table.$("input[name='checkvalue']");
if (table.$("input[name='checkvalue']:checked").size() == 0) {
pt.showMsg("未选中行,请至少选中一行记录。");
}
else {
pt.confirm("你确定要删除选中记录吗?", function (ok) {
if (ok) {
pt.confirmDelete(table, url, keys, checkboxes, msgTarget);
}
});
}
};
pt.confirmDelete = function (table, url, keys, checkboxes, msgTarget) {
msgTarget = msgTarget || 'data';
var paramsArray = {};
checkboxes.each(function (i, o) {
if (o.checked == true) {
var data = table.data()[i];
$.each(keys, function (k, v) {
if (!paramsArray[v]) paramsArray[v] = [];
paramsArray[v].push(data[v]);
});
}
});
if (!$.isEmptyObject(paramsArray)) {
var params = {}
$.each(paramsArray, function (k, v) {
params[k] = paramsArray[k].join(',');
});
$.post(url, params, function (response) {
if (response.success) {
//$('#IQCBase_ConfirmModal').modal('hide');
table.ajax.reload();
}
else {
pt.showMsg(response[msgTarget] && response[msgTarget].length == 0 ? "删除失败" : response[msgTarget]);
}
}, "json");
}
}; //params: url, modalID, paramString, onShown, onHidden
pt.showDetail = function (config) {
$('body').modalmanager('loading');
var modal = $("#" + config.id);
if (modal.length < 1) {
$('body').append('<div id="' + config.id + '" class="modal fade" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="add-role-title" aria-hidden="true"></div>');
}
modal.load(config.url, config.paramString || '', function () {
if ($.isFunction(config.onShow)) {
modal.off("show.bs.modal");
modal.on("show.bs.modal", config.onShow);
}
if ($.isFunction(config.onShown)) {
modal.off("shown.bs.modal");
modal.on("shown.bs.modal", config.onShown);
}
if ($.isFunction(config.onHide)) {
modal.off("hide.bs.modal");
modal.on("hide.bs.modal", config.onHide);
}
if ($.isFunction(config.onHidden)) {
modal.off("hidden.bs.modal");
modal.on("hidden.bs.modal", config.onHidden);
}
modal.modal('show');
});
};
//注册datatables超链接的点击事件
pt.registerLinkClick = function (tableID, detailID, url) {
$('#' + tableID + ' tbody tr a[data-params]').on('click', '', function () {
var lnk = $(this);
pt.showDetail({
id: detailID,
url: url,
paramString: lnk.attr('data-params'),
onHidden: function (event) {
$(this).removeData('bs.modal').empty();
}
});
});
};
pt.columns = {};
//初始化自动加载数据的datatables
pt.initAutoDT = function (config) {
var areaName = config.areaName || 'IQC';
var url = "/" + areaName + "/" + config.target + "/QueryNullable";
var detailUrl = config.detailUrl || "/" + areaName + "/" + config.target + "/Detail";
var processing = config.pagingType != undefined ? config.pagingType : true,
tableID = config.tableID || config.perfix + 'tbData';
scrollY = '' + ($(window).height() - $(config.queryPanel).outerHeight() - 244);
var tbObj = $('#' + tableID);
if (config.onInit) { tbObj.on('init.dt', config.onInit); }
if (config.onDraw) { tbObj.on('draw.dt', config.onDraw); }
if (config.onXHR) { tbObj.on('xhr.dt', config.onXHR); }
else if (config.autoBindLink === true) {
tbObj.on('draw.dt', function () {
pt.registerLinkClick(tableID, config.perfix + 'DetailDialog', detailUrl);
});
}
pt.columns[tableID] = config.columns;
var table = tbObj.DataTable({
//lengthChange: false,
//xcol: config.columns,
autoWidth: false,
pagingType: config.pagingType || "full_numbers",
searching: false,
serverSide: true,
processing: processing,
scrollX: config.scrollX || true,
scrollY: config.scrollY || scrollY,
scrollCollapse: false,
lengthMenu: IQCBase.pageSelector,
pageLength: config.pageLength || 20,
order: config.order || [],
ordering: config.orderable || false,
retrieve: true,
dom: IQCBase.tablesDom,
ajax: {
type: "post",
url: config.url || url,
cache: false,
dataSrc: "data",
beforeSend: function (r) { if (!config.autoLoad) { IQCBase.ajaxBeforeSend(this, tableID, r); } },
error: IQCBase.ajaxError,
complete: function () {
IQCBase.ajaxComplete(tableID);
},
data: function (d) {
debugger;
return IQCBase.getQueryParams(config.queryPanel, config.queryObjectPerfix, d, config.orderable).param;
}
},
columns: pt.getColumns(config.columns, detailUrl, config.perfix),
language: config.language || IQCBase.tablesLanguage
});
return table;
};
//初始化手动加载数据的datatables
pt.initManualDT = function (config) {
var tableID = config.tableID || config.perfix + 'tbData';
pt.columns[tableID] = config.columns;
var tbObj = $('#' + tableID),
scrollY = config.scrollY ? config.scrollY : '';
if (config.onInit) { tbObj.on('init.dt', config.onInit); }
if (config.onDraw) { tbObj.on('draw.dt', config.onDraw); }
var table = tbObj.DataTable({
//autoWidth: true,
//pagingType: config.pagingType || "full_numbers",
//serverSide: true,
//lengthMenu: IQCBase.pageSelector,
//pageLength: config.pageLength || 10,
//retrieve: true,
//dom: IQCBase.tablesDom,
dom: '<"top"f>rt<"bottom"pli><"clear">',
paging: false,
searching: false,
retrieve: true,
processing: config.processing || true,
scrollX: config.scrollX || false,
scrollY: scrollY,
order: config.order || [],
ordering: config.orderable || false,
columns: pt.getColumns(config.columns, config.detailUrl, config.perfix),
language: config.language || IQCBase.tablesLanguage
});
return table;
};
//datatables add rows
pt.addRows = function (table, datas, clear) {
if (clear) { table.rows().remove(); }
$.each(datas, function (i, o) { table.row.add(o); });
table.draw();
}; //datatables checkbox column
pt.parseCheckAll = function (v) {
return '<input name="checkAll" type="checkbox" class="checkboxes" />';
};
pt.parseCheck = function (v, type, full, meta) {
return '<input name="checkvalue" type="checkbox" class="checkboxes" data-row="' + meta.row + '" data-id="' + v.ID + '" />';
};
pt.parseRadio = function (v) {
return '<input name="checkvalue" type="radio" class="radio" />';
};
pt.checkColumn = { width: 20, className: 'text-center', orderable: false, data: pt.parseCheck, title: pt.parseCheckAll };
pt.radioColumn = { width: 20, className: 'text-center', orderable: false, data: pt.parseRadio }; //datatables checkbox column values
pt.parseCheckValues = function (v, type, full, meta) {
return '<input name="checkvalue" type="checkbox" class="checkboxes" data-row="' + meta.row + '"value="' + v.ID + '" />';
};
pt.checkColumnValues = { width: 20, className: 'text-center', orderable: false, data: pt.parseCheckValues, title: pt.parseCheckAll }; //datatables 序号列
pt.snColumn = {
title: '序号', className: 'text-center', orderable: false, data: function (data, type, full, meta) {
return meta.row + 1;
}
};
//datatables htmlEncode column
pt.getHtmlColumn = function (column) {
return {
title: column.title,
data: function (e) {
return IQCBase.htmlEncode(e[column.data]);
}
};
},
//datatables link column
pt.getLinkTabColumn = function (col) {
var colName = col.data;
var obj = {
title: col.title,
className: 'text-center',
data: function (d) {
var paramString = '', key = col.key, params = {};
$.each(key, function (i, v) { params[v] = d[v]; });
paramString = $.param(params).replace(/&/g, '&');
var lnk = '<a target="navTab" rel="{4}" title="{3}" href="{1}?{2}">{0}</a>';
var rel = col.rel || 'this';
var tabTitle = IQCBase.format(col.tabTitle, d[colName]);
return IQCBase.format(lnk, d[colName], col.url, paramString, tabTitle, col.rel);
}
};
return obj;
};
pt.getLinkColumn = function (col) {
var colName = col.data;
var obj = {
title: col.title,
className: 'text-center',
data: function (d, type, full, meta) {
var paramString = '', key = col.key, params = {};
$.each(key, function (i, v) { params[v] = d[v]; });
paramString = $.param(params).replace(/&/g, '&');
return IQCBase.getLinkCell(paramString, d[colName], meta.row);
}
};
return obj;
};
pt.getLinkCell = function (paramString, text, row) {
var rowIndex = row ? row : '-1';
var lnk = '<a href="javascript:void(0)" data-row={2} data-params="{0}">{1}</a>';
return pt.format(lnk, paramString, text, row);
};
//datatables color column
pt.getColorCol = function (col) {
return {
title: col.title, className: 'text-center',
data: function (e) {
return '<span style="color:' + col.color + '">' + e[col.data] + '</span>';
}
};
};
//datatables 显示是或否
pt.getEnableCol = function (col) {
return { title: col.title, className: 'text-center', data: function (d) { return d[col.data] == 2 ? "是" : "否"; } };
};
//datatables cut string column
pt.getLenCol = function (col) {
return {
title: col.title,
className: col.className,
data: function (d) {
var val = d[col.data];
if (!val) return val;
var len = col.len;
var parseHtmlVal = IQCBase.removeHtml(val);
var cut = '';
if (parseHtmlVal.length > 0 && parseHtmlVal.length > len) {
cut = parseHtmlVal.substr(0, len) + '...';
} else {
cut = parseHtmlVal;
}
return '<span title="' + parseHtmlVal + '">' + cut + '</span>';
}
};
};
pt.getStanrdLenCol = function (col) {
return {
orderable: col.orderable || false,
title: col.title,
name: col.name,
className: 'text-center',
data: function (d) {
var val = d[col.data];
var title = col.titleValue ? col.titleValue : null;
if (!val && !title) return val;
var cut = val && val.length > 0 && val.length > col.len ? val.substr(0, col.len) : val;
if (typeof title == 'function') {
var text = d[col.data];
var split = col.splitStr || ',';
if (text && text.length > 0) {
var lt = text.replace(new RegExp(split, 'gi'), ",");
lt = lt.length > col.len ? lt.substr(0, col.len) : lt;
return '<span title="' + title(d) + '">' + lt + '...</span>';
}
else {
return '';
} }
else if (val && val.length > 0 && val.length > col.len) {
return '<span title="' + (d[title] || val) + '">' + cut + '...</span>';
}
else {
return '<span title="' + (d[title] || val) + '">' + cut + '</span>';
}
}
};
};
//datatables replace html span column
pt.removeHtml = function (val) {
var v = '<p>' + val + '</p>';
return $(v).text();
};
pt.getHtmlLenCol = function (col) {
return {
title: col.title,
data: function (d) {
var val = d[col.data];
if (!val) return val;
var noHtmlVal = pt.removeHtml(val);
var cut = noHtmlVal.length > 0 && noHtmlVal.length > col.len ? noHtmlVal.substr(0, col.len) : noHtmlVal;
return '<span title="' + noHtmlVal + '">' + cut + '...</span>';
}
};
};
//datatables 技术要求
pt.parseTech = function (d, type, full, meta) {
var result = pt.getTechRange(d, true),
len = 25, val = d.TECH_REQUIREMENT; if (!val) return result;
var parseHtmlVal = IQCBase.removeHtml(val);
var cut = '', hasMore = val.indexOf('<table>') > -1;
if (parseHtmlVal.length > 0 && parseHtmlVal.length > len) {
hasMore = true;
cut = parseHtmlVal.substr(0, len);
} else {
cut = parseHtmlVal;
}
result = parseHtmlVal + ' ' + result;
if (hasMore) { cut += '...'; }
return "<span title='" + result + "' data-tech='" + meta.row + "'>" + cut + "</span>";
}; //onclick='$.messager.alert('计数要求','" + parseHtmlVal + "')' pt.getTechCol = function (col) {
return {
title: col.title,
className: col.className,
data: pt.parseTech
};
};
//datatables 检验结果
pt.insprOutOfRange = function (o) {
var hasDefect = false,
currentValue = parseFloat(o.INSPECTION_RESULT),
max = o.OFFSET_VALUE_UP, min = o.OFFSET_VALUE_LOW;
if (IQCBase.isNumeric(max, min)) {
max = parseFloat(max);
min = parseFloat(min);
var sort = IQCBase.sort([min, max]);
hasDefect = currentValue > sort[1] || currentValue < sort[0];
}
else if ($.isNumeric(max) && !$.isNumeric(min)) {
max = parseFloat(max);
hasDefect = currentValue > max
}
else if ($.isNumeric(min) && !$.isNumeric(max)) {
min = parseFloat(min);
hasDefect = currentValue < min;
}
return hasDefect;
};
pt.getISPRCol = function (col) {
return {
title: col.title,
data: function (d, type, full, meta) {
var result, currentValue = d.INSPECTION_RESULT;
if (d.FEATURES == '计量') {
var input = '<input type="text" data-row="{5}" data-name="{0}" data-up="{1}" name="abc" data-low="{2}" value="{3}" title="如该项为不适用项目,请输入\'-\'标识" style="width:50px"{4} {6} />';
var max = d.OFFSET_VALUE_UP, min = d.OFFSET_VALUE_LOW, color = '';
if ($.isNumeric(currentValue)) {
currentValue = parseFloat(currentValue);
color = IQCBase.insprOutOfRange(d) ? ' class="input-danger"' : '';
}
else if (currentValue == '-') { currentValue = currentValue; }
else { currentValue = ''; } result = IQCBase.format(input, 'INSPECTION_RESULT', max, min, currentValue, color, meta.row, col.insDisabled);
} else {
var select = '<select name="abc" data-name="{0}" data-row="{4}" {5}>\
<option value="OK"{1}>OK</option>\
<option value="NG"{2}>NG</option>\
<option value="N/A"{3}>N/A</option>\
</select>';
var selectedObj = { OK: '', NG: '', "N/A": '' };
if (currentValue) {
selectedObj[currentValue] = ' selected="selected"';
} else {
selectedObj['OK'] = ' selected="selected"';
}
result = IQCBase.format(select, 'INSPECTION_RESULT', selectedObj.OK, selectedObj.NG, selectedObj["N/A"], meta.row, col.insDisabled);
}
return result;
}
};
};
pt.getDownFileCol = function (col) {
var colName = col.data;
var obj = {
title: col.title,
className: col.className,
data: function (d, type, full, meta) {
var paramString = '', key = col.key, params = {};
$.each(key, function (i, v) { params[v] = d[v]; });
paramString = $.param(params).replace(/&/g, '&');
var display = '<a href="/Common/FileService/DownLoadFile?id=' + d.ID + '">' + d[colName] + '</a>';
return display;
}
};
return obj;
};
//get all columns
pt.getColumns = function (cols, detailUrl, perfix) {
var dataTablesColumns = [];
for (var i = 0; i < cols.length; i++) {
var col = cols[i];
switch (col.xtype) {
case 'linkTab': dataTablesColumns.push(pt.getLinkTabColumn(col)); break;
case 'link': dataTablesColumns.push(pt.getLinkColumn(col)); break;
case 'enable': dataTablesColumns.push(pt.getEnableCol(col)); break;
case 'htmlencode': dataTablesColumns.push(pt.getHtmlColumn(col)); break;
case 'color': dataTablesColumns.push(pt.getColorCol(col, col.color)); break;
case 'cut': dataTablesColumns.push(pt.getLenCol(col)); break;
case 'cutStanrd': dataTablesColumns.push(pt.getStanrdLenCol(col)); break;
case 'htmlcut': dataTablesColumns.push(pt.getHtmlLenCol(col)); break;
case 'tech': dataTablesColumns.push(pt.getTechCol(col)); break;
case 'ISPR': dataTablesColumns.push(pt.getISPRCol(col)); break;
case 'downFile': dataTablesColumns.push(pt.getDownFileCol(col)); break;
default: dataTablesColumns.push(col);
}
}
return dataTablesColumns;
};
//处理datatables绑定ajax时首次必须加载的问题
pt.ajaxBeforeSend = function (o, tableID, XMLHttpRequest) {
if (o.url.indexOf('QueryNullable') > -1) {
XMLHttpRequest.abort();
$('#' + tableID + '_processing').hide();
}
};
pt.ajaxError = function (o) {
if (o.responseText.indexOf("程序发生了错误,请报告给管理员.") != -1)
IQCBase.showMsg(o.responseText);
else
IQCBase.showMsg('服务器错误');
};
pt.ajaxComplete = function (tableID, area, controller, perfix) {
$('#' + tableID + '_processing').hide();
var table = $('#' + tableID).DataTable().table();
var check = $(table.header()).find('input[name="checkAll"]');
if (check.length > 0) check[0].checked = false;
var linkItems = table.$('a[name="linkCell"]').on('click', function () {
$('body').modalmanager('loading');
var modal = $('#' + perfix + 'DetailDialog');
modal.load('/' + area + '/' + controller + '/Detail', paramString, function () { modal.modal(); });
});
};
//绑定页面Enter键事件
pt.bindKeyup = function () {
var args = arguments;
$(document).keyup(function (e) {
if (e.which == 13) {
var btn = $("[data-keyup='enter']:visible");
if (btn.length > 0) { btn.last().click(); }
}
});
};
pt.registerTechClick = function (perfix) {
var techObjects = $('#' + perfix + 'tbData tbody tr span[data-tech]');
techObjects.on('click', function () {
var rowIndex = $(this).attr('data-tech');
var data = $('#' + perfix + 'tbData').DataTable().rows(rowIndex).data()[0];
if (data) {
var techData = data.TECH_REQUIREMENT;
if (techData && techData.length > 0 && techData.indexOf('<table>') > -1) {
IQCBase.showTech(perfix + 'TechModal', perfix + 'TechField', data);
}
}
});
};
//技术要求弹出框
pt.showTech = function (modelID, fieldID, data) {
var initTemplate = function () {
if ($('#' + modelID).length > 0) { $('#' + modelID).remove(); }
var html = ' \
<div id="{0}" class="modal fade" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true"> \
<div class="modal-dialog">\
<div class="modal-content">\
<div class="modal-header">\
<a class="close" id="close" data-dismiss="modal">×</a>\
<h3 class="modal-title">详细技术要求</h3>\
</div>\
<div class="modal-body">\
<script id="{1}" type="text/plain"></script>\
</div>\
<div class="modal-footer">\
<button class="btn btn-danger" data-dismiss="modal" aria-hidden="true">关闭</button> \
</div>\
</div>\
</div>\
</div>';
$('body').append(pt.format(html, modelID, fieldID));
};
initTemplate();
var modal = $('#' + modelID);
modal.off("shown.bs.modal");
modal.off("hidden.bs.modal");
modal.on("shown.bs.modal", function () {
var editor = UE.getEditor(fieldID, pt.UEConfigDisable);
if (editor) {
var techData = data.TECH_REQUIREMENT;
editor.addListener("ready", function () {
if (data.FEATURES == '计量') {
techData += IQCBase.getTechRange(data);
}
this.setContent(techData);
this.removeListener("ready");
});
}
});
modal.on("hidden.bs.modal", function () {
var editor = UE.getEditor(fieldID);
if (editor) {
editor.destroy();
editor = null;
}
});
modal.modal();
};
//获取技术要求追加的计量范围
pt.getTechRange = function (d, noHtml) {
var result = '';
if (IQCBase.isNumeric(d.OFFSET_VALUE_UP, d.OFFSET_VALUE_LOW)) {
var arr = [parseFloat(d.OFFSET_VALUE_UP), parseFloat(d.OFFSET_VALUE_LOW)];
var arrSort = IQCBase.sort(arr);
result = arrSort[0] + '~' + arrSort[1];
}
else if ($.isNumeric(d.OFFSET_VALUE_UP) && !$.isNumeric(d.OFFSET_VALUE_LOW)) {
result = '≤' + d.OFFSET_VALUE_UP;
}
else if ($.isNumeric(d.OFFSET_VALUE_LOW) && !$.isNumeric(d.OFFSET_VALUE_UP)) {
result = '≥' + d.OFFSET_VALUE_LOW;
}
if (!noHtml) {
result = '<p>' + result + '</p>';
}
return result;
};
pt.INSDetailOnShown = function (editorID, tableID, perfix, iRow, editorDisabled) {
var result = '',
editor = UE.getEditor(editorID, pt.UEConfig);
var childPage = $('#' + perfix + 'DetailForm');
var oData = $('#' + tableID).DataTable().rows(iRow).data();
childPage.find('[name="qrEdit"]').val('1');
if (oData && oData.length > 0) {
var data = oData[0];
var itemTypeSelect = childPage.find('[name="txtITEM_TYPE"]');
if (itemTypeSelect.children('option[value="' + data.ITEM_TYPE + '"]').length == 0) {
var option = '<option value="{0}">{0}</option>';
itemTypeSelect.append(pt.format(option, data.ITEM_TYPE));
}
pt.setForm(childPage, data, perfix);
childPage.find('[name="txtSEQ"]').val(data.SEQ);
childPage.find('[name="txtITEM_NAME_OLD"]').val(data.ITEM_NAME);
childPage.find('[name="txtITEM_TYPE_OLD"]').val(data.ITEM_TYPE);
childPage.find('[name="txtCHECK_TYPE_OLD"]').val(data.CHECK_TYPE); childPage.find('[name="txtSTANDARD_VALUE"][value="' + data.STANDARD_VALUE + '"]').prop("checked", true);
childPage.find('[name="txtFIX_NUM"]').val(data.FIX_NUM);
childPage.find('[name="txtAC_VALUE"]').val(data.AC_VALUE);
childPage.find('[name="txtRE_VALUE"]').val(data.RE_VALUE); childPage.find('[name="txtSTANDARD_VALUE"][value="' + data.INSPECTION_LEVEL + '"]').prop("checked", true); var selector = '[name="txtOFFSET_VALUE_LOW"],[name="txtOFFSET_VALUE_UP"],[name="txtUNIT"]';
var $spanTech = childPage.find('span.tech-must');
if (data.FEATURES == '计量') {
$spanTech.show();
//childPage.find(selector).removeAttr('disabled');
result = IQCBase.getTechRange(data);
childPage.find('[name="qrTechReplace"]').val(result); if (editorDisabled) {
if (childPage.find('[name="txtOFFSET_VALUE_LOW"]').val() != "") { childPage.find('[name="txtOFFSET_VALUE_LOW"]').prop('disabled', true); }
if (childPage.find('[name="txtOFFSET_VALUE_UP"]').val() != "") { childPage.find('[name="txtOFFSET_VALUE_UP"]').prop('disabled', true); }
} } else {
//if (editorDisabled) {
// if (childPage.find('[name="txtOFFSET_VALUE_LOW"]').val() != "") { childPage.find('[name="txtOFFSET_VALUE_LOW"]').prop('disabled', true); }
// if (childPage.find('[name="txtOFFSET_VALUE_UP"]').val() != "") { childPage.find('[name="txtOFFSET_VALUE_UP"]').prop('disabled', true); }
//}
childPage.find(selector).prop('disabled', true);
$spanTech.hide();
}
if (editor) {
editor.addListener("ready", function () {
if (data.TECH_REQUIREMENT) {
result = data.TECH_REQUIREMENT + result;
}
this.setContent(result);
//if (editorDisabled) {
// this.setDisabled();
//}
this.removeListener("ready");
});
}
}
};
//导出Excel
pt.getExportCols = function (tableID) {
var columns = pt.columns[tableID];
var arrKeyValue = [];
for (var i = 0; i < columns.length; i++) {
if (!columns[i].noExport) {
var col = columns[i];
if (typeof (col.data) == 'string') {
arrKeyValue.push(col.data + ',' + col.title);
}
else if (typeof (col.name) == 'string') {
arrKeyValue.push(col.name + ',' + col.title);
}
} }
return arrKeyValue.join('$');
};
pt.downloadExcel = function (param, url) { if ($('#iframeExport').length < 1) {
if (document.domain && document.domain != "") {
var ifr = document.createElement("iframe");
ifr.id = "iframeExport";
ifr.src = "javascript:void((function(){var d=document;d.open();d.domain='" + document.domain + "';d.write('');d.close()})())";
ifr.style.display = "none";
document.body.appendChild(ifr);
}
else
$('body').append('<iframe id="iframeExport" style="display:none;"></iframe>');
} //var $iframe = $('<iframe id="iframeExport" name="iframeExport" style="display:none;"></iframe>');
//if ($('#iframeExport').length < 1) {
// $('body').append($iframe);
//} setTimeout(function () {
var form = $('<form name="exportForm" id="exportForm" action="' + url + '" method="post"></form>');
$.each(param, function (i, val) {
if (val instanceof Array) {
$.each(val, function (j, v) {
$.each(v, function (k, kv) {
form.append('<input type="hidden" name="' + i + '[' + j + '][' + k + ']" value="' + kv + '" />');
}); });
}
else if (val.length > 0) { form.append('<input type="hidden" name="' + i + '" value="' + val + '" />');
}
}); var body = $($('#iframeExport')[0].contentWindow.document.body);
if (body.length < 1) {
$iframe.load(function () { //fix IE9 before issue
body = $($('#iframeExport')[0].contentWindow.document.body);
body.html(form[0].outerHTML);
body.find('#exportForm').submit();
});
}
else {
body.html(form[0].outerHTML);
body.find('#exportForm').submit();
}
}, 200); };
pt.onConfirmExport = function (table, url, queryPanel, queryObjectPerfix, ableOrder) {
debugger;
var param = table.ajax.params();
var params = IQCBase.getQueryParams(queryPanel, queryObjectPerfix, param, ableOrder);
params.param['headers'] = IQCBase.getExportCols(table.settings()[0].sTableId);
IQCBase.downloadExcel(params.param, url);
};
pt.iFrameOnload = function (iframe) {
if (iframe.attachEvent) {
iframe.attachEvent("onload", function () {
alert("Local iframe is now loaded.");
});
} else {
iframe.onload = function () {
alert("Local iframe is now loaded.");
};
}
};
pt.exportExcel = function (table, url, queryPanel, queryObjectPerfix) {
var initTemplate = function () {
if ($('#iframeExport').length < 1) {
if (document.domain && document.domain != "") {
var ifr = document.createElement("iframe");
ifr.id = "iframeExport";
ifr.src = "javascript:void((function(){var d=document;d.open();d.domain='" + document.domain + "';d.write('');d.close()})())";
ifr.style.display = "none";
document.body.appendChild(ifr);
}
else
$('body').append('<iframe id="iframeExport" style="display:none;"></iframe>');
} if ($('#ExportExcelDialog').length < 1) {
$('body').append('<iframe id="iframeExport" style="display:none;"></iframe>\
<div id="ExportExcelDialog" class="modal fade" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="false">\
<div class="modal-dialog">\
<div class="modal-content">\
<div class="modal-header">提示</div>\
<div class="modal-body">\
<p>是否要导出Excel</p>\
</div>\
<div class="modal-footer text-right">\
<button class="btn btn-primary" data-dismiss="modal" data-keyup="enter">导出Excel</button>\
<button class="btn-danger" data-dismiss="modal">取消</button>\
</div>\
</div>\
</div>\
</div>');
}
}
var bootStrapConfirm = function () {
if (!$.fn.modal.Constructor)
return false; $('body').off('click', '#ExportExcelDialog .btn-primary'); function confirm() {
var params = IQCBase.getQueryParams(queryPanel, queryObjectPerfix, table.ajax.params());
params.param['headers'] = IQCBase.getExportCols(table.settings()[0].sTableId);
IQCBase.downloadExcel(params.param, url);
}
$('body').on('click', '#ExportExcelDialog .btn-primary', confirm);
return true;
}
initTemplate(); if (bootStrapConfirm()) {
$('#ExportExcelDialog').modal();
} else {
alert('bootstrap was not found');
}
};
})();
window.IQCBase = new IQCBase();
//
js封装包的更多相关文章
- SQLite C++ Wrapper 是一个 C++ 语言对 SQLite 的最小封装包。
SQLite C++ Wrapper 是一个 C++ 语言对 SQLite 的最小封装包. 示例代码1: #include <string> #include <iostream ...
- JS封深入了解
1. javascript 语言理解闭包 js变量的范围分成两个:全局变量.局部变量.在全局变量的函数外声明变量,内部功能可以直接调用全局变量.声明变量里面的函数必须使用var 命令,否则,它里面的函 ...
- rpm封装包,只用于记录自己过程,不适合初学者看,请看参考链接
参考http://www.worldhello.net/2011/04/02/2405.html http://www.ibm.com/developerworks/cn/linux/manageme ...
- js封常用类
ajax刷 下拉框联动 /*基础初始化类*/ $.EBC = { setCourse:function(obj){ $(obj).empty(); $.get('../Index/getCoursei ...
- 一个画ROC曲线的封装包
Draw_ROC_Curves This is a python file which is used for drawing ROC curves -f : assign file name -t ...
- JQuery的$和其它JS发生冲突的快速解决方法
众所周知,jQuery是目前最流行的JS封装包,简化了很多复杂的JS程序,JQuery讲浏览器DOM树定义为$,通过$来获取各个子节点. 然后,JS插件并非只有JQuery,还有prototype.j ...
- 两个js冲突怎么解决?试试这四个方法
两个js冲突很让前端头疼,虽然jquery是通用的,但调用不同经常会出问题.jQuery是目前流行的JS封装包,简化了很多复杂的JS程序,JQuery讲浏览器DOM树定义为$,通过$来获取各个子节点. ...
- [转]为什么我要用 Node.js? 案例逐一介绍
原文地址:http://blog.jobbole.com/53736/ 介绍 JavaScript 高涨的人气带来了很多变化,以至于如今使用其进行网络开发的形式也变得截然不同了.就如同在浏览器中一样, ...
- 【转】为什么我要用 Node.js? 案例逐一介绍
原文转自:http://blog.jobbole.com/53736/ 介绍 JavaScript 高涨的人气带来了很多变化,以至于如今使用其进行网络开发的形式也变得截然不同了.就如同在浏览器中一样, ...
随机推荐
- Mysqli封装
<?php //headerheader('content-type:text/html;charset=UTF-8'); class DB { //定义属性 private $ho ...
- Excel常用操作
[对Excel工作表,按某一列数据进行排序] 选中这些数据,在菜单栏上点"数据 - 排序",在弹出的窗口中的主要关键字里选择这一列,按升序或降序,那么其它的数据也会跟着它一一对应变 ...
- MySql的max_connections和max pool的设置
这几天工作当中,在使用mysql数据库的时候,碰到了too many connections的问题和timeout expired的问题,经过尝试,稍作总结,希望能够帮到需要的朋友; 在测试当中发现, ...
- css声明应用优先级
1.特殊性 选择器的特殊值由四部分组成:0,0,0,0 第一位预留给内联样式 <h1 style="color:red;"></h1> 第二位属于ID选 ...
- .net 过滤特殊字符
/// <summary> /// 过滤标记 /// </summary> /// <param name="NoHTML">包括HTML,脚本 ...
- C#求任意范围内的质数
class Program { public static List<int> list; static void Main(string[] args) { Console.WriteL ...
- HttpModule的认识
1.asp.net的HTTP请求处理过程 说明: (1).客户端浏览器向服务器发出一个http请求,此请求会被inetinfo.exe进程截获,然后转交给aspnet_isapi.dll进程,接着它又 ...
- Javascript 事件对象(四)一个事件绑定多个不同的函数
给一个对象绑定多个事件处理函数: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-T ...
- JavaScript闭包模型
JavaScript闭包模型 ----- [原创翻译]2016-09-01 09:32:22 < 一> 闭包并不神秘 本文利用JavaScript代码来阐述闭包,目的是为了使普通 ...
- capwap协议重点分析
一. CAPWAP概述 CAPWAP由两个部分组成:CAPWAP协议和无线BINDING协议. (1)CAPWAP协议是一个通用的隧道协议,完成AP发现AC等基本协议功能,和具体的无线接入技术 ...