david-PC\david
2018-06-12 f240ac3ccd37c541cab2c21cfc433d3510999a3c
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
    // ================================Dialog===================================//
    Dialog = {};
        
    $.fm.DialogClass = Control.subClass({
        template: [
             '<div class="win_mask"></div>',
             '<div class="dialog_mask" style="display: none; z-index: 1001;" align="center">',
             '<div class="dialog">',
                '<div class="dialog_header" id="title">',
                    '信息提示',
                '</div>',
                '<div class="dialog_body" id="dialog_body">',
                    '<div class="dialog_content" id="dialog_content">',
                        '<div class="dialog_image" id="image"></div>',
                        '<span id="body_title"></span>',
                        '<div class="dialog_text" id="text"></div>',
                    '</div>',
                '</div>',
                '<div class="dialog_footer" id="dialog_footer">',
                    '<button class="button btn_light" id="btn_cancel">取消</button>',
                    '<button class="button btn_blue" id="btn_ok" style="margin-left:8px">确定</button>',
                '</div>',            
            '</div>',
            '</div>'
        ],
    
        init: function(options) {
            options = options ? options : {};
            Control.call(this, options);
            
            this.createEl();
        },
        
        createEl: function() {
            var me = this;
            var el = this.el = $(this.template.join(""));
            
            this.title = $("#title", el);
            this.body = $("#dialog_body", el);
            this.body_title = $("#body_title", el);
            this.dialog_content = $("#dialog_content", el);
            this.dialog_footer = $("#dialog_footer", 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);
        },
        
        databox: function(title, callback, config) {
            var input = config.input || "";
            var body_title = config.body_title || "";
            
            if (config.onShow) {
                onShow();
            }
            
            this.title.html(title);
            this.body.removeAttr("class");
            this.dialog_content.removeAttr("class");
            this.image.removeAttr("class");
            this.text.removeAttr("class");
            this.dialog_footer.removeAttr("class");
            this.body.addClass("databox_body");
            this.dialog_content.addClass("databox_content");
            this.image.addClass("databox_image");
            this.text.addClass("databox_text");
            this.dialog_footer.addClass("databox_footer");
            
            this.body_title.html(body_title);
            this.text.html(input);
            this.btn_cancel.show();            
            
            this.callback = callback;
            
            this.el.show();
        },
        
        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, callback) {
            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", "36px");
            }
            
            this.image.removeClass("icon_confirm");
            this.image.addClass("icon_alert");            
            this.btn_cancel.hide();
            
            this.callback = callback ? callback : null;
            
            this.el.show();
        }
    });        
    
    Dialog.databox = function(title, callback, config) {
        config = config || {};
        
        if (!this.instance) {
            this.instance = new $.fm.DialogClass();
        }
        this.instance.databox(title, callback, config);
    };
    
    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, callback) {
        if (!this.instance) {
            this.instance = new $.fm.DialogClass();
        }
        this.instance.alert("提醒", text1, text2, callback);
    };
    
    Dialog.wait = function(text) {
        if (!this.instance) {
            this.instance = new $.fm.DialogClass();
        }
        this.instance.wait("提醒", text1, text2);        
    };