//================================ global ====================================//
|
pageArray = [];
|
senderPage = null;
|
serverAddress = "http://localhost:8080/cbi/";
|
netErrorPage = "/cbi/www/netError.html";
|
jsonErrorPage = "/cbi/www/jsonError.html";
|
//何飞侠增加
|
//jumpPageId = null;
|
jumpStr = null;
|
var xmlHttp;
|
|
var browser={
|
versions:function(){
|
var u = navigator.userAgent, app = navigator.appVersion;
|
return {
|
trident: u.indexOf('Trident') > -1, //IE内核
|
presto: u.indexOf('Presto') > -1, //opera内核
|
webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
|
gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,//火狐内核
|
mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
|
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
|
android: u.indexOf('Android') > -1 || u.indexOf('Adr') > -1, //android终端
|
iPhone: u.indexOf('iPhone') > -1 , //是否为iPhone或者QQHD浏览器
|
iPad: u.indexOf('iPad') > -1, //是否iPad
|
webApp: u.indexOf('Safari') == -1, //是否web应该程序,没有头部与底部
|
weixin: u.indexOf('MicroMessenger') > -1, //是否微信 (2015-01-22新增)
|
qq: u.match(/\sQQ/i) == " qq" //是否QQ
|
};
|
}(),
|
language:(navigator.browserLanguage || navigator.language).toLowerCase()
|
};
|
|
refreshPage = function() {
|
|
var refreshTo = window.top.window.location.href;
|
window.top.window.location.href = refreshTo;
|
|
//pageTo(jumpPageId);
|
}
|
|
Date.prototype.format = function(fmt) {
|
var o = {
|
"M+" : this.getMonth()+1, //月份
|
"d+" : this.getDate(), //日
|
"h+" : this.getHours(), //小时
|
"m+" : this.getMinutes(), //分
|
"s+" : this.getSeconds(), //秒
|
"q+" : Math.floor((this.getMonth()+3)/3), //季度
|
"S" : this.getMilliseconds() //毫秒
|
};
|
if (/(y+)/.test(fmt)) {
|
fmt = fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
|
}
|
for (var k in o){
|
if (new RegExp("("+ k +")").test(fmt)) {
|
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
|
}
|
}
|
return fmt;
|
}
|
|
function isWide() {
|
var result = $(window).width() >= 640;
|
|
return result;
|
}
|
|
function getInfo(){
|
if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
|
} else {
|
try {
|
Dialog.alert("网络连接超时,请刷新");
|
if (console.log) {
|
console.log(error);
|
}
|
}
|
catch (e) {
|
|
}
|
}
|
}
|
|
function jumpTo(target) {
|
/* var url = target;
|
|
if(window.XMLHttpRequest){
|
xmlHttp = new XMLHttpRequest();
|
}else{
|
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
|
}
|
|
xmlHttp.onreadystatechange = getInfo;
|
xmlHttp.open("GET", url);
|
xmlHttp.send(null);*/
|
window.location.href = target;
|
|
}
|
|
jQuery.fn.onShow = function(fun){
|
this.data("onShow", fun);
|
}
|
|
//何飞侠增加
|
jQuery.fn.onRedirect = function(fun){
|
this.data("onRedirect", fun);
|
}
|
//*页面跳转
|
function pageTo(target, frontway){
|
if (target && target.is(":animated")){
|
return;
|
}
|
|
senderPage = target;
|
|
/* if (jumpStr) {
|
eval(jumpStr);
|
}*/
|
|
var prior = null;
|
if (pageArray.length > 0) {
|
prior = pageArray[pageArray.length - 1];
|
}
|
|
if (prior && prior.is(":animated")){
|
|
return;
|
|
}
|
|
var onShow = target.data("onShow");
|
if (onShow) { onShow(); }
|
|
target.frontway = frontway;
|
pageArray.push(target);
|
|
if (isWide() || !prior) {
|
if (prior && !prior.frontway) {
|
prior.hide();
|
}
|
target.fadeIn(300);
|
}
|
else {
|
|
var width = $(window).width(), halfWidth = Math.floor(width / 2);
|
|
target.css({left: width, right: -width});
|
target.show();
|
target.animate({left:0, right:0}, 300);
|
|
prior.css({left:0, right:0});
|
prior.animate({left: -halfWidth, right: halfWidth}, 300, function() {
|
prior.hide();
|
prior.css({left:0, right:0});
|
});
|
}
|
|
if($("div").hasClass('to_02')){
|
$("#toMenu").trigger("click");
|
}
|
|
}
|
|
function pageBackIframe(){
|
var next = window.parent.pageArray.pop();
|
var target = window.parent.pageArray[window.parent.pageArray.length - 1];
|
|
var onClose = next.data("onClose");
|
if (onClose) { onClose(); }
|
|
var onShow = target.data("onShow");
|
if (onShow) { onShow(); }
|
|
var onRedirect = target.data("onRedirect");
|
if(onRedirect){
|
onRedirect();
|
};
|
|
if (isWide()) {
|
next.hide();
|
if (!target.frontway) {
|
target.fadeIn(300);
|
}
|
}
|
else {
|
if (next.is(":animated")) {
|
next.stop(true, true);
|
}
|
if (target.is(":animated")) {
|
target.stop(true, true);
|
}
|
|
var width = $(window).width(), halfWidth = Math.floor(width / 2);
|
|
next.css({left:"0", right:"0"});
|
next.animate({left: width, right: -width}, 300, function(){
|
next.hide();
|
next.css({left:"0", right:"0"});
|
});
|
|
target.css({left: -halfWidth, right: halfWidth});
|
target.show();
|
target.animate({left:"0", right:"0"}, 300);
|
}
|
}
|
|
function pageBack() {
|
var next = pageArray.pop();
|
var target = pageArray[pageArray.length - 1];
|
|
var onClose = next.data("onClose");
|
if (onClose) { onClose(); }
|
|
var onShow = target.data("onShow");
|
if (onShow) { onShow(); }
|
|
var onRedirect = target.data("onRedirect");
|
if(onRedirect){
|
onRedirect();
|
};
|
|
if (isWide()) {
|
next.hide();
|
if (!target.frontway) {
|
target.fadeIn(300);
|
}
|
}
|
else {
|
if (next.is(":animated")) {
|
next.stop(true, true);
|
}
|
if (target.is(":animated")) {
|
target.stop(true, true);
|
}
|
|
var width = $(window).width(), halfWidth = Math.floor(width / 2);
|
|
next.css({left:"0", right:"0"});
|
next.animate({left: width, right: -width}, 300, function(){
|
next.hide();
|
next.css({left:"0", right:"0"});
|
});
|
|
target.css({left: -halfWidth, right: halfWidth});
|
target.show();
|
//target.animate({left:"0", right:"0"}, 300, "linear", callback);
|
target.animate({left:"0", right:"0"}, 300);
|
if (target[0].children.enableTitle) {
|
try {
|
if (browser.versions.ios) {
|
window.webkit.messageHandlers.runJavaScriptWithShowMessage.backButtonAppearWithJS();
|
} else if (browser.versions.android) {
|
window.adnroidVisible.Visiable();
|
}
|
|
} catch (e) {
|
}
|
}
|
}
|
|
$("#toMenu").trigger("click");
|
}
|
|
function getSessionData(name) {
|
var data = sessionStorage.getItem(name);
|
return data ? JSON.parse(data) : null;
|
};
|
|
function setSessionData(name, value) {
|
try {
|
sessionStorage.setItem(name, JSON.stringify(value));
|
} catch (e) { }
|
};
|
|
function getLocalData(name) {
|
var data = localStorage.getItem(name);
|
return data ? JSON.parse(data) : null;
|
};
|
|
function setLocalData(name, value) {
|
try {
|
localStorage.setItem(name, JSON.stringify(value));
|
} catch (e) { }
|
};
|
|
function rateRender(rowdata, index, value) {
|
if (!value) { return "0"; }
|
return value + "%";
|
}
|
|
function assignTo(source, dest) {
|
for (var prop in dest) {
|
delete dest[prop];
|
}
|
|
$.extend(dest, source);
|
}
|
|
function fmoney(s, n) {
|
n = n >= 0 && n <= 20 ? n : 2;
|
s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
|
var l = s.split(".")[0].split("").reverse(),
|
r = s.split(".")[1];
|
t = "";
|
for(var i = 0; i < l.length; i ++ )
|
{
|
t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
|
}
|
if(n == 0){
|
return t.split("").reverse().join("");//+ "." + r;
|
}else{
|
return t.split("").reverse().join("")+ "." + r;
|
}
|
}
|
|
(function ($) {
|
//=========================================================================//
|
|
$.fm = {
|
decode: function (obj) {
|
if (!obj) {
|
return null;
|
}
|
|
if ($.isArray(obj)) {
|
return this.decodeArray(obj);
|
}
|
else if (typeof obj == "object") {
|
return this.decodeObject(obj);
|
}
|
else if (typeof obj == "string") {
|
try{
|
return 3(obj);
|
}catch(e){
|
try{
|
return obj;
|
}catch(e){
|
}
|
}
|
}
|
else {
|
return obj;
|
}
|
},
|
|
decodeArray: function(data) {
|
for (var i = 0; i < data.length; i++) {
|
if (data[i]) {
|
this.decodeObject(data[i]);
|
}
|
}
|
|
return data;
|
},
|
|
decodeObject: function(data) {
|
for (var prop in data) {
|
if (data[prop]) {
|
data[prop] = this.decode(data[prop]);
|
}
|
}
|
|
return data;
|
},
|
|
encode: function(obj) {
|
if ($.isArray(obj)) {
|
return this.encodeArray(obj);
|
}
|
else if (typeof obj == "object") {
|
return this.encodeObject(obj);
|
}
|
else if (typeof obj == "string") {
|
return '"' + obj + '"';
|
}
|
else if (typeof obj == "boolean") {
|
return String(obj);
|
}
|
else if (typeof obj == "number") {
|
return String(obj);
|
}
|
else if (typeof obj === "function") {
|
return "";
|
}
|
},
|
|
encodeArray: function(o) {
|
var a = ["[", ""],
|
|
len = o.length,
|
i;
|
for (i = 0; i < len; i += 1) {
|
a.push(this.encode(o[i]), ',');
|
}
|
|
a[a.length - 1] = ']';
|
return a.join("");
|
},
|
|
encodeObject: function(o) {
|
if (!o) {
|
return "null";
|
}
|
if (o.length) {
|
return "el";
|
}
|
var a = ["{", ""];
|
|
for (var i in o) {
|
if (i == 'parent') {
|
continue;
|
}
|
a.push(this.encode(i), ":", this.encode(o[i]), ',');
|
}
|
|
a[a.length - 1] = '}';
|
return a.join("");
|
},
|
|
objectToURI: function(object) {
|
var param = null;
|
|
for (var prop in object) {
|
if (object[prop]) {
|
if (param) {
|
param = param + "&" + prop + "=" + encodeURI(object[prop]);
|
}
|
else {
|
param = prop + "=" + encodeURI(object[prop]);
|
}
|
}
|
}
|
|
return param;
|
},
|
|
formatBarcode: function(value) {
|
if (!value) {
|
return value;
|
}
|
|
var pos = value.indexOf(",");
|
if (pos > 0) {
|
value = value.substring(pos + 1);
|
}
|
|
return value;
|
},
|
|
S4 : function(){
|
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
},
|
|
guid : function(){
|
return (this.S4() + this.S4() + this.S4() + this.S4() + this.S4() + this.S4() + this.S4() + this.S4());
|
}
|
};
|
|
Object.init = function(options) {
|
if (prototyping) {
|
return;
|
}
|
|
if (options) {
|
var name = null, value;
|
|
for (name in options) {
|
value = options[name];
|
this[name] = value;
|
}
|
}
|
};
|
|
Object.subClass = function(properties) {
|
if (!properties) {
|
return;
|
}
|
|
var clazz = properties.init;
|
delete properties.init;
|
|
if (!clazz) {
|
clazz = new Function();
|
}
|
|
prototyping = true;
|
try {
|
var prototype = new this();
|
}
|
finally {
|
prototyping = false;
|
}
|
|
$.extend(prototype, properties);
|
|
clazz.prototype = prototype;
|
clazz.subClass = arguments.callee;
|
|
return clazz;
|
};
|
|
var ServerClass = Object.subClass({
|
dataNames: ["line", "dataset", "Rows", "tree", "user"],
|
sysParams: {
|
|
},
|
|
ajaxRequest: function(url, param, callback, onSuccess, type) {
|
if (param) {
|
if ($.isFunction(param)) {
|
callback = param;
|
param = null;
|
}
|
else {
|
if(typeof(param) == "string"){
|
url = url + "?" + param;
|
}
|
else if(typeof(param) == "object"){
|
param = $.fm.objectToURI(param);
|
url = url + "?" + param;
|
}
|
}
|
}
|
|
//url = serverAddress + url;
|
type = type || 'post';
|
|
$.ajax(url, {
|
type: type,
|
dataType: 'json',
|
success: function(result) {
|
if (result && result.errorcode) {
|
window.top.location.href = netErrorPage;
|
}
|
|
if (result.timeout) {
|
window.top.location.href = $.fm.decode(result.timeoutPage);
|
return;
|
}
|
|
onSuccess(callback, result);
|
},
|
error: function(d1, error, message) {
|
try {
|
if (error == "parsererror"){
|
window.top.location.href = jsonErrorPage;
|
return;
|
}
|
//window.top.location.href = netErrorPage;
|
|
if (browser.versions.ios) {
|
alert("网络不稳定,请稍后再试");
|
Loading.hide();
|
//window.location.href = netErrorPage;
|
} else if (browser.versions.android) {
|
window.top.location.href = netErrorPage;
|
} else {
|
window.top.location.href = netErrorPage;
|
}
|
|
if (console.log) {
|
console.log(error);
|
}
|
}
|
catch (e) {
|
}
|
}
|
});
|
},
|
|
getResultData: function(result) {
|
if (!result) return;
|
|
for (var i = 0; i < this.dataNames.length; i++) {
|
var name = this.dataNames[i];
|
|
if (result[name]) {
|
var data = result[name];
|
return $.fm.decode(data);
|
}
|
}
|
},
|
|
newObject: function(vtableName, me, callBack, asynchroniz) {
|
var url = serverAddress + vtableName + '.newRecord.do';
|
|
$.ajax(url, {
|
type: 'get',
|
async: asynchroniz,
|
success: function(data){
|
if (data.success) {
|
if (callBack) {
|
var object = data.object;
|
callBack.call(me, object);
|
}
|
}
|
else if (data.invalidUser) {
|
document.location = data.url;
|
}
|
else if (data.execError) {
|
alert('exec error:' + data.execError.message);
|
}
|
else if (data.dataError) {
|
alert('data error:' + data.dataError.message);
|
}
|
}
|
});
|
},
|
|
saveData: function(url, data, callback) {
|
var me = this;
|
if (!url || !data) {return;}
|
|
var param = $.fm.objectToURI(data);
|
url = serverAddress + url;
|
|
me.ajaxRequest(url, param, callback, function(doCallback, result) {
|
// if (doCallback) {
|
// callback(result.success);
|
// }
|
if (doCallback) {
|
callback(result);
|
}
|
});
|
},
|
|
getData: function(url, param, callback) {
|
if (!url) {return;} var me = this;
|
url = serverAddress + url;
|
|
me.ajaxRequest(url, param, callback, function(doCallback, result) {
|
if (doCallback) {
|
var data = me.getResultData(result);
|
if (data){
|
doCallback(data);
|
} else {
|
doCallback(result);
|
}
|
}
|
});
|
},
|
|
deleteById: function(url, data, callback, asynchroniz) {
|
if (!url) {return;} var me = this;
|
|
var id = 'string' == typeof (data) ? data : data.id;
|
url = serverAddress + url + '?id=' + id;
|
|
me.ajaxRequest(url, param, callback, function(doCallback, result) {
|
if (doCallback) {
|
doCallback.call({}, data.success);
|
}
|
}, "get");
|
},
|
|
call: function(url, param, callback, asynchroniz) {
|
if (!url) {return;} var me = this;
|
|
url = serverAddress + url;
|
me.ajaxRequest(url, param, callback, function(doCallback, result) {
|
if (doCallback) {
|
result = $.fm.decode(result);
|
return doCallback(result);
|
}
|
});
|
}
|
});
|
|
Server = $.fm.Server = new ServerClass();
|
|
DateTime = $.fm.DateTime = Object.subClass({
|
|
init: function(millisecond) {
|
if (prototyping) {
|
return;
|
}
|
|
this.date = millisecond ? new Date(millisecond) : new Date();
|
this.parseField();
|
},
|
|
parseField: function() {
|
this.year = this.date.getFullYear();
|
this.month = this.date.getMonth() + 1;
|
this.day = this.date.getDate();
|
this.week = this.date.getDay();
|
this.str = this.year + (this.month <10 ? "-0" : "-") + this.month + (this.day <10 ? "-0" : "-") + this.day;
|
this.ms = Date.parse(this.date);
|
},
|
|
clone: function() {
|
var result = new DateTime(this.ms);
|
return result;
|
},
|
|
setDate: function(value) {
|
this.date.setDate(value);
|
this.parseField();
|
},
|
|
incDate: function() {
|
this.ms = this.ms + 1000 * 60 * 60 * 24;
|
this.date = new Date(this.ms);
|
this.parseField();
|
},
|
|
incMonth: function(value) {
|
if (value > 0) {
|
var beginMonth = this.date.getMonth(), beginDate = this.day, beginYear = this.year;
|
var currMonth = this.date.getMonth(), currDate = 1, currYear = this.date.getFullYear();
|
|
while ((currYear - beginYear) * 12 + (currMonth - beginMonth) < value) {
|
this.ms = this.ms + 1000 * 60 * 60 * 24;
|
this.date = new Date(this.ms);
|
currMonth = this.date.getMonth();
|
currYear = this.date.getFullYear();
|
}
|
|
while (currDate < beginDate) {
|
this.ms = this.ms + 1000 * 60 * 60 * 24;
|
this.date = new Date(this.ms);
|
currDate = this.date.getDate();
|
}
|
|
this.parseField();
|
}
|
else if (value < 0) {
|
var beginMonth = this.date.getMonth(), beginDate = this.day, beginYear = this.year;
|
var currMonth = this.date.getMonth(), currYear = this.date.getFullYear();
|
|
while (((currYear - beginYear) * 12 + (currMonth - beginMonth)) > value) {
|
this.ms = this.ms - 1000 * 60 * 60 * 24;
|
this.date = new Date(this.ms);
|
currMonth = this.date.getMonth();
|
currYear = this.date.getFullYear();
|
}
|
|
currDate = this.date.getDate();
|
|
while (currDate > beginDate) {
|
this.ms = this.ms - 1000 * 60 * 60 * 24;
|
this.date = new Date(this.ms);
|
currDate = this.date.getDate();
|
}
|
|
this.parseField();
|
}
|
},
|
|
toMonthBegin: function() {
|
this.date.setDate(1);
|
this.date.setHours(0, 0 , 0, 1);
|
this.parseField();
|
},
|
|
toMonthEnd: function() {
|
this.date.setDate(1);
|
this.date.setHours(0, 0 , 0, 1);
|
|
var month = this.date.getMonth();
|
if (month < 11) {
|
this.date.setMonth(month + 1);
|
}
|
else {
|
this.date.setYear(this.date.getFullYear() + 1);
|
this.date.setMonth(0);
|
this.date.setDate(1);
|
}
|
|
this.parseField();
|
},
|
|
toStr: function() {
|
return this.year + (this.month <10 ? "-0" : "-") + this.month + (this.day <10 ? "-0" : "-") + this.day;
|
}
|
});
|
|
//================================Control===================================//
|
Control = $.fm.Control = Object.subClass({
|
|
init: function(options) {
|
if (prototyping) {
|
return;
|
}
|
|
Object.init.call(this, options);
|
this.createCanvas(options);
|
},
|
|
createCanvas: function(options) {
|
if (!this.element) {
|
this.canvas = $("body");
|
return;
|
}
|
|
this.getEl();
|
this.canvas = this.element;
|
},
|
|
averageTo: function(total, size) {
|
if (size <= 0) {
|
return null;
|
}
|
|
var result = new Array(size);
|
var max = size - 1;
|
var value = Math.floor(total / size);
|
var sum = 0;
|
|
for (var i = 0; i < max; i++) {
|
result[i] = value;
|
sum = sum + value;
|
}
|
|
result[max] = total - sum;
|
return result;
|
},
|
|
getEl: function() {
|
var element = this.element;
|
|
if (typeof element == "string") {
|
if ("#" != element.substring(0, 1)) {
|
element = "#" + element;
|
}
|
|
this.element = $(element);
|
return;
|
}
|
},
|
});
|
|
//================================Record===================================//
|
Record = $.fm.Record = Control.subClass ({
|
|
init: function(options) {
|
this.datalink = {};
|
this.labellink = {};
|
this.imglink = {};
|
this.selectlink = {};
|
this.data = {};
|
this.editClasss = ["input", "textarea"];
|
|
Control.call(this, options);
|
|
this.linkTo(this.element);
|
this.publishData();
|
},
|
|
clear: function() {
|
this.datalink = {};
|
this.labellink = {};
|
this.imglink = {};
|
this.selectlink = {};
|
},
|
|
linkTo: function(element) {
|
this.clear();
|
if (!element) return;
|
|
for (var no in this.editClasss) {
|
var editClass = this.editClasss[no];
|
var valueEl = $(editClass, element);
|
this.doLinkTo(valueEl, this.datalink);
|
}
|
|
var valueEl = $("select", element);
|
this.doLinkTo(valueEl, this.selectlink);
|
|
var valueEl = $("#label", element);
|
this.doLinkTo(valueEl, this.labellink);
|
|
var valueEl = $("#img", element);
|
this.doLinkTo(valueEl, this.imglink);
|
},
|
|
doLinkTo: function(valueEl, link) {
|
for (var i = 0; i < valueEl.length; i++) {
|
var item = $(valueEl.get(i));
|
var name = item.attr("name");
|
|
if (name) {
|
link[name] = item;
|
}
|
}
|
|
this.publishData();
|
},
|
|
setData: function(data) {
|
this.data = data;
|
},
|
|
setValue: function(name, value) {
|
this.data[name] = value;
|
},
|
|
publishData: function() {
|
if (!this.data) return;
|
|
for (var name in this.datalink) {
|
this.datalink[name].val(this.data[name]);
|
}
|
|
for (var name in this.selectlink) {
|
var link = this.selectlink[name];
|
var value = this.data[name];
|
if (!value) { continue; };
|
var option = $("option[value='" + value + "']", link);
|
option.attr("selected", "selected");
|
}
|
|
for (var name in this.labellink) {
|
this.labellink[name].html(this.data[name]);
|
}
|
|
for (var name in this.imglink) {
|
try{
|
if(this.data[name].indexOf("imagelib") > 0){
|
this.imglink[name].attr("src", serverAddress+"a/" + this.data[name]);
|
}else{
|
this.imglink[name].attr("src", this.data[name]);
|
}
|
}catch(e){
|
this.imglink[name].attr("src", this.data[name]);
|
}
|
|
}
|
},
|
|
setEditable: function(editable) {
|
for (var name in this.datalink) {
|
if (editable) {
|
this.datalink[name].removeAttr("readonly");
|
}
|
else {
|
this.datalink[name].attr("readonly", "readonly");
|
}
|
}
|
},
|
|
getData: function() {
|
var result = this.data || {};
|
|
for (var name in this.datalink) {
|
var link = this.datalink[name];
|
var value = link.val();
|
|
if (!value || value == "") { continue; };
|
result[name] = value;
|
}
|
|
for (var name in this.selectlink) {
|
var link = this.selectlink[name];
|
var value = $("option:selected", link).val();
|
|
if (!value || value == "") { continue; };
|
result[name] = value;
|
}
|
|
return result;
|
},
|
|
validate: function() {
|
for (var name in this.datalink) {
|
var link = this.datalink[name];
|
var required = link.attr("require");
|
|
if (required) {
|
var value = link.val();
|
if (!value) {
|
Dialog.alert("请填写“" + required + "”");
|
return false;
|
}
|
}
|
}
|
|
return true;
|
}
|
|
});
|
|
//================================Filter===================================//
|
Filter = $.fm.Filter = Control.subClass ({
|
init: function(options) {
|
this.links = [];
|
this.defaultValue = "";
|
|
Control.call(this, options);
|
this.createLink();
|
},
|
|
createLink: function() {
|
if (!this.element) {
|
return;
|
}
|
|
this.linkElements("input");
|
this.linkElements("select");
|
},
|
|
linkElements: function(elName) {
|
var els = $(elName, this.element);
|
|
for (var i = 0; i < els.length; i++) {
|
var el = $(els.get(i));
|
var name = el.attr("name");
|
|
if (!name) {
|
continue;
|
}
|
|
el.fieldName = name;
|
el.operator = el.attr("operator");
|
|
this.links.push(el);
|
}
|
},
|
|
clear: function() {
|
for (var i = 0; i < this.links.length; i++) {
|
this.links[i].val("");
|
}
|
},
|
|
toURL: function(page) {
|
var result = null;
|
|
var filter = this.defaultValue;
|
var empty = this.defaultValue == "";
|
|
for (var i = 0; i < this.links.length; i++) {
|
var link = this.links[i];
|
var value = link.val();
|
|
if (!value || value == "") {
|
continue;
|
};
|
|
if (!empty) {
|
filter = filter + " and ";
|
}
|
|
if (link["operator"] == "like") {
|
filter = filter + link["fieldName"] + " like '%" + value + "%'";
|
}
|
else {
|
filter = filter + link["fieldName"] + " = '" + value + "'";
|
}
|
|
empty = false;
|
}
|
|
if (filter) {
|
result = "filter=" + encodeURI(filter);
|
}
|
|
if (page) {
|
result = result ? result + "&" + page.toURL() : page.toURL();
|
}
|
|
return result;
|
}
|
});
|
|
//===============================Navigator=================================//
|
Navigator = $.fm.Navigator = Control.subClass({
|
template: [
|
'<div class="navigator">',
|
'<div class="navigator-prior" id="btn_prior"></div>',
|
'<input class="navigator-text" value="共0条, 每页10条, 第1页" id="btn_text"></input>',
|
'<div class="navigator-next" id="btn_next"></div>',
|
'</div>'
|
],
|
|
init: function(options) {
|
this.buttons = {};
|
this.page = new $.fm.Page();
|
this.subscribers = [];
|
|
options = options ? options : {};
|
Control.call(this, options);
|
|
if (this.control) {
|
this.subscribers.push(this.control);
|
}
|
this.initButtons();
|
},
|
|
initButtons: function() {
|
var me = this;
|
this.body = $(this.template.join(""));
|
var buttons = this.buttons;
|
|
buttons.prior = $("#btn_prior", this.body);
|
buttons.prior.click(function() {
|
if (!me.url) {
|
return;
|
}
|
|
me.page.prior();
|
me.moveto();
|
});
|
|
buttons.next = $("#btn_next", this.body);
|
buttons.next.click(function() {
|
if (!me.url) {
|
return;
|
}
|
|
me.page.next();
|
me.moveto();
|
});
|
|
this.text = $("#btn_text", this.body);
|
this.text.val(this.page.toText());
|
|
this.canvas.append(this.body);
|
},
|
|
checkStatus: function() {
|
// var buttons = this.buttons;
|
// this.setStatus(buttons.prior, this.page.isBof());
|
// this.setStatus(buttons.next, this.page.isEof());
|
},
|
|
open: function() {
|
this.moveto();
|
},
|
|
moveto: function() {
|
var me = this, param = null;
|
|
if (me.filter) {
|
param = me.filter.toURL(this.page);
|
}
|
|
if (me.param) {
|
param = param ? param + "&" + me.param : me.param;
|
}
|
|
Server.getData(this.url, param, function(data, page) {
|
var offset = 0;
|
if (page) {
|
offset = page.pagesize * Math.max((page.pageno - 1), 0);
|
};
|
|
me.data = data;
|
me.page.setData(page);
|
|
me.text.val(me.page.toText());
|
me.checkStatus();
|
me.notifySubscribers(offset);
|
});
|
},
|
|
notifySubscribers: function(offset) {
|
for (var i = 0; i < this.subscribers.length; i++) {
|
var subscriber = this.subscribers[i];
|
|
if (subscriber.loadData) {
|
subscriber.loadData(this.data, offset);
|
}
|
}
|
}
|
});
|
|
//================================page===================================//
|
$.fm.Page = Object.subClass ({
|
init: function(options) {
|
if (prototyping) {
|
return;
|
}
|
|
this.recordCount = 0;
|
this.beginRecordNo = 0;
|
this.pageSize = 8;
|
this.endRecordNo = 0;
|
this.pageCount = 0;
|
this.pageNo = 1;
|
|
Object.init.call(this, options);
|
},
|
|
setData: function(data) {
|
if (!data) {return;}
|
this.recordCount = data.recordcount || this.recordCount;
|
this.pageSize = data.pagesize || this.pageSize;
|
this.pageNo = data.pageno || this.pageNo;
|
|
if (this.recordCount > 0) {
|
this.pageCount = Math.ceil(this.recordCount / this.pageSize);
|
this.beginRecordNo = (this.pageNo - 1) * this.pageSize + 1;
|
this.endRecordNo = Math.min((this.beginRecordNo + this.pageSize - 1), this.recordCount);
|
}
|
},
|
|
first: function() {
|
if (this.recordCount > 0) {
|
this.beginRecordNo = 1;
|
this.pageNo = 1;
|
}
|
},
|
|
prior: function() {
|
if (this.pageNo > 1) {
|
this.pageNo--;
|
this.beginRecordNo = this.beginRecordNo - this.pageSize;
|
this.endRecordNo = this.endRecordNo - this.pageSize;
|
}
|
},
|
|
next: function() {
|
if (this.pageNo < this.pageCount) {
|
this.pageNo++;
|
this.beginRecordNo = this.beginRecordNo + this.pageSize;
|
this.endRecordNo = this.endRecordNo + this.pageSize;
|
}
|
},
|
|
last: function() {
|
if (this.count > 0) {
|
this.beginRecordNo = (this.pageCount - 1) * this.pageSize + 1;
|
this.endRecordNo = this.count;
|
this.pageNo = this.pageCount;
|
}
|
},
|
|
setPageNo: function(pageNo) {
|
if (this.pageNo != pageNo) {
|
if (pageNo > this.pageCount) {
|
pageNo = this.pageCount;
|
}
|
|
if (pageNo < 1) {
|
pageNo = 1;
|
}
|
|
this.pageNo = pageNo;
|
this.beginRecordNo = (pageNo - 1) * this.pageSize + 1;
|
this.endRecordNo = this.beginRecordNo + this.pageSize;
|
}
|
},
|
|
isBof: function() {
|
|
},
|
|
isEof: function() {
|
|
},
|
|
toText: function() {
|
return "共" + this.recordCount + "条记录, 每页" + this.pageSize + "条,第" + this.pageNo + "页";
|
},
|
|
toURL: function() {
|
return "pagesize=" + this.pageSize + "&pageno=" + this.pageNo;
|
}
|
});
|
|
|
//================================Mask===================================//
|
Mask = $.fm.Mask = Control.subClass({
|
template: [
|
'<div class="mask" style="position: fixed; z-index: 0; top: 0; left: 0; right: 0; bottom: 0;" />',
|
'</div>'
|
],
|
|
init: function(options) {
|
options = options ? options : {};
|
Control.call(this, options);
|
|
this.mask = $(this.template.join(""));
|
this.canvas.append(this.mask);
|
}
|
});
|
|
//================================Message===================================//
|
Message = $.fm.Message = Control.subClass({
|
template: [
|
'<div align="center" class="mask" style="position: fixed; z-index: 0; top: 0; left: 0; right: 0; bottom: 0;" />',
|
'<div id="message" class="message" style="position: fixed; z-index: 100; left: 30px; right: 30px;" />',
|
'</div>'
|
],
|
|
init: function(options) {
|
options = options ? options : {};
|
Control.call(this, options);
|
|
this.mask = $(this.template.join(""));
|
this.message = $("#message", this.mask);
|
|
this.canvas.append(this.mask);
|
},
|
|
show: function(text) {
|
this.message.html(text);
|
this.mask.show();
|
}
|
});
|
|
|
//================================Window===================================//
|
Win = {};
|
|
$.fm.WinClass = Control.subClass({
|
template: [
|
'<div class="win">',
|
'<iframe class="win-iframe" />',
|
'</iframe>',
|
'</div>'
|
],
|
|
init: function(options) {
|
options = options ? options : {};
|
Control.call(this, options);
|
|
this.winList = {};
|
this.activeWin = [];
|
},
|
|
getWinItem: function(url) {
|
if (!url) return;
|
|
var pos = url.lastIndexOf("/");
|
var name = url.substring(pos + 1);
|
pos = name.indexOf(".");
|
name = name.substring(0, pos);
|
|
var item = this.winList[name];
|
|
if (!item) {
|
item = {"name": name};
|
this.winList[name] = item;
|
|
item.body = $(this.template.join(""));
|
item.iframe = $("iframe", item.body);
|
//item.iframe.attr("src", url + "?" + Math.random());
|
if(url.indexOf("imagelib") > 0){
|
item.iframe.attr("src", serverAddress+"a/"+url + "?" + Math.random());
|
}else{
|
item.iframe.attr("src", url + "?" + Math.random());
|
}
|
|
this.canvas.append(item.body);
|
}
|
else {
|
item.created = true;
|
}
|
|
this.activeWin.push(item);
|
return item;
|
},
|
|
popup: function(url) {
|
var winItem = this.getWinItem(url);
|
|
winItem.body.css({
|
"transform": "translateY(0)",
|
"background": "rgba(0, 0, 0, 0.5)"
|
});
|
|
winItem.iframe.css({
|
"margin-top": "20%",
|
"width": "80%",
|
"height": "80%"
|
});
|
|
winItem.body.show();
|
|
if (winItem.created && winItem.onShowFunc) {
|
winItem.onShowFunc();
|
}
|
|
return winItem;
|
},
|
|
open: function(url, data) {
|
var winItem = this.getWinItem(url);
|
winItem.data = data;
|
|
winItem.iframe.css({
|
"background-color": "white"
|
});
|
|
winItem.body.show();
|
|
if (winItem.created && winItem.onShowFunc) {
|
winItem.onShowFunc();
|
}
|
|
return winItem;
|
},
|
|
close: function() {
|
var winItem = this.activeWin.pop();
|
|
if (winItem) {
|
winItem.body.hide();
|
}
|
},
|
|
getData: function() {
|
if (this.activeWin.length == 0) {return;};
|
|
var winItem = this.activeWin[this.activeWin.length - 1];
|
if (winItem) {
|
return winItem.data;
|
}
|
},
|
|
onShow: function(func) {
|
if (this.activeWin.length == 0) {return;};
|
|
var winItem = this.activeWin[this.activeWin.length - 1];
|
if (winItem) {
|
return winItem.onShowFunc = func;
|
}
|
}
|
});
|
|
Win.popup = function(url) {
|
if (!this.instance) {
|
this.instance = new $.fm.WinClass();
|
}
|
|
this.instance.popup(url);
|
};
|
|
Win.open = function(url, data) {
|
if (window.top && window.top.Win && window.top.Win.instance) {
|
this.instance = window.top.Win.instance;
|
this.instance.open(url, data);
|
return;
|
}
|
|
if (!this.instance) {
|
this.instance = new $.fm.WinClass();
|
}
|
|
this.instance.open(url, data);
|
};
|
|
Win.close = function() {
|
if (!window.top || !window.top.Win) {
|
return;
|
}
|
|
var instance = window.top.Win.instance;
|
instance.close();
|
};
|
|
Win.getData = function() {
|
if (!window.top || !window.top.Win) {
|
return null;
|
}
|
|
var instance = window.top.Win.instance;
|
return instance.getData();
|
};
|
|
Win.onShow = function(func) {
|
if (!window.top || !window.top.Win) {
|
return;
|
}
|
|
var instance = window.top.Win.instance;
|
return instance.onShow(func);
|
};
|
|
//================================Dialog===================================//
|
Dialog = {};
|
|
$.fm.DialogClass = Control.subClass({
|
template: [
|
'<div class="mask" style="display: none; z-index: 9999" align="center">',
|
'<div class="dialog">',
|
'<div class="dialog_header" id="title">',
|
'信息提示',
|
'</div>',
|
'<div class="dialog_body">',
|
'<div class="dialog_content">',
|
'<div class="dialog_image" id="image"></div>',
|
'<div class="dialog_text" id="text" style="width:320px;"></div>',
|
'</div>',
|
'</div>',
|
'<div class=dialog_footer>',
|
'<button class="button button_std button_active" id="btn_cancel">取消</button>',
|
'<button class="button button_std button_active" id="btn_ok" style="margin-left:8px">确定</button>',
|
'</div>',
|
'</div>',
|
'</div>'
|
],
|
|
init: function(options) {
|
options = options ? options : {};
|
Control.call(this, options);
|
this.canvas = $(window.top.window.document.body);
|
|
this.createEl();
|
},
|
|
createEl: function() {
|
var me = this;
|
var el = this.el = $(this.template.join(""));
|
|
this.title = $("#title", el);
|
this.image = $("#image", el);
|
this.text = $("#text", el);
|
this.btn_cancel = $("#btn_cancel", el);
|
this.btn_ok = $("#btn_ok", el);
|
|
this.btn_cancel.click(function() {
|
me.el.hide();
|
if (me.callback) {
|
me.callback(false);
|
}
|
});
|
|
this.btn_ok.click(function() {
|
me.el.hide();
|
if (me.callback) {
|
me.callback(true);
|
}
|
});
|
|
this.canvas.append(this.el);
|
},
|
|
confirm: function (title, text, callback) {
|
this.title.html(title);
|
this.text.html(text);
|
this.image.removeClass("icon_alert");
|
this.image.addClass("icon_confirm");
|
this.btn_cancel.show();
|
|
this.callback = callback;
|
|
this.el.show();
|
},
|
|
alert: function (title, text1, text2) {
|
this.title.html(title);
|
|
if (text2) {
|
this.text.html(text1 + "<br>" + text2);
|
this.text.css("line-height", "23px");
|
}
|
else {
|
this.text.html(text1);
|
this.text.css("line-height", "40px");
|
}
|
|
this.image.removeClass("icon_confirm");
|
this.image.addClass("icon_alert");
|
this.btn_cancel.hide();
|
|
this.callback = null;
|
|
this.el.show();
|
}
|
});
|
|
Dialog.confirm = function(title, text, callback) {
|
if (!this.instance) {
|
this.instance = new $.fm.DialogClass();
|
}
|
this.instance.confirm(title, text, callback);
|
};
|
|
Dialog.alert = function(text1, text2) {
|
if (!this.instance) {
|
this.instance = new $.fm.DialogClass();
|
}
|
this.instance.alert("提醒", text1, text2);
|
};
|
|
Dialog.wait = function(text) {
|
if (!this.instance) {
|
this.instance = new $.fm.DialogClass();
|
}
|
this.instance.wait("提醒", text1, text2);
|
};
|
|
|
//================================Dialog===================================//
|
Loading = {};
|
|
$.fm.LoadingClass = Control.subClass({
|
template: [
|
'<div class="maskdata" style="display: none" align="center">',
|
'<div class="loading">',
|
'<div id="text"></div>',
|
'</div>',
|
'</div>'
|
],
|
caller: {},
|
|
init: function(options) {
|
options = options ? options : {};
|
Control.call(this, options);
|
|
this.createEl();
|
},
|
|
createEl: function() {
|
var el = this.el = $(this.template.join(""));
|
this.text = $("#text", el);
|
this.canvas.append(this.el);
|
},
|
|
show: function (text) {
|
this.text.html(text);
|
this.el.show();
|
},
|
|
showAll: function (code, text) {
|
this.caller[code] = text;
|
this.text.html(text);
|
this.el.show();
|
},
|
|
hide: function(code) {
|
if (!code) {
|
this.el.hide();
|
this.caller = {};
|
return;
|
}
|
|
delete this.caller[code];
|
|
for (var n in this.caller) {
|
this.text.html(this.caller[n]);
|
return;
|
}
|
|
this.el.hide();
|
}
|
});
|
|
Loading.show = function(text) {
|
if (!this.instance) {
|
this.instance = new $.fm.LoadingClass();
|
}
|
this.instance.show(text);
|
};
|
|
Loading.showAll = function(code, remark, text) {
|
if (!this.instance) {
|
this.instance = new $.fm.LoadingClass();
|
}
|
this.instance.showAll(code, remark, text);
|
};
|
|
Loading.hide = function(code) {
|
if (!this.instance) {
|
this.instance = new $.fm.LoadingClass();
|
}
|
this.instance.hide(code);
|
};
|
|
|
})(jQuery);
|