首页 > 代码库 > AspxGridView 弹框选择器 JS

AspxGridView 弹框选择器 JS

function Dictionary() {    this.data = http://www.mamicode.com/new Array();    this.put = function (key, value) {        this.data[key] = value;    };    this.get = function (key) {        return this.data[key];    };    this.remove = function (key) {        this.data[key] = null;    };    this.isEmpty = function () {        return this.data.length == 0;    };    this.size = function () {        return this.data.length;    };};$.fn.set = function (text) {    sele.SetValue(this, text);}/*选择器(王志强-2014-04-26)*/var sele = {    rIndex: 1, para: { id: 1, name: "", parameter: "" },    paras: new Dictionary(),    Init: function (options) {        this.SetOptions(options);        this.gname = this.options.gname;        this.fname = this.options.fname;        var controls = this.options.controls;        var column = gridDefault.GetColumnByField(this.fname);        sele[this.fname] = $("input[name=‘" + this.gname + "$DXEditor" + column.index + "‘]");        for (var i = 0; i < controls.length; i++) {            var c = gridDefault.GetColumnByField(controls[i]);            if (c)                sele[controls[i]] = $("input[name=‘" + this.gname + "$DXEditor" + c.index + "‘][autocomplete!=‘off‘]");        }        var cIndex = parseInt(column.index);        cIndex = cIndex < 10 ? "_" + cIndex : cIndex;        var evObj = {            EventObj: $("td[id^=" + this.gname + "_tccell][id$=" + cIndex + "]"),            InputObj: $("input[name=‘" + this.gname + "$DXEditor" + column.index + "‘][autocomplete!=‘off‘]")        }        return evObj;    },    SetOptions: function (_options) {        this.options = {            gname: "ASPxGridView1",            fname: "SupplierId",            controls: []        };        $.extend(this.options, _options || {});    },    DialogOpen: function (url, _options, control, callback) {        var _this = this;        var options = {            title: "标题",            id: "msgDialog",            width: $(window).width() / 3 + "px",            height: $(window).height() / 3 + "px",            lock: false,            drag: false,            position: "default"        };        $.extend(options, _options || {});        var kHeight = 0;        var cHeight = parseInt(options.height.replace("px", ""));        var cWidth = parseInt(options.width.replace("px", ""));        try {            if (($(control).offset().top + $(control).height() - $(document).scrollTop() + cHeight > $(window).height())                                 || $(control).offset().left + $(control).width() - $(document).scrollLeft() + +cWidth > $(window).width()) {            }            if ($(control).offset().top == 0 || $(control).offset().left == 0) {                options.position = "default";            }        } catch (e) {            options.position = "default";        }        switch (options.position) {            case "default":                options.top = ($(window).height() - cHeight + kHeight) / 2 + $(document).scrollTop() + "px";                options.left = ($(window).width() - cWidth) / 2 + "px";                break;            case "right":                options.top = $(control).offset().top - cHeight / 2 + kHeight + "px";                options.left = $(control).offset().left + $(control).width() + "px";                break;            case "right-bottom":                options.top = $(control).offset().top + $(control).height() + kHeight + "px";                options.left = $(control).offset().left + $(control).width() + "px";                break;            case "bottom":                options.top = $(control).offset().top-2 +  kHeight + "px";                options.left = $(control).offset().left-7 + "px";                break;        }        if (options.top == "0px" || options.top == "0px") {            options.top = ($(window).height() - cHeight + kHeight) / 2 + $(document).scrollTop() + "px";            options.left = ($(window).width() - cWidth) / 2 + "px";        }        art.dialog.data("callback", function (data) {            callback(data);        });        if ((typeof sele.paras.get(sele.rIndex)) != "undefined") {            sele.para.id = sele.paras.get(sele.rIndex);        } else if (gridDefault.GetRowKey(sele.rIndex) != null) {            sele.para.id = gridDefault.GetRowKey(sele.rIndex);        } else {            sele.para.id = 0;        }        url += (url.indexOf("?") != -1) ? "&" : "?";        url += "id=" + sele.para.id + "&name=" + decodeURIComponent(sele.para.name) + "&parameter=" + decodeURIComponent(sele.para.parameter) + "";        art.dialog.open(url, options);        $("html").bind("click", function () { art.dialog({ id: options.id }).close(); $("html").unbind("click"); });    },    SetValue: function (o, txt) {        gridDefault.StartEditRow(this.rIndex);        o.val(Math.ceil(Math.random() * 10) + txt);        o.change();        o.val(txt);        o.change().blur();        gridDefault.StartEditRow(this.rIndex);    },    ShowAdvanceSelector: function (fname, controls, url, options, callback, dataType, eventObj) {        var _this = this;        var obj = this.Init({ fname: fname, controls: controls });                    $(eventObj).live("click", function () {                _this.DialogOpen(url, options, obj.InputObj, function (data) {                    if (!dataType) { dataType = "string"; }                    dataType = dataType.toLocaleLowerCase();                    var result = data;                    if (dataType == "json") {                        result = eval(‘(‘ + data + ‘)‘);                    }                    callback(result);                });            });                    obj.EventObj.live("click", function () {                _this.DialogOpen(url, options, obj.InputObj, function (data) {                    if (!dataType) { dataType = "string"; }                    dataType = dataType.toLocaleLowerCase();                    var result = data;                    if (dataType == "json") {                        result = eval(‘(‘ + data + ‘)‘);                    }                    callback(result);                });            });               obj.InputObj.live("click", function () { return false; });    }};