wzp
2021-07-19 e65183d31755a0e5fae4bf428435d2e0fd6afdc5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
 * require artDialog 5.0.4.
 *
 * @author Baishui2004
 * @Date March 21, 2014
 */
(function ($) {
 
    /**
     * Copy all properties of config obj to obj, if defaults is not undefined or null then first copy all properties of defaults obj to obj.
     */
    $.apply = $.dialog.apply = function (o, c, defaults) {
        if (defaults) {
            $.apply(o, defaults);
        }
        if (o && c && typeof c == 'object') {
            for (var p in c) {
                o[p] = c[p];
            }
        }
        return o;
    };
 
    $.getCfg = $.dialog.getCfg = function (params) {
        var cfg = {
            esc: false, // key Esc to close dialog, default true
            lock: true, // lock screen, default false
            okValue: $.bsgrid_artDialog.okValue,
            cancelValue: $.bsgrid_artDialog.cancelValue
        };
        return $.apply(params, cfg);
    };
 
    /**
     * alert dialog.
     *
     * @param msg    message
     * @param fn     callback function after trigger ok
     * @param follow HTMLElement, set dialog follow HTMLElement
     * @param title  dilog title
     */
    $.alert = $.dialog.alert = function (msg, fn, follow, title) {
        if (title == undefined) {
            title = $.bsgrid_artDialog.alertDialogTitle;
        }
        var params = {
            id: 'Alert',
            title: title,
            content: [
                '<div style="width:200px; height:75px; overflow:auto; font-size:12px; word-wrap: break-word; word-break: break-all; margin-bottom:0; padding:0;">',
                msg,
                '</div>'
            ].join(''),
            ok: true,
            beforeunload: fn
        };
        if (follow == undefined) {
            return $.dialog($.getCfg(params));
        } else {
            params = $.getCfg(params);
            return $.dialog($.apply(params, {follow: follow}));
        }
    };
 
    /**
     * confirm dialog.
     *
     * @param msg    message
     * @param ok     callback function after trigger ok
     * @param cancel callback function after trigger cancel or close
     * @param follow HTMLElement, set dialog follow HTMLElement
     * @param title  dilog title
     */
    $.confirm = $.dialog.confirm = function (msg, ok, cancel, follow, title) {
        if (ok == undefined) {
            ok = function(){
                this.close();
                return true;
            };
        }
        if (cancel == undefined) {
            cancel = function () {
                this.close();
                return false;
            };
        }
        if (title == undefined) {
            title = $.bsgrid_artDialog.confirmDialogTitle;
        }
        var params = {
            id: 'Confirm',
            title: title,
            content: [
                '<div style="width:200px; height:75px; overflow:auto; font-size:12px; word-wrap: break-word; word-break: break-all; margin-bottom:0; padding:0;">',
                msg,
                '</div>'
            ].join(''),
            ok: ok,
            cancel: cancel,
            cancelValue: $.bsgrid_artDialog.cancelValue
        };
        if (follow == undefined) {
            return $.dialog($.getCfg(params));
        } else {
            params = $.getCfg(params);
            return $.dialog($.apply(params, {follow: follow}));
        }
    };
 
    /**
     *  prompt dialog.
     *
     * @param msg           message
     * @param defaultValue  default value
     * @param fn            callback function after trigger ok
     * @param follow        HTMLElement, set dialog follow HTMLElement
     * @param title         dilog title
     */
    $.prompt = $.dialog.prompt = function (msg, defaultValue, ok, cancel, follow, title) {
        if (ok == undefined) {
            ok = function (newText) {
                return newText;
            };
        }
        if (cancel == undefined) {
            cancel = function () {
                this.close();
            };
        }
        if (title == undefined) {
            title = $.bsgrid_artDialog.promptDialogTitle;
        }
        var params = {
            id: 'Prompt',
            title: title,
            content: [
                '<div style="width:200px; font-size:12px; word-wrap: break-word; word-break: break-all; margin-bottom:5px; padding:0;">',
                msg,
                '</div>',
                '<div>',
                '<textarea class="d-input-text"',
                ' style="width:200px; height:75px; overflow:auto; font-size:12px; padding:0;">',
                defaultValue,
                '</textarea>',
                '</div>'
            ].join(''),
            initialize: function () {
                input = this.dom.content.find('.d-input-text')[0];
                input.select();
                input.focus();
            },
            ok: function () {
                return ok && ok.call(this, input.value);
            },
            cancel: cancel
        };
        defaultValue = defaultValue || '';
        var input;
        if (follow == undefined) {
            return $.dialog($.getCfg(params));
        } else {
            params = $.getCfg(params);
            return $.dialog($.apply(params, {follow: follow}));
        }
    };
 
}(this.art || this.jQuery));