var $ae = new function () { this.applyAwesomeStyles = function () { $(".ae-lookup-openbtn").empty().prepend(''); $(".ae-lookup-clearbtn").empty().prepend(''); $ae.mybutton(".ae-lookup-openbtn"); $ae.mybutton(".ae-lookup-clearbtn"); } this.mybutton = function (sel) { $(sel).unbind('mousedown mouseup mouseleave') .hover(function () { $(this).addClass("ui-state-hover"); }, function () { $(this).removeClass("ui-state-hover"); }) .bind({ 'mousedown mouseup': function () { $(this).toggleClass('ui-state-active'); } }) .addClass("ui-state-default").addClass("ui-corner-all") .bind('mouseleave', function () { $(this).removeClass('ui-state-active') }); } this.interactive = function (o) { $(o + ' input:text').keyup(function (e) { if ($ae.isKeyChange(e.which)) { $(o).submit(); } }); $(o + ' input[type="hidden"], ' + o + ' .ae-array').change(function () { $(o).submit(); }); } this.isKeyChange = function (w) { if (w < 9 || w > 45 && w < 91 || w > 93 && w < 112 || w > 185 || w == 32) return true; return false; } this.fullscreen = function (o) { $(window).bind("resize", function (e) { $(o).dialog("option", { height: $(window).height() - 50, width: $(window).width() - 50 }).trigger('dialogresize'); }); } loadRadioList = function (o, url, parent) { var data = new Array(); addval(data, parent, "parent"); addval(data, o, "key"); $.post(url, data, function (d) { $("#" + o + "list").empty(); if (typeof (d) == 'object') { var found = false; $.each(d, function (i, j) { var sel = ""; if (j.Selected == true) { sel = "checked = 'checked'"; $('#' + o).val(j.Value).change(); found = true; }; $("#" + o + "list").append("
"); if (!found) $('#' + o).val('').change(); }); } else { $('#' + o).val('').change(); } }); } this.radioList = function (o, url, parent) { loadRadioList(o, url, parent); $('#' + o + 'list').on('change', 'input', function () { $('#' + o).val($('#' + o + 'list input:checked').val()).change(); }); if (parent) $('#' + parent).change(function () { loadRadioList(o, url, parent); }); } this.checkBoxList = function (o, url, parent, prop, htmlAttributes, pkeys, pvals) { loadCheckBoxList(o, url, parent, prop, htmlAttributes, pkeys, pvals); // 2012-3-6 zhx 调整为click事件 因为使用change在360和ie下无效 //$('#' + o + 'list input').live('change', function () { syncCheckBoxList(o, prop); }); $('#' + o + 'list').on('click', 'input', function () { linkAgeCheckAll(this,prop);syncCheckBoxList(o, prop); }); if (parent) $('#' + parent).change(function () { loadCheckBoxList(o, url, parent, prop, htmlAttributes, pkeys, pvals); }); } syncCheckBoxList = function (o, prop) { $('#' + o).empty(); var ids = ''; $('#' + o + 'list input:checked').each(function () { if (ids.length > 0) ids += ","; ids += $(this).val(); }); $('#' + o).prepend(''); // 2011-11-11 zhx 调整 原来的选项列表后台获取 全是双份 // $('#' + o + 'list input:checked').each(function () { // $('#' + o).prepend(''); // }); $('#' + o).change(); } loadCheckBoxList = function (o, url, parent, prop, htmlAttributes, pkeys, pvals) { var data = new Array(); addval(data, o, "keys"); addval(data, parent, "parent"); $.each(pkeys, function (i, k) { data.push({ name: k, value: pvals[i] }); }); $.post(url, data, function (d) { $('#' + o + 'list').empty(); if (typeof d == 'object') { $.each(d, function (i, j) { var sel = j.Selected ? 'checked="checked"' : ""; $('#' + o + 'list').append(''); //$('#' + o + 'list').append(''); }); } $('#' + o + 'list').change(); syncCheckBoxList(o, prop); }); } addval = function (arr, id, key) { if (!id) return; var o = $('#' + id); if (o.hasClass('ae-array')) { $('#' + id + ' input').each(function () { arr.push({ name: key, value: $(this).val() }); }); } else { arr.push({ name: key, value: o.val() }); } } this.ajaxDropdown = function (o, p, url, keys, values, pkeys, pvals) { this.loadAjaxDropdown(o, p, url, false, keys, values, pkeys, pvals); $("#" + o + "dropdown").keyup(function () { $(this).change(); }).change(function () { $('#' + o).val($('#' + o + 'dropdown').val()).trigger('change'); }); if (p) $('#' + p).change(function () { $ae.loadAjaxDropdown(o, p, url, true, keys, values, pkeys, pvals); }); $.each(keys, function (i, k) { $('#' + k).change(function () { $ae.loadAjaxDropdown(o, p, url, true, keys, values, pkeys, pvals); }); }); //if keys foreach key change same } this.loadAjaxDropdown = function (o, p, url, c, keys, values, pkeys, pvals) { if (c) $('#' + o).val(null); var data = new Array(); addval(data, o, "key"); addval(data, p, "parent"); $.each(pkeys, function (i, k) { data.push({ name: k, value: pvals[i] }); }); $.each(keys, function (i, k) { addval(data, k, values[i]); }); $.post(url, data, function (d) { $("#" + o + "dropdown").empty(); if (typeof (d) == 'object') $.each(d, function (i, j) { var sel = ""; if (j.Selected == true) sel = "selected = 'selected'"; $("#" + o + "dropdown").append(""); }); if (c) $("#" + o + "dropdown").trigger('change'); }); } this.autocomplete = function (o, k, p, u, mr, delay, minLen, keys, values, pkeys, pvals) { $('#' + o).autocomplete({ delay: delay, minLength: minLen, source: function (request, response) { var data = new Array(); data.push({ name: 'searchText', value: request.term }); data.push({ name: 'maxResults', value: mr }); addval(data, p, "parent"); $.each(keys, function (i, k) { addval(data, k, values[i]); }); $.each(pkeys, function (i, k) { data.push({ name: k, value: pvals[i] }); }); $.ajax({ url: u, type: "POST", dataType: "json", data: data, success: function (d) { response($.map(d, function (o) { return { label: o.Text, value: o.Text, id: o.Id} })); } }); } }); $('#' + o).bind("autocompleteselect", function (e, ui) { $('#' + k).val(ui.item ? ui.item.id : null).trigger('change'); $('#' + o).trigger('change'); }); //火狐中文输入完毕时不会触发KeyDown 所以在输入完毕会触发的KeyUp事件中 触发KeyDown $('#' + o).keyup(function (e) { if (e.which != '13') $("#" + k).val(null).trigger('change'); $('#' + o).trigger('keydown'); }); } this.popup = function (o, w, h, title, modal, pos, res, btns, fulls) { var dragg = true; if (fulls) { res = false; modal = true; dragg = false; } $("#" + o).dialog({ show: "fade", width: fulls ? $(window).width() - 50 : w, height: fulls ? $(window).height() - 50 : h, title: title, modal: modal, position: { my: pos, at: pos, of: window }, resizable: res, draggable: dragg, buttons: btns, autoOpen: false, close: function (e, ui) { $("#" + o).find('*').remove(); } }); if (modal || fulls) $("#" + o).dialog("option", { dialogClass: 'ae-fixed' }); if (fulls) this.fullscreen("#" + o); } this.loadLookupDisplay = function (o, url, isChange) { $('#ld' + o).val(''); var id = $('#' + o).val(); if (id) $.get(url, { id: id }, function (d) { $("#ld" + o).val(d); if (isChange) { // 2011-11-10 zhx 增加触发改变事件 $("#ld" + o).change(); } }); } this.loadMultiLookupDisplay = function (o, url, isChange) { var ids = $("#" + o + " input").map(function () { return $(this).attr("value"); }).get(); $("#ld" + o).html(''); if (ids.length != 0) $.post(url, $.param({ selected: ids }, true), function (d) { $.each(d, function () { $("#ld" + o).append('