Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
5 lars 1
var AppInbox = function () {
2
 
3
    var content = $('.inbox-content');
4
    var listListing = '';
5
 
6
    var loadInbox = function (el, name) {
7
        var url = 'app_inbox_inbox.html';
8
        var title = el.attr('data-title');
9
        listListing = name;
10
 
11
        App.blockUI({
12
            target: content,
13
            overlayColor: 'none',
14
            animate: true
15
        });
16
 
17
        toggleButton(el);
18
 
19
        $.ajax({
20
            type: "GET",
21
            cache: false,
22
            url: url,
23
            dataType: "html",
24
            success: function(res)
25
            {
26
                toggleButton(el);
27
 
28
                App.unblockUI('.inbox-content');
29
 
30
                $('.inbox-nav > li.active').removeClass('active');
31
                el.closest('li').addClass('active');
32
                $('.inbox-header > h1').text(title);
33
 
34
                content.html(res);
35
 
36
                if (Layout.fixContentHeight) {
37
                    Layout.fixContentHeight();
38
                }
39
            },
40
            error: function(xhr, ajaxOptions, thrownError)
41
            {
42
                toggleButton(el);
43
            },
44
            async: false
45
        });
46
 
47
        // handle group checkbox:
48
        jQuery('body').on('change', '.mail-group-checkbox', function () {
49
            var set = jQuery('.mail-checkbox');
50
            var checked = jQuery(this).is(":checked");
51
            jQuery(set).each(function () {
52
                $(this).attr("checked", checked);
53
            });
54
        });
55
    }
56
 
57
    var loadMessage = function (el, name, resetMenu) {
58
        var url = 'app_inbox_view.html';
59
 
60
        App.blockUI({
61
            target: content,
62
            overlayColor: 'none',
63
            animate: true
64
        });
65
 
66
        toggleButton(el);
67
 
68
        var message_id = el.parent('tr').attr("data-messageid");
69
 
70
        $.ajax({
71
            type: "GET",
72
            cache: false,
73
            url: url,
74
            dataType: "html",
75
            data: {'message_id': message_id},
76
            success: function(res)
77
            {
78
                App.unblockUI(content);
79
 
80
                toggleButton(el);
81
 
82
                if (resetMenu) {
83
                    $('.inbox-nav > li.active').removeClass('active');
84
                }
85
                $('.inbox-header > h1').text('View Message');
86
 
87
                content.html(res);
88
                Layout.fixContentHeight();
89
            },
90
            error: function(xhr, ajaxOptions, thrownError)
91
            {
92
                toggleButton(el);
93
            },
94
            async: false
95
        });
96
    }
97
 
98
    var initWysihtml5 = function () {
99
        $('.inbox-wysihtml5').wysihtml5({
100
            "stylesheets": ["../assets/global/plugins/bootstrap-wysihtml5/wysiwyg-color.css"]
101
        });
102
    }
103
 
104
    var initFileupload = function () {
105
 
106
        $('#fileupload').fileupload({
107
            // Uncomment the following to send cross-domain cookies:
108
            //xhrFields: {withCredentials: true},
109
            url: '../assets/global/plugins/jquery-file-upload/server/php/',
110
            autoUpload: true
111
        });
112
 
113
        // Upload server status check for browsers with CORS support:
114
        if ($.support.cors) {
115
            $.ajax({
116
                url: '../assets/global/plugins/jquery-file-upload/server/php/',
117
                type: 'HEAD'
118
            }).fail(function () {
119
                $('<span class="alert alert-error"/>')
120
                    .text('Upload server currently unavailable - ' +
121
                    new Date())
122
                    .appendTo('#fileupload');
123
            });
124
        }
125
    }
126
 
127
    var loadCompose = function (el) {
128
        var url = 'app_inbox_compose.html';
129
 
130
        App.blockUI({
131
            target: content,
132
            overlayColor: 'none',
133
            animate: true
134
        });
135
 
136
        toggleButton(el);
137
 
138
        // load the form via ajax
139
        $.ajax({
140
            type: "GET",
141
            cache: false,
142
            url: url,
143
            dataType: "html",
144
            success: function(res)
145
            {
146
                App.unblockUI(content);
147
                toggleButton(el);
148
 
149
                $('.inbox-nav > li.active').removeClass('active');
150
                $('.inbox-header > h1').text('Compose');
151
 
152
                content.html(res);
153
 
154
                initFileupload();
155
                initWysihtml5();
156
 
157
                $('.inbox-wysihtml5').focus();
158
                Layout.fixContentHeight();
159
            },
160
            error: function(xhr, ajaxOptions, thrownError)
161
            {
162
                toggleButton(el);
163
            },
164
            async: false
165
        });
166
    }
167
 
168
    var loadReply = function (el) {
169
        var messageid = $(el).attr("data-messageid");
170
        var url = 'app_inbox_reply.html';
171
 
172
        App.blockUI({
173
            target: content,
174
            overlayColor: 'none',
175
            animate: true
176
        });
177
 
178
        toggleButton(el);
179
 
180
        // load the form via ajax
181
        $.ajax({
182
            type: "GET",
183
            cache: false,
184
            url: url,
185
            dataType: "html",
186
            success: function(res)
187
            {
188
                App.unblockUI(content);
189
                toggleButton(el);
190
 
191
                $('.inbox-nav > li.active').removeClass('active');
192
                $('.inbox-header > h1').text('Reply');
193
 
194
                content.html(res);
195
                $('[name="message"]').val($('#reply_email_content_body').html());
196
 
197
                handleCCInput(); // init "CC" input field
198
 
199
                initFileupload();
200
                initWysihtml5();
201
                Layout.fixContentHeight();
202
            },
203
            error: function(xhr, ajaxOptions, thrownError)
204
            {
205
                toggleButton(el);
206
            },
207
            async: false
208
        });
209
    }
210
 
211
    var handleCCInput = function () {
212
        var the = $('.inbox-compose .mail-to .inbox-cc');
213
        var input = $('.inbox-compose .input-cc');
214
        the.hide();
215
        input.show();
216
        $('.close', input).click(function () {
217
            input.hide();
218
            the.show();
219
        });
220
    }
221
 
222
    var handleBCCInput = function () {
223
 
224
        var the = $('.inbox-compose .mail-to .inbox-bcc');
225
        var input = $('.inbox-compose .input-bcc');
226
        the.hide();
227
        input.show();
228
        $('.close', input).click(function () {
229
            input.hide();
230
            the.show();
231
        });
232
    }
233
 
234
    var toggleButton = function(el) {
235
        if (typeof el == 'undefined') {
236
            return;
237
        }
238
        if (el.attr("disabled")) {
239
            el.attr("disabled", false);
240
        } else {
241
            el.attr("disabled", true);
242
        }
243
    }
244
 
245
    return {
246
        //main function to initiate the module
247
        init: function () {
248
 
249
            // handle compose btn click
250
            $('.inbox').on('click', '.compose-btn', function () {
251
                loadCompose($(this));
252
            });
253
 
254
            // handle discard btn
255
            $('.inbox').on('click', '.inbox-discard-btn', function(e) {
256
                e.preventDefault();
257
                loadInbox($(this), listListing);
258
            });
259
 
260
            // handle reply and forward button click
261
            $('.inbox').on('click', '.reply-btn', function () {
262
                loadReply($(this));
263
            });
264
 
265
            // handle view message
266
            $('.inbox').on('click', '.view-message', function () {
267
                loadMessage($(this));
268
            });
269
 
270
            // handle inbox listing
271
            $('.inbox-nav > li > a').click(function () {
272
                loadInbox($(this), 'inbox');
273
            });
274
 
275
            //handle compose/reply cc input toggle
276
            $('.inbox-content').on('click', '.mail-to .inbox-cc', function () {
277
                handleCCInput();
278
            });
279
 
280
            //handle compose/reply bcc input toggle
281
            $('.inbox-content').on('click', '.mail-to .inbox-bcc', function () {
282
                handleBCCInput();
283
            });
284
 
285
            //handle loading content based on URL parameter
286
            if (App.getURLParameter("a") === "view") {
287
                loadMessage();
288
            } else if (App.getURLParameter("a") === "compose") {
289
                loadCompose();
290
            } else {
291
               $('.inbox-nav > li:first > a').click();
292
            }
293
 
294
        }
295
 
296
    };
297
 
298
}();
299
 
300
jQuery(document).ready(function() {
301
    AppInbox.init();
302
});