if(!I18n) { var I18n = { trans: function(s) { return s; } }; } jQuery.fn.extend({ /** * 灏唖erializeArray浜х敓鐨勭粨鏋滃皝瑁呮垚{{property, value}, }鐨凧son鏍煎紡瀵硅薄 * @returns */ form2Json:function(prefix){ var json = {}; var fields = jQuery(this).serializeArray(); jQuery.each( fields, function(i, field){ var key = field.name; if(prefix){ // 杩欎釜鏂瑰紡涓嶆槸寰堝仴澹紝閬囧埌鐗规畩鎯呭喌锛岄渶瑕佸畬鍠勮繖閲 key = key.replace( prefix + '\.', '' ); } json[key] = field.value; }); return json; }, //checkbox銆乺adio绛夊簲璇ヨ繕鏈夐棶棰橈紝鏆傛椂鍏堣繖涔堝啓 form2Criteria:function(option){ option = option || {}; var prefix = option.prefix; var fuzzyFields = option.fuzzyFields || []; var ignoreFields = option.ignoreFields || []; var criteria = ''; var fields = jQuery(this).serializeArray(); var fuzzy = {}; for (var i = 0; i < fuzzyFields.length; i++) { fuzzy[fuzzyFields[i]] = 1; } var ignore = {}; for (var i = 0; i < ignoreFields.length; i++) { ignore[ignoreFields[i]] = 1; } jQuery.each( fields, function(i, field){ if (field.value) { var key = field.name; if(prefix){ // 杩欎釜鏂瑰紡涓嶆槸寰堝仴澹紝閬囧埌鐗规畩鎯呭喌锛岄渶瑕佸畬鍠勮繖閲 key = key.replace( prefix + '\.', '' ); } if (ignore[key] == 1) { return; } if (criteria != '') { criteria += ' and '; } if (fuzzy[key] == 1) { criteria += field2ColumnName(key) + " like '%" + field.value + "%' "; } else { criteria += field2ColumnName(key) + " = '" + field.value + "' "; } } }); return criteria; }, form2CriteriaJson:function(option){ option = option || {}; var prefix = option.prefix; var fuzzyFields = option.fuzzyFields || []; var ignoreFields = option.ignoreFields || []; var criteria = ''; var fields = jQuery(this).serializeArray(); var fuzzy = {}; for (var i = 0; i < fuzzyFields.length; i++) { fuzzy[fuzzyFields[i]] = 1; } var ignore = {}; for (var i = 0; i < ignoreFields.length; i++) { ignore[ignoreFields[i]] = 1; } var queryConditons = []; jQuery.each( fields, function(i, field){ if (field.value) { var key = field.name; if(prefix){ // 杩欎釜鏂瑰紡涓嶆槸寰堝仴澹紝閬囧埌鐗规畩鎯呭喌锛岄渶瑕佸畬鍠勮繖閲 key = key.replace( prefix + '\.', '' ); } if (ignore[key] == 1) { return; } queryConditons[queryConditons.length] = { field: field2ColumnName(key), op: (fuzzy[key] == 1? 'cn' : 'eq'), data: jQuery.trim(field.value) }; } }); return JSON2.stringify(queryConditons); }, // 涓巉orm.reset鐨勫尯鍒?鍙互娓呯┖hidden input clearForm:function() { jQuery(this).find(':input').each(function() { switch(this.type) { case 'password': case 'select-multiple': case 'select-one': case 'text': case 'textarea': case 'hidden': jQuery(this).val(''); break; case 'checkbox': case 'radio': this.checked = false; } }); }, /** * 闅愯棌褰撳墠html鐗囨柇,骞朵笖鏄剧ずloading鍥剧墖 * @returns */ loading:function(){ jQuery(this).before('loading...'); }, /** * 鍦ㄦ煇涓厓绱犲唴閮ㄦ樉绀簂oading */ innerLoading:function(loadingMsg) { if(!loadingMsg) { loadingMsg = 'loading...'; } jQuery(this).html('
'+loadingMsg+'
'); jQuery(this).show(); }, /** * 楂樹寒鏌愪釜閮ㄥ垎锛岃〃绀鸿繖閮ㄥ垎鍙戠敓浜嗗彉鍖 */ highlight: function() { dwr.util.yellowFadeHighlightHandler(jQuery(this)); }, /** * 璁╁綋鍓嶅厓绱犲叏閮芥樉绀哄嚭鏉ワ紝涓嶈杩涘叆绐楀彛涓嬫柟 * @returns */ slideIntoView: function() { var element = jQuery(this); var offset = element.offset(); // 鍔?0鏄负浜嗗幓鎺夐〉搴曠殑娴姩灞傚伐鍏锋爮 var min = offset.top + element.height() + 50 - jQuery(window).scrollTop() - jQuery(window).height(); if ( min > 0 ) { jQuery(window).scrollTop( jQuery(window).scrollTop() + min ); } return element; }, simpleForm: function(validationOptions){ var $this = jQuery(this); $this.find('.control-group').click(function(){ $this.find('.control-group.focus').removeClass('focus'); jQuery(this).addClass('focus'); }); if(validationOptions) { return $this.bind("invalid-form.validate").validate($.extend({}, validationOptions, { ignore: "", errorPlacement: function(error, element) { var container = element.parents('.controls'); element.parents(".control-group").removeClass('success').addClass('error'); container.find('.tip-error').remove(); container.find('.tip-success').remove(); error.addClass('tip-error').css({ display: 'inline-block' }).appendTo(container); }, success: function(label) { label.parent().find('.tip-success').remove(); label.html(' ').removeAttr('class').addClass('tip-success').css({ display: 'inline-block' }); label.parents(".control-group").removeClass('error').addClass('success'); }, onfocusout: function(element) { if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) { this.element(element); } //濡傛灉鏌愪釜鍏冪礌涓嶆槸蹇呭~鐨勶紝濡傛灉濉啓鏈夎鍚庯紝鍒犻櫎鎵€鏈夊凡濉殑椤癸紝姝ゆ椂搴旇鏄纭殑锛屾墍浠ヨ鍘绘帀鍔犲湪鏈€澶栧洿鐨勯敊璇牱寮 if(this.optional(element)) { if(jQuery(element).parent().find('.tip-error').length == 0) { jQuery(element).parents(".control-group").removeClass('error'); } } } })); } }, formValid: function(validationOptions) { return jQuery(this).validate(jQuery.extend({}, validationOptions, { ignore: "", errorPlacement: function(error, element) { element.parent().find('.tip-error').remove(); error.addClass('tip-error').css({display: 'inline-block', 'zoom': '1'}).appendTo(element.parent()); //濡傛灉鏈夋垚鍔熸彁绀轰俊鎭殑璇濆垯鍘绘帀 error.siblings('.tip-success').remove(); }, success: function(label) { label.parent().find('.tip-success').remove(); label.html(' ').removeAttr('class').addClass('tip-success'); }, onfocusout: function(element) { if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) { this.element(element); } //濡傛灉鏌愪釜鍏冪礌涓嶆槸蹇呭~鐨勶紝濡傛灉濉啓鏈夎鍚庯紝鍒犻櫎鎵€鏈夊凡濉殑椤癸紝姝ゆ椂搴旇鏄纭殑锛屾墍浠ヨ鍘绘帀鍔犲湪鏈€澶栧洿鐨勯敊璇牱寮 if(this.optional(element)) { if(jQuery(element).parent().find('.tip-error').length == 0) { jQuery(element).parents(".control-group").removeClass('error'); } } } })); } }); function hideloading(){ jQuery('#loading_bar').remove(); } function field2ColumnName(fieldName){ var columnName = ''; var str = new Array(); for (var i = 0; i < fieldName.length; i++) { str[i] = fieldName.substring(i,i+1); if (/[A-Z]/.test(str[i])) { columnName += '_' + str[i].toLowerCase(); } else { columnName += str[i].toLowerCase(); } } return columnName; } !function ($) { var _CACHE_DATA = {}; var KEY = { UP: 38, DOWN: 40, DEL: 46, TAB: 9, RETURN: 13, ESC: 27, COMMA: 188, PAGEUP: 33, PAGEDOWN: 34, BACKSPACE: 8 }; var selectTreeId = 'dynamic-tree-div'; function getSelectBtn(inputBtn, hideBtn) { var combo = inputBtn.next('.btn-combo'); if(combo.length == 0) { if(!hideBtn) { combo = jQuery(''); inputBtn.after(combo); } } return combo; } function getYearOptions4Select(options) { var years = [], currentYear = (new Date()).getFullYear(), begin = options.begin, end = options.end; if (begin === null || begin === '' || typeof begin === 'undefined') { begin = currentYear - (options.down || 8); } if (end === null || end === '' || typeof end === 'undefined') { end = currentYear + (options.up || 0); } for (var i = end; i >= begin; i--) { years.push({text : i , value : i}); } return years; } function forceSelection(obj, options, keyupcallback) { //寮哄埗閫夋嫨鍒ゆ柇鍒嗕笁姝ワ細 //1銆侀€夋嫨鍓嶅皢灞炴€ata-selected缃负false //2銆侀€夋嫨鍚庡皢灞炴€ata-selected缃负true //3銆乥lur鍚庡垽鏂璬ata-selected鏄惁涓簍rue锛屼笉涓簍rue琛ㄧず杩樻病鏈夐€夋嫨鍒欏己鍒舵竻绌 obj.attr('defaultValue', obj.val()); obj.bind( 'keyup', function(eve){ // 鍥炶溅娓呯┖Bug if(eve.keyCode == KEY.RETURN){ return false; } if(obj.attr('defaultValue') != obj.val()) { obj.attr('data-selected', 'false'); } if(typeof keyupcallback == 'function') { keyupcallback(eve); } }); if(options.forceSelection) { obj.bind( 'blur', function(eve){ if(obj.attr('data-selected') != 'true') { //寮哄埗閫夋嫨,濡傛灉娌℃湁閫夋嫨鐨勮瘽鍒欐竻绌 obj.val(''); if (options.hiddenId) { var hidenObj = (typeof options.hiddenId == 'string') ? jQuery('#' + options.hiddenId) : jQuery(options.hiddenId); hidenObj.val(''); } } obj.attr('defaultValue', obj.val()); }); } } function setSelectedTreeNode2Obj(obj, hiddenObj, nodes, options) { //閫夋嫨鍓嶈皟鐢 if(options.beforeSelect) { if(!(options.beforeSelect(nodes))) { return false; }; } var nodeId = [], nodeText = []; $.each(nodes, function(index, ele){ if(options.selectNodeType == 'leaf') { if(!ele.hasClass('leaf')) { return; } } nodeId.push(options.idIsCode? jQuery(ele).attr('code') : jQuery(ele).attr('id')); nodeText.push(jQuery(ele).attr('text')); }); jQuery(obj).val(nodeText.join(options.multiSeparator)); if(hiddenObj) { jQuery(hiddenObj).val(nodeId.join(options.multiSeparator)); } //閫夋嫨鍚庤皟鐢 if(options.afterSelect) { options.afterSelect(nodes); } return true; } function showTree(eve, obj, options, data) { try{ if(jQuery.tree_reference(selectTreeId)) { jQuery.tree_reference(selectTreeId).destroy(); } }catch(e){} //閫夋嫨鑺傜偣绫诲瀷 if(typeof options.selectNodeType == 'undefined') { options.selectNodeType = 'leaf'; } //榛樿涓哄崟閫 if(typeof options.multi == 'undefined') { options.multi = false; } //濡傛灉鏄閫夌殑璇濋粯璁ゆ樉绀洪€夋嫨鎸夐挳 if(options.multi && typeof options.selectBtn == 'undefined') { options.selectBtn = true; } if(!(options.multi) && typeof options.closeOnSelect == 'undefined') { options.closeOnSelect = true; } //澶氶€夊垎闅旂 options.multiSeparator = options.multiSeparator || ';'; //瀛樻斁鑺傜偣id瀛楁 var hiddenObj = null; if(options.hiddenId) { if(typeof options.hiddenId == 'string') { hiddenObj = jQuery('#' + options.hiddenId); } else { hiddenObj = jQuery(options.hiddenId); } } var selectedIds = []; if(options.selectBtn && hiddenObj) { selectedIds = hiddenObj.val().split(options.multiSeparator); } var buttons = []; //鏄惁闇€瑕侀€夋嫨鎸夐挳 if(options.selectBtn) { buttons[buttons.length] = { 'text': '閫夋嫨', 'class': 'btn-primary', 'callback': function() { setSelectedTreeNode2Obj(obj, hiddenObj, JsTreeUtil.getSelectedNodeArray(selectTreeId), options); jQuery.unblockUI(); } }; } buttons[buttons.length] = { 'text': '鍏抽棴', 'callback': function() { jQuery.unblockUI(); } }; DialogUtil.innerDialog({ title: options.title, html: '
杞藉叆涓?..
', buttons: buttons, height: options.height, width: options.width || '400', initCallback: function() { //鏄剧ず鏍 JsTreeUtil.getJsTree(selectTreeId, data, { onselect : function (node, tree_obj) { node = jQuery(node); if(options.selectNodeType == 'leaf' && !node.hasClass('leaf')) { return; } if(!(options.selectBtn)) { if(!setSelectedTreeNode2Obj(obj, hiddenObj, [node], options)) { return; } } if(options.closeOnSelect) { jQuery.unblockUI(); } }, onchange : function(node, tree_obj) { if(options.treeOnchangeCallback) { options.treeOnchangeCallback(node, tree_obj); }else{ if(options.followParent === false){ JsTreeUtil.singleCheckboxTreeOnchange(node, tree_obj); }else{ JsTreeUtil.checkboxTreeOnchange(node, tree_obj); } } } },{ multiple: (options.multi? 'on':false) },{ searchResultOnlyView: true, 'theme_name' : (options.multi? 'checkbox' : ''), context: []}, selectedIds); if(options.multi) { var cancelSelectBtn = jQuery(''); cancelSelectBtn.click(function(e){ var tree = jQuery.tree_reference(selectTreeId); tree.container.find("a.checked").removeClass('checked').addClass('unchecked'); tree.container.find("a.undetermined").removeClass('undetermined').addClass('unchecked'); }); cancelSelectBtn.appendTo(jQuery('#popupFooterLeft')); } if(options.filter) { var search = jQuery('
'); search.keyup(function(e){ if(e.keyCode == KEY.RETURN) { jQuery.tree_reference(selectTreeId).search(jQuery(this).find('input').val().trim()); //濡傛灉娌℃湁鎼滅储鍒扮粨鏋滅殑璇濇樉绀轰竴涓粨鏋滀俊鎭 if(jQuery('#' + selectTreeId + ' > ul').is(':hidden')) { jQuery('#' + selectTreeId + '-no-data-found').show(); }else{ jQuery('#' + selectTreeId + '-no-data-found').hide(); } } }); search.appendTo(jQuery('#popupFooterLeft')); jQuery("#i-searchbtn").click(function(){ jQuery.tree_reference(selectTreeId).search(jQuery(this).prev().val().trim()); //濡傛灉娌℃湁鎼滅储鍒扮粨鏋滅殑璇濇樉绀轰竴涓粨鏋滀俊鎭 if(jQuery('#' + selectTreeId + ' > ul').is(':hidden')) { jQuery('#' + selectTreeId + '-no-data-found').show(); }else{ jQuery('#' + selectTreeId + '-no-data-found').hide(); } }); } } }); } //骞翠唤杈撳叆妗 $.fn.selectYear = function (options) { options = options || {}; return this.each(function () { var $this = jQuery(this), combo = getSelectBtn($this, options.hideBtn), years = getYearOptions4Select(options); $this.attr('autocomplete', 'off'); combo && combo.click(function(eve){ AppSelect.getStaticOptions(eve, $this, null, years, options.multi, true, options.callback, options.width,options.clear,options.multiFilter); }); $this.bind( 'click keyup', function(eve){ AppSelect.getStaticOptions(eve, $this, null, years, options.multi, true, options.callback, options.width,options.clear,options.multiFilter); }); }); }; //combo杈撳叆妗 $.fn.comboTree = function (options) { options = options || {}; function initComboEvent($this, combo, options, data) { combo && combo.click(function(eve){ showTree(eve, $this, options, data); }); $this.bind( 'click', function(eve){ showTree(eve, $this, options, data); }); } return this.each(function () { var $this = jQuery(this), combo = getSelectBtn($this, options.hideBtn); $this.attr('autocomplete', 'off'); if(options.dm) { DataSelectRemoteCallController.getDmCodeTreeWithCodeByLevel(options.dm.split(','), options.level || 0, (options.fullname? true: false), function(dmdata){ initComboEvent($this, combo, options, dmdata); }); } else if(options.clazz){ DataSelectRemoteCallController.getClazzTree(function(dmdata){ initComboEvent($this, combo, options, dmdata); }); } else{ var data = options.data; if(data) { for(var i = 0; i < data.length; i++) { if(typeof data[i] != 'object') { data[i] = { text: data[i], id: data[i] }; } } initComboEvent($this, combo, options, data); } } }); }; /** * 鏄惁闇€瑕佹牴鎹€兼潵鍒濆鍖栨枃鏈紝濡傛灉鏂囨湰妗嗗凡缁忔湁鍊间簡灏变笉鑰冭檻浜 */ function isNeedInitDefaultTextByValue($this, options) { if(!(options.hiddenId) || ($this.val())) { return false; } var hiddenObj = (typeof options.hiddenId == 'string') ? jQuery(document.getElementById(options.hiddenId)) : options.hiddenId, hiddenVal = hiddenObj.val(); return (typeof hiddenVal != 'undefined') && (hiddenVal != ''); } function initDefaultTextByValue($this, options, data) { var hiddenObj = (typeof options.hiddenId == 'string') ? jQuery(document.getElementById(options.hiddenId)) : options.hiddenId; if(hiddenObj && hiddenObj.val()) { var hiddenValueArray = [], displayTextArray = []; if(options.multi) { hiddenValueArray = hiddenObj.val().split(';'); }else{ hiddenValueArray = [hiddenObj.val()]; } jQuery.each(data, function(index, ele) { if(hiddenValueArray.indexOf(ele.value) >= 0) { displayTextArray[displayTextArray.length] = ele.text; } }); $this.val(displayTextArray.join(';')); } } function getComboData(getDataFunc) { var d = getDataFunc(); for(var i = 0; i < d.length; i++) { if(typeof d[i] != 'object') { d[i] = { text: d[i], value: d[i] }; } } return d; } //combo杈撳叆妗 $.fn.combo = function (options) { options = options || {}; var DEFAULT_MAX_ITEM = 10; return this.each(function () { var $this = jQuery(this), combo = getSelectBtn($this, options.hideBtn), data = options.data || []; $this.attr('autocomplete', 'off'); if(typeof options.forceSelection == 'undefined') { options.forceSelection = true; } $.data(this, 'comb-max-item', options.maxItems || DEFAULT_MAX_ITEM); if(options.data && jQuery.isArray(options.data)) { for(var i = 0; i < data.length; i++) { if(typeof data[i] != 'object') { data[i] = { text: data[i], value: data[i] }; } } if(isNeedInitDefaultTextByValue($this, options)) { initDefaultTextByValue($this, options, data); } combo && combo.click(function(eve){ AppSelect.getStaticOptions(eve, $this, options.hiddenId, data, options.multi, !(options.filter), options.callback, options.width,options.clear); }); $this.bind( 'click keyup', function(eve){ AppSelect.getStaticOptions(eve, $this, options.hiddenId, data, options.multi, !(options.filter), options.callback, options.width,options.clear); }); }else if(typeof options.data == 'function'){ if(isNeedInitDefaultTextByValue($this, options)) { initDefaultTextByValue($this, options, getComboData(options.data)); } combo && combo.click(function(eve){ AppSelect.getStaticOptions(eve, $this, options.hiddenId, getComboData(options.data), options.multi, !(options.filter), options.callback, options.width,options.clear); }); $this.bind( 'click keyup', function(eve){ AppSelect.getStaticOptions(eve, $this, options.hiddenId, getComboData(options.data), options.multi, !(options.filter), options.callback, options.width,options.clear); }); }else if(options.dm) { options.filter = (typeof options.filter != 'undefined')? options.filter : true; if(isNeedInitDefaultTextByValue($this, options)) { AppSelect.getDmData(options, function(data){ initDefaultTextByValue($this, options, data); //闃叉寮哄埗娓呯┖ $this.attr('data-selected', 'true'); }); } combo && combo.click(function(eve){ AppSelect.getDmOptions2(eve, $this, options); }); $this.bind( 'click', function(eve){ AppSelect.getDmOptions2(eve, $this, options); }); //寮哄埗閫夋嫨鍒ゆ柇 forceSelection($this, options, function(eve) { AppSelect.getDmOptions2(eve, $this, options); }); }else if(options.url){ options.filter = (typeof options.filter != 'undefined')? options.filter : true; options.cache = (typeof options.cache != 'undefined')? options.cache : true; function getComboUrlParams(options) { if(typeof options.params == 'function') { return options.params.call(this); }else{ return options.params || {}; } } if(isNeedInitDefaultTextByValue($this, options)) { var timestramp = (options.url.indexOf('?') >= 0? '&' : '?') + '_' + new Date().getTime(); if(options.cache && _CACHE_DATA[options.url]) { initDefaultTextByValue($this, options, _CACHE_DATA[options.url]); //闃叉寮哄埗娓呯┖ $this.attr('data-selected', 'true'); }else{ $.post(options.url + timestramp, getComboUrlParams(options), function(data){ data = eval('('+ data +')'); _CACHE_DATA[options.url] = data; initDefaultTextByValue($this, options, _CACHE_DATA[options.url]); //闃叉寮哄埗娓呯┖ $this.attr('data-selected', 'true'); }); } } function showOptions(eve, cacheData) { var timestramp = (options.url.indexOf('?') >= 0? '&' : '?') + '_' + new Date().getTime(); if(cacheData || options.cache) { if(_CACHE_DATA[options.url]) { AppSelect.getStaticOptions(eve, $this, options.hiddenId, _CACHE_DATA[options.url], options.multi, !(options.filter), options.callback, options.width,options.clear); }else{ $.post(options.url + timestramp, getComboUrlParams(options), function(data){ data = eval('('+ data +')'); AppSelect.getStaticOptions(eve, $this, options.hiddenId, data, options.multi, !(options.filter), options.callback, options.width,options.clear); _CACHE_DATA[options.url] = data; }); } }else{ delete _CACHE_DATA[options.url]; $.post(options.url + timestramp, getComboUrlParams(options), function(data){ data = eval('('+ data +')'); AppSelect.getStaticOptions(eve, $this, options.hiddenId, data, options.multi, !(options.filter), options.callback, options.width,options.clear); _CACHE_DATA[options.url] = data; }); } } combo && combo.click(function(eve){ showOptions(eve); }); $this.bind( 'click', function(eve){ showOptions(eve); }); //寮哄埗閫夋嫨鍒ゆ柇 forceSelection($this, options, function(eve) { //濡傛灉鏄Е鍙戠殑鏄痥eyup浜嬩欢锛屽垯浠庣紦瀛樹腑鍙栵紝鑰屼笉鏄瘡娆¢兘浠庡悗鍙拌幏鍙 if(eve.type == 'keyup') { showOptions(eve, true); }else{ showOptions(eve, false); } }); }else if (options.options) { $this.bind( 'click keyup', function(event){ AppSelect.getStaticOptions(event, $this, options.hiddenObjId, options.options,options.isMulti, options.showAll,options.callback,options.width,options.clear); }); $this.next('button').bind( 'click', function(event){ AppSelect.getStaticOptions(event, $this, options.hiddenObjId, options.options,options.isMulti, options.showAll,options.callback,options.width,options.clear); }); } else if (options.rulename) { $this.bind( 'click keyup', function(event){ AppSelect.getOptions(event, $this, options.hiddenObjId, options.rulename,options.isMulti, options.showAll, options.params); }); $this.next('button').bind( 'click', function(event){ AppSelect.getOptions(event, $this, options.hiddenObjId, options.rulename,options.isMulti, options.showAll, options.params); }); } else if (options.department) { $this.bind( 'click keyup', function(event){ AppSelect.getDepartmentOptions(event, $this, options.hiddenObjId, options.isMulti, options.callback); }); $this.next('button').bind( 'click', function(event){ AppSelect.getDepartmentOptions(event, $this, options.hiddenObjId, options.isMulti, options.callback); }); }else if (options.category) { $this.bind( 'click keyup', function(event){ AppSelect.getCategoryOptions(event, $this, options.hiddenObjId, options.isMulti); }); $this.next('button').bind( 'click', function(event){ AppSelect.getCategoryOptions(event, $this, options.hiddenObjId, options.isMulti); }); } else if (options.room) { $this.bind( 'click keyup', function(event){ AppSelect.getRoomOptions(event, $this, options.hiddenObjId, options.isMulti); }); $this.next('button').bind( 'click', function(event){ AppSelect.getRoomOptions(event, $this, options.hiddenObjId, options.isMulti); }); }else if(options.sgRoom){ $this.bind( 'click keyup', function(event){ AppSelect.getSgRoomOptions(event, $this, options.hiddenObjId, options.isMulti); }); $this.next('button').bind( 'click', function(event){ AppSelect.getSgRoomOptions(event, $this, options.hiddenObjId, options.isMulti); }); }else if(options.bjclass){ $this.bind( 'click keyup', function(event){ AppSelect.getBjClassOptions(event, $this, options.hiddenObjId, options.isMulti); }); $this.next('button').bind( 'click', function(event){ AppSelect.getBjClassOptions(event, $this, options.hiddenObjId, options.isMulti); }); }else if (options.comboName) { var options_yearORMonth; if (options.comboName == 'xn') { options.defaultCurrent = true; jQuery($this).selectXn(options); return; } else if (options.comboName == 'xq') { //榛樿褰撳墠瀛︽湡 options.defaultCurrent = true; jQuery($this).selectXq(options); return; }else if (options.comboName == 'year') { options_yearORMonth = AppSelect.getYear(options.begin, options.end); } else if (options.comboName == 'month') { options_yearORMonth = AppSelect.getMonth(); } $this.bind( 'click keyup', function(event){ AppSelect.getStaticOptions(event, $this, options.hiddenObjId, options_yearORMonth,options.isMulti, options.showAll); }); $this.next('button').bind( 'click', function(event){ AppSelect.getStaticOptions(event, $this, options.hiddenObjId, options_yearORMonth,options.isMulti, options.showAll); }); }else{ alert('鍒濆鍖? + $this.attr('id') + '涓嬫媺鍒楄〃澶辫触'); } }); }; $.fn.selectgroup = function (options) { options = options || {}; options.selected = options.selected || []; return this.each(function () { //濡傛灉宸茬粡鍒濆鍖栬繃浜嗗氨涓嶉渶瑕佷簡 if(jQuery(this).hasClass('selectgroup')) { return; }; var hiddenObj = null; if(options.hiddenId) { hiddenObj = (typeof options.hiddenId == 'string') ? jQuery('#' + options.hiddenId) : jQuery(options.hiddenId); options.separator = options.separator || ','; hiddenObj.val(options.selected.join(options.separator)); } if(!options.data) { alert('璇锋寚瀹歞ata灞炴€?); return; } var html = ''; jQuery(this).html(html); //灏嗛€夋嫨鍚庣殑鍊兼斁鍦ㄤ复鏃跺彉閲忎腑锛屽鏋滃凡缁忚缃簡闅愯棌瀛楁鐨勮瘽锛屽垯鐐瑰嚮鐨勬椂鍊欏悓鏃惰缃殣钘忓瓧娈电殑鍊 jQuery(this).find('li').click(function(){ var hasSelected = jQuery(this).hasClass('selected'), val = jQuery(this).attr('data-value'), text = jQuery(this).children('a').text(); if(typeof val == 'undefined') { //榛樿涓烘枃鏈 val = text; } if(hasSelected) { jQuery(this).removeClass('selected'); jQuery(this).children('i').remove(); var filterValues = []; $.each(options.selected, function(index, ele){ if(ele != val) { filterValues.push(ele); } }); options.selected = filterValues; //鍙栨秷鏃惰Е鍙戠殑浜嬩欢 if(typeof options.onCancelSelect == 'function') { options.onCancelSelect(val, text); } }else{ if(!jQuery(this).parent().hasClass('multi')) { var selectedObj = jQuery(this).parent().find('li.selected'); selectedObj.removeClass('selected'); selectedObj.children('i').remove(); //鍙栨秷鏃惰Е鍙戠殑浜嬩欢 if(typeof options.onCancelSelect == 'function' && selectedObj.length > 0) { var cancelVal = selectedObj.attr('data-value'), cancelText = selectedObj.children('a').text(); if(typeof cancelVal == 'undefined') { cancelVal = cancelText; } options.onCancelSelect(cancelVal, cancelText); } options.selected = [ val ]; }else{ if(options.selected.indexOf(val) < 0) { options.selected.push(val); } } //閫変腑鏃惰Е鍙戠殑浜嬩欢 if(typeof options.onSelect == 'function') { options.onSelect(val, text); } jQuery(this).addClass('selected').append('宸查€変腑'); } if(hiddenObj) { hiddenObj.val(options.selected.join(options.separator)); } }); }); }; /** * 涓嬫媺鍒楄〃閫夋嫨鏁欏笀锛屽彲浠ラ€氳繃鎷奸煶鏉ラ€夋嫨 */ $.fn.selectTeacher = function (options) { options = options || {}; function showSelectTeacher(eve, $this, data, option) { var filterValue = $this.val().trim(), displayData = []; for(var i = 0; i < data.length; i++) { if(filterValue != '') { filterValue = filterValue.toLowerCase(); if(data[i].quanpin && data[i].quanpin.indexOf(filterValue) >= 0) { displayData.push({ text: data[i].nameNoPinyin, value: data[i].id, bmmc: data[i].bmmc}); }else if(data[i].pinyin.indexOf(filterValue) >= 0 || data[i].name.indexOf(filterValue) >= 0) { displayData.push({ text: data[i].nameNoPinyin, value: data[i].id, bmmc: data[i].bmmc}); } }else{ displayData.push({ text: data[i].nameNoPinyin, value: data[i].id, bmmc: data[i].bmmc}); } } AppSelect.getStaticOptions(eve, $this, options.hiddenId, displayData, false, true, options.callback, options.width); } return this.each(function () { var $this = jQuery(this); $this.attr('autocomplete', 'off'); if(!$this.attr('title')) { $this.attr('title', '鍙互杈撳叆濮撳悕鎷奸煶棣栧瓧姣嶈繘琛屾煡璇?); AppUtils.qtip($this, options.qtipOptions || {}); } $this.keyup(function(eve){ var condition = options.condition || '', cacheKey = 'selectTeacherData' + condition, teacherData = _CACHE_DATA[cacheKey], onlySchool = ((options.onlySchool == false)?"false":"true"); //鍏堜粠缂撳瓨涓彇 if(teacherData == null) { DataSelectRemoteCallController.queryAllTeacher(condition,onlySchool, function(data){ _CACHE_DATA[cacheKey] = data; showSelectTeacher(eve, $this, data, options); }); }else{ showSelectTeacher(eve, $this, teacherData, options); } }); }); }; /** * 涓嬫媺鍒楄〃閫夋嫨瀛︾敓锛屽彲浠ラ€氳繃鎷奸煶鏉ラ€夋嫨 */ $.fn.selectAllStudent = function (options) { options = options || {}; function showSelectStudent(eve, $this, data, option) { var filterValue = $this.val().trim(), displayData = []; for(var i = 0; i < data.length; i++) { if(filterValue != '') { filterValue = filterValue.toLowerCase(); if(data[i].quanpin && data[i].quanpin.indexOf(filterValue) >= 0) { displayData.push({ text: data[i].nameNoPinyin, value: data[i].studentno+"_"+data[i].studentname }); }else if(data[i].pinyin.indexOf(filterValue) >= 0 || data[i].name.indexOf(filterValue) >= 0) { displayData.push({ text: data[i].nameNoPinyin, value: data[i].studentno+"_"+data[i].studentname }); } }else{ displayData.push({ text: data[i].nameNoPinyin, value: data[i].studentno+"_"+data[i].studentname }); } } AppSelect.getStaticOptions(eve, $this, options.hiddenId, displayData, false, true, options.callback, options.width); } return this.each(function () { var $this = jQuery(this); $this.attr('autocomplete', 'off'); if(!$this.attr('title')) { $this.attr('title', '鍙互杈撳叆濮撳悕鎷奸煶棣栧瓧姣嶆垨鑰?+EcampusGlobalSetting.customLabel['studentno']+'杩涜鏌ヨ'); AppUtils.qtip($this, options.qtipOptions || {}); } $this.keyup(function(eve){ var condition = options.condition || '', cacheKey = 'selectStudentData' + condition, studentData = _CACHE_DATA[cacheKey]; //鍏堜粠缂撳瓨涓彇 if(studentData == null) { DataSelectRemoteCallController.queryStudent(condition,options.schoolId, function(data){ _CACHE_DATA[cacheKey] = data; showSelectStudent(eve, $this, data, options); }); }else{ showSelectStudent(eve, $this, studentData, options); } }); }); }; /** * 涓嬫媺鍒楄〃閫夋嫨瀛︾敓锛屽彲浠ラ€氳繃鎷奸煶鏉ラ€夋嫨锛屽绫嶄腑浣跨敤 */ $.fn.selectAllStudentByMaster = function (options) { options = options || {}; function showSelectStudent(eve, $this, data, option) { var filterValue = $this.val().trim(), displayData = []; for(var i = 0; i < data.length; i++) { displayData.push({ text: data[i].nameNoPinyin, value: data[i].studentno+"_!@#$%^_"+data[i].studentname }); } AppSelect.getStaticOptions(eve, $this, options.hiddenId, displayData, false, true, options.callback, options.width); } return this.each(function () { var $this = jQuery(this); $this.attr('autocomplete', 'off'); if(!$this.attr('title')) { $this.attr('title', '鍙互杈撳叆濮撳悕鎴栬€?+EcampusGlobalSetting.customLabel['studentno']+'杩涜鏌ヨ'); AppUtils.qtip($this, options.qtipOptions || {}); } var inputing = false; var query = null; $this.bind('compositionstart', function(){ inputing = true; }) $this.bind('compositionend', function(){ inputing = false; }) $this.bind('input', function(eve){ query =this.value; setTimeout(function(){ if (!inputing) { handler(eve) } },0); }); var timerId = null; function handler (eve) { if (timerId) return; timerId = setTimeout(function(){ var condition = query || '', cacheKey = 'selectStudentData' + condition; DataSelectRemoteCallController.queryStudentByMaster(condition,options.schoolId,function(studentdata){ _CACHE_DATA[cacheKey] = studentdata; showSelectStudent(eve, $this, studentdata, options); timerId = null; }); }, 300) } }); }; /** * 涓嬫媺鍒楄〃閫夋嫨璇剧▼锛屽彲浠ラ€氳繃鎷奸煶鏉ラ€夋嫨 */ $.fn.selectAllCourse = function (options) { options = options || {}; function showSelectCourse(eve, $this, data) { var filterValue = $this.val().trim(), displayData = []; for(var i = 0; i < data.length; i++) { if(filterValue != '') { filterValue = filterValue.toLowerCase(); if(data[i].pinyin.indexOf(filterValue) >= 0 || data[i].kcmc.indexOf(filterValue) >= 0) { displayData.push({ text: data[i].kcmc, value: data[i].kcId }); } }else{ displayData.push({ text: data[i].kcmc, value: data[i].kcId }); } } AppSelect.getStaticOptions(eve, $this, options.hiddenId, displayData, false, true, options.callback, options.width); } return this.each(function () { var $this = jQuery(this); $this.attr('autocomplete', 'off'); if(!$this.attr('title')) { $this.attr('title', '鍙互杈撳叆璇剧▼鎷奸煶棣栧瓧姣嶈繘琛岃绋嬫煡璇?); AppUtils.qtip($this); } $this.keyup(function(eve){ var condition = options.condition || '', cacheKey = 'selectAllCourseData' + condition, courseData = _CACHE_DATA[cacheKey]; //鍏堜粠缂撳瓨涓彇 if(courseData == null) { CourseController.queryAllCourse(condition, function(data){ _CACHE_DATA[cacheKey] = data; showSelectCourse(eve, $this, data); }); }else{ showSelectCourse(eve, $this, courseData); } }); }); }; function generateXnOptions(options, currentXn) { var data = [], begin = options.begin, end = options.end, currentYear = parseInt(currentXn.substring(0,4)); if (begin === null || begin === '' || typeof begin === 'undefined') { begin = currentYear - (options.down === 0? 0 : (options.down|| 5)); } if (end === null || end === '' || typeof end === 'undefined') { end = currentYear + (options.up === 0? 0 : (options.up || 5)); } for (var i = begin; i <= end; i++) { data.push({text : i + "-" + (i + 1), value : i + "-" + (i + 1)}); } return data; } //瀛﹀勾杈撳叆妗 $.fn.selectXn = function (options) { options = options || {}; var cacheKey = 'select_currentXn' + (options.schoolId? options.schoolId : ''), currentXn = _CACHE_DATA[cacheKey]; if(!currentXn) { if(options.schoolId) { var _contextPath; if(window.ptContextPath) { _contextPath = window.ptContextPath; }else{ _contextPath = contextPath; } $.ajax({ type : "get", async: false, url : _contextPath + 'gy/querySchoolAcademicYear.do?' + new Date().getTime(), dataType : "json", data: { schoolId: options.schoolId }, success : function(result){ _CACHE_DATA[cacheKey] = result.data; currentXn = result.data; }, error:function(){ alert('鏍规嵁瀛︽牎鏌ヨ瀛﹀勾澶辫触锛岃妫€鏌ュ簲鐢ㄧ▼搴忔槸鍚﹀崌绾?); } }); }else{ DataSelectRemoteCallController.getCurrentXn({ callback: function(xn){ _CACHE_DATA[cacheKey] = xn; currentXn = xn; }, async: false }); } } var data = generateXnOptions(options, currentXn); return this.each(function () { var $this = jQuery(this), combo = getSelectBtn($this, options.hideBtn); $this.attr('autocomplete', 'off'); if(!$this.hasClass('i-txt')) { $this.addClass('i-txt'); } if (options.defaultCurrent && !$this.val()) { // 鍏煎浠ュ墠鐨 if((""+currentXn).length<5){ currentXn = currentXn + "-" +(parseInt(currentXn)+1); } $this.val(currentXn); } combo && combo.click(function(eve){ AppSelect.getStaticOptions(eve, $this, $this.hiddenId, data, options.multi, true, options.callback, options.width,options.clear); }); $this.bind( 'click keyup', function(eve){ AppSelect.getStaticOptions(eve, $this, $this.hiddenId, data, options.multi, true, options.callback, options.width,options.clear); }); }); }; //瀛︽湡杈撳叆妗 $.fn.selectXq = function (options) { options = options || {}; var cacheKey = 'select_currentXq' + (options.schoolId? options.schoolId : ''), currentXq = _CACHE_DATA[cacheKey]; if(!currentXq) { if(options.schoolId) { var _contextPath; if(window.ptContextPath) { _contextPath = window.ptContextPath; }else{ _contextPath = contextPath; } $.ajax({ type : "get", async: false, url : _contextPath + 'gy/querySchoolAcademicTerm.do?' + new Date().getTime(), dataType : "json", data: { schoolId: options.schoolId }, success : function(result){ _CACHE_DATA[cacheKey] = result.data; currentXq = result.data; }, error:function(){ alert('鏍规嵁瀛︽牎鏌ヨ瀛︽湡澶辫触锛岃妫€鏌ュ簲鐢ㄧ▼搴忔槸鍚﹀崌绾?); } }); }else{ DataSelectRemoteCallController.getCurrentXq({ callback: function(xq){ _CACHE_DATA[cacheKey] = xq; currentXq = xq; }, async: false }); } } var data = [{text: '绗竴瀛︽湡', value: '绗竴瀛︽湡'}, { text: '绗簩瀛︽湡', value: '绗簩瀛︽湡' }]; return this.each(function () { var $this = jQuery(this), combo = getSelectBtn($this, options.hideBtn); $this.attr('autocomplete', 'off'); if(!$this.hasClass('i-txt')) { $this.addClass('i-txt'); } if (options.defaultCurrent && !$this.val()) { $this.val(currentXq); } combo && combo.click(function(eve){ AppSelect.getStaticOptions(eve, $this, $this.hiddenId, data, options.multi, true, options.callback, options.width,options.clear); }); $this.bind( 'click keyup', function(eve){ AppSelect.getStaticOptions(eve, $this, $this.hiddenId, data, options.multi, true, options.callback, options.width,options.clear); }); }); }; function defaultGetLength(text) { return text && text.length? text.length : 0; } //瀛楁暟闄愬埗 $.fn.textCounter = function (options) { if(isNaN(options)) { options = options || {}; }else{ options = { count: options }; } var getLength = (typeof options.getTextLength == 'function'? options.getTextLength : defaultGetLength), displayTextCounterFunc = function(displayAt, canInputTextCount){ if(canInputTextCount >= 0) { displayAt.html('杩樺彲浠ヨ緭鍏?em>'+ canInputTextCount +'瀛?).show(); }else{ displayAt.html('宸茬粡瓒呰繃'+ (canInputTextCount * -1) +'瀛?).show(); } }, alwaysDisplay = options.alwaysDisplay === true? true : false; return this.each(function () { var $this = jQuery(this), displayAt = options.displayAt, maxLength = (options.count || $this.attr('maxlength')) || 0; if(!maxLength || isNaN(maxLength) || maxLength == 0) { return; } //鍒濆鍖栨樉绀轰俊鎭殑浣嶇疆 if(displayAt) { displayAt = jQuery(displayAt).addClass('textCounter'); }else{ displayAt = jQuery('
'); $this.after(displayAt); } if(alwaysDisplay){ displayTextCounterFunc(displayAt, maxLength - getLength($this.val())); }else{ //绂诲紑鐒︾偣鐨勬椂鍊欒嚜鍔ㄩ殣钘忥紝濡傛灉杈撳叆鏈夎鐨勮瘽鍒欎笉闅愯棌 jQuery(this).blur(function(){ if(displayAt.find('em.overlimit').length == 0) { displayAt.hide(); } }); } jQuery(this).bind('focus keyup', function(){ displayTextCounterFunc(displayAt, maxLength - getLength($this.val())); }); }); }; /*鍒濆鍖栨枃浠朵笂浼犵晫闈?/ $.fn.initFileUpload=function(options){ var wrap = '
'; var btn_value = options.btnValue || "閫夋嫨鏂囦欢"; var btn_only = options.btnOnly || false; var type = options.type; //闄愬埗鐨勬枃浠剁被鍨 var fstr=''; if(btn_only){ fstr = ''; } //鎴彇涓婁紶鏂囦欢鍚 function getFileName(str){ return str.match(/[^\/|^\\]*$/)[0]; } //鍒ゆ柇鍊兼槸鍚﹀湪鏁扮粍涓 function in_array(val,arr){ var type = typeof val; if(type == "string" || type == "number"){ for(var i in arr){ if(arr[i] == val) return true; } } return false; } return this.each(function(){ var $this = jQuery(this); if($this.attr("data-initfile") == "true") { return false; } $this.wrap(wrap); jQuery(fstr).insertAfter($this); var fparent = $this.parent(); var fakeFile=fparent.find(".fake-file"); var fileName = ""; if(fakeFile && options.width){ fakeFile.width(options.width); } fparent.width(fparent.find(".fake-file").width()+fparent.find(".chose-file").width()+12);//12涓簍ext鐨刴argin+padding+border $this.change(function(){ if(undefined != type){ var fileType = $this.val().substring($this.val().lastIndexOf(".")+1); if(!in_array(fileType,type)){ return false; } } if(!btn_only){ fakeFile.val($this.val()); } fileName = getFileName($this.val()); if(typeof options.callBack ==="function"){ options.callBack(fileName); } }); $this.attr("data-initfile",true); }); }; /** * 鍒濆鍖栨悳绱㈡锛屾樉绀烘牸寮忥細鏂囨湰+杈撳叆妗?鎼滅储鎸夐挳 * @param id 鏂囨湰妗嗙殑id */ jQuery.fn.searchInput = function(options) { options = options || {}; return this.each(function(){ var $this = jQuery(this), searchBtnId = (options.id? options.id +'-search-btn' : ''), searchText = jQuery(''), searchBtn = jQuery(''), clearBtn = jQuery(''); if(jQuery(this).find('.btn-search').length == 0) { jQuery(this).html('').append(searchText).append(searchBtn).append(clearBtn); }else{ searchText = jQuery(this).find('.i-txt'); searchBtn = jQuery(this).find('.btn-search'); clearBtn = jQuery(this).find('.input-clear'); } jQuery(this).addClass('form-inline form-quicksearch'); searchText.bind('focus keyup', function(eve){ if(this.value != '') { clearBtn.show(); }else{ clearBtn.hide(); } if(eve.which == 13 && options.onSearch) { //鍥炶溅鐨勮瘽瑙﹀彂鎼滅储鎿嶄綔 options.onSearch.call(searchBtnId? document.getElementById(searchBtnId) : this); } }); if(options.defaultValue) { clearBtn.show(); } searchBtn.click(options.onSearch || function(){}); clearBtn.click(function(){ searchText.val('').focus(); jQuery(this).hide(); (options.onClear || options.onSearch || function(){}).call(this); }); }); }; /** * 鐢熸垚鍒嗛〉鏍囩锛屼负浜嗘柟渚挎坊鍔狅紝杩欓噷鐩存帴浠巎query.pagination.js鎷疯礉杩囨潵浜 * This jQuery plugin displays pagination links inside the selected elements. * * @author Gabriel Birke (birke *at* d-scribe *dot* de) * @version 1.2 * @param {int} maxentries Number of entries to paginate * @param {Object} opts Several options (see README for documentation) * @return {Object} jQuery Object */ jQuery.fn.pagination = function(maxentries, opts){ opts = jQuery.extend({ items_per_page:10, num_display_entries:10, current_page:0, num_edge_entries:0, link_to:"javascript:void(0)", prev_text:I18n.trans("涓婁竴椤?), next_text:I18n.trans("涓嬩竴椤?), ellipse_text:"...", prev_show_always:true, next_show_always:true, callback:function(){return false;} },opts||{}); return this.each(function() { /** * Calculate the maximum number of pages */ function numPages() { return Math.ceil(maxentries/opts.items_per_page); } /** * Calculate start and end point of pagination links depending on * current_page and num_display_entries. * @return {Array} */ function getInterval() { var ne_half = Math.ceil(opts.num_display_entries/2); var np = numPages(); var upper_limit = np-opts.num_display_entries; var start = current_page>ne_half?Math.max(Math.min(current_page-ne_half, upper_limit), 0):0; var end = current_page>ne_half?Math.min(current_page+ne_half, np):Math.min(opts.num_display_entries, np); return [start,end]; } /** * This is the event handling function for the pagination links. * @param {int} page_id The new page number */ function pageSelected(page_id, evt){ current_page = page_id; drawLinks(); var continuePropagation = opts.callback(page_id, panel); if (!continuePropagation) { if (evt.stopPropagation) { evt.stopPropagation(); } else { evt.cancelBubble = true; } } return continuePropagation; } /** * This function inserts the pagination links into the container element */ function drawLinks() { panel.empty(); var interval = getInterval(); var np = numPages(); // This helper function returns a handler function that calls pageSelected with the right page_id var getClickHandler = function(page_id) { return function(evt){ return pageSelected(page_id,evt); } } // Helper function for generating a single link (or a span tag if it's the current page) var appendItem = function(page_id, appendopts){ page_id = page_id<0?0:(page_id"+(appendopts.text)+""); } else { var lnk = jQuery(""+(appendopts.text)+"") .bind("click", getClickHandler(page_id)) .attr('href', opts.link_to.replace(/__id__/,page_id)); } if(appendopts.classes){lnk.addClass(appendopts.classes);} panel.append(lnk); } // Generate "Previous"-Link if(opts.prev_text && (current_page > 0 || opts.prev_show_always)){ appendItem(current_page-1,{text:opts.prev_text, classes:"prev"}); } // Generate starting points if (interval[0] > 0 && opts.num_edge_entries > 0) { var end = Math.min(opts.num_edge_entries, interval[0]); for(var i=0; i"+opts.ellipse_text+"").appendTo(panel); } } // Generate interval links for(var i=interval[0]; i 0) { if(np-opts.num_edge_entries > interval[1]&& opts.ellipse_text) { jQuery(""+opts.ellipse_text+"").appendTo(panel); } var begin = Math.max(np-opts.num_edge_entries, interval[1]); for(var i=begin; i 0) { pageSelected(current_page - 1); return true; } else { return false; } } this.nextPage = function(){ if(current_page < numPages()-1) { pageSelected(current_page+1); return true; } else { return false; } } // When all initialisation is done, draw the links drawLinks(); // call callback function opts.callback(current_page, this); }); }; // end jQuery.fn.pagination }(window.jQuery);