1
|
$(function() {
|
2
|
// mailbox init functions
|
3
|
altair_mailbox.init();
|
4
|
});
|
5
|
|
6
|
// variables
|
7
|
var $mailbox = $('#mailbox'),
|
8
|
$split_view_btn = $('#mailbox_list_split'),
|
9
|
$combined_view_btn = $('#mailbox_list_combined'),
|
10
|
$msg_list = $mailbox.find('.md-card-list'),
|
11
|
anim_duration = 140;
|
12
|
|
13
|
altair_mailbox = {
|
14
|
init: function() {
|
15
|
// split/combined list
|
16
|
altair_mailbox.list_switch();
|
17
|
// assign colors to each message (data-message-category-color)
|
18
|
altair_mailbox.list_category_color();
|
19
|
// select messages
|
20
|
altair_mailbox.select_messages();
|
21
|
// show/hide single message
|
22
|
altair_mailbox.toggle_message();
|
23
|
// compose message
|
24
|
altair_mailbox.create_message();
|
25
|
},
|
26
|
// split/combined list
|
27
|
list_switch: function() {
|
28
|
$combined_view_btn.on('click', function(e) {
|
29
|
e.preventDefault();
|
30
|
e.stopPropagation();
|
31
|
$combined_view_btn.velocity("transition.expandOut", {
|
32
|
duration: anim_duration,
|
33
|
easing: easing_swiftOut,
|
34
|
begin: function() {
|
35
|
$mailbox
|
36
|
.addClass('md-card-list-combined')
|
37
|
.find('.md-card-list-header').not('.md-card-list-header-combined')
|
38
|
.velocity("transition.expandOut", {
|
39
|
duration: anim_duration,
|
40
|
easing: easing_swiftOut,
|
41
|
begin: function() {
|
42
|
$msg_list.each(function(index) {
|
43
|
if(index != 0 ) {
|
44
|
$(this).velocity({
|
45
|
marginTop: 0
|
46
|
}, {
|
47
|
duration: (anim_duration * index) + 200,
|
48
|
easing: easing_swiftOut
|
49
|
})
|
50
|
}
|
51
|
});
|
52
|
},
|
53
|
complete: function() {
|
54
|
$mailbox.find('.md-card-list-header-combined').velocity("transition.expandIn", {
|
55
|
duration: anim_duration,
|
56
|
easing: easing_swiftOut
|
57
|
})
|
58
|
}
|
59
|
});
|
60
|
},
|
61
|
complete: function() {
|
62
|
$split_view_btn.velocity("transition.expandIn", {
|
63
|
duration: anim_duration,
|
64
|
easing: easing_swiftOut
|
65
|
})
|
66
|
}
|
67
|
});
|
68
|
});
|
69
|
|
70
|
$split_view_btn.on('click', function(e) {
|
71
|
e.preventDefault();
|
72
|
$split_view_btn.velocity("transition.expandOut", {
|
73
|
duration: anim_duration,
|
74
|
easing: easing_swiftOut,
|
75
|
begin: function() {
|
76
|
var $list = $mailbox.find('.md-card-list'),
|
77
|
list_length = $list.length;
|
78
|
|
79
|
$mailbox
|
80
|
.find('.md-card-list-header-combined')
|
81
|
.velocity("transition.expandOut", {
|
82
|
duration: anim_duration,
|
83
|
easing: easing_swiftOut
|
84
|
});
|
85
|
|
86
|
$list.reverse().each(function(index) {
|
87
|
if(index != list_length-1 ) {
|
88
|
$(this).velocity("reverse", {
|
89
|
duration: anim_duration + 200,
|
90
|
easing: easing_swiftOut
|
91
|
})
|
92
|
}
|
93
|
});
|
94
|
setTimeout(function() {
|
95
|
$mailbox.removeClass('md-card-list-combined');
|
96
|
$('.md-card-list-header')
|
97
|
.not('.md-card-list-header-combined')
|
98
|
.show()
|
99
|
.velocity("reverse");
|
100
|
},500);
|
101
|
},
|
102
|
complete: function() {
|
103
|
$combined_view_btn.velocity("transition.expandIn", {
|
104
|
duration: anim_duration,
|
105
|
easing: easing_swiftOut
|
106
|
})
|
107
|
}
|
108
|
});
|
109
|
|
110
|
});
|
111
|
|
112
|
if($mailbox.hasClass('md-card-list-combined')) {
|
113
|
$combined_view_btn.click();
|
114
|
} else {
|
115
|
$split_view_btn.hide();
|
116
|
}
|
117
|
|
118
|
},
|
119
|
// assign colors to each message (data-message-category-color)
|
120
|
list_category_color: function() {
|
121
|
$('.md-card-list > ul > li').each(function() {
|
122
|
$this = $(this);
|
123
|
var thisCatColor = $this.attr('data-message-category-color');
|
124
|
if(thisCatColor) {
|
125
|
$(this).find('span.md-card-list-item-avatar').css({
|
126
|
backgroundColor: '#'+thisCatColor
|
127
|
})
|
128
|
}
|
129
|
})
|
130
|
},
|
131
|
// select messages
|
132
|
select_messages: function () {
|
133
|
|
134
|
$mailbox.on('ifChanged', '[data-md-icheck]', function() {
|
135
|
$(this).is(':checked')
|
136
|
?
|
137
|
$(this).closest('li').addClass('md-card-list-item-selected')
|
138
|
:
|
139
|
$(this).closest('li').removeClass('md-card-list-item-selected');
|
140
|
});
|
141
|
|
142
|
$('#mailbox_select_all').on('ifChanged',function() {
|
143
|
var $this = $(this);
|
144
|
$mailbox.find('[data-md-icheck]').each(function() {
|
145
|
$this.is(':checked')
|
146
|
?
|
147
|
$(this).iCheck('check')
|
148
|
:
|
149
|
$(this).iCheck('uncheck');
|
150
|
})
|
151
|
});
|
152
|
},
|
153
|
// show/hide single message
|
154
|
toggle_message: function() {
|
155
|
|
156
|
$mailbox.on('click', '.md-card-list ul > li', function(e) {
|
157
|
|
158
|
if ( !$(e.target).closest('.md-card-list-item-menu').length && !$(e.target).closest('.md-card-list-item-select').length ) {
|
159
|
|
160
|
var $this = $(this);
|
161
|
|
162
|
if (!$this.hasClass('item-shown')) {
|
163
|
// get height of clicked message
|
164
|
var el_min_height = $this.height() + $this.children('.md-card-list-item-content-wrapper').actual("height");
|
165
|
|
166
|
// hide opened message
|
167
|
$mailbox.find('.item-shown').velocity("reverse", {
|
168
|
begin: function (elements) {
|
169
|
$(elements).removeClass('item-shown').children('.md-card-list-item-content-wrapper').hide().velocity("reverse");
|
170
|
}
|
171
|
});
|
172
|
|
173
|
// show message
|
174
|
$this.velocity({
|
175
|
marginTop: 40,
|
176
|
marginBottom: 40,
|
177
|
marginLeft: -20,
|
178
|
marginRight: -20,
|
179
|
minHeight: el_min_height
|
180
|
}, {
|
181
|
duration: 300,
|
182
|
easing: easing_swiftOut,
|
183
|
begin: function (elements) {
|
184
|
$(elements).addClass('item-shown');
|
185
|
},
|
186
|
complete: function (elements) {
|
187
|
// show: message content, reply form
|
188
|
$(elements).children('.md-card-list-item-content-wrapper').show().velocity({
|
189
|
opacity: 1
|
190
|
});
|
191
|
|
192
|
// scroll to message
|
193
|
var container = $('body'),
|
194
|
scrollTo = $(elements);
|
195
|
container.animate({
|
196
|
scrollTop: scrollTo.offset().top - $page_content.offset().top - 8
|
197
|
}, 1000, bez_easing_swiftOut);
|
198
|
|
199
|
}
|
200
|
});
|
201
|
}
|
202
|
}
|
203
|
|
204
|
});
|
205
|
// hide message on: outside click, esc button
|
206
|
$(document).on('click keydown', function(e) {
|
207
|
if (
|
208
|
( !$(e.target).closest('li.item-shown').length ) || e.which == 27
|
209
|
) {
|
210
|
$mailbox.find('.item-shown').velocity("reverse", {
|
211
|
begin: function(elements) {
|
212
|
$(elements).removeClass('item-shown').children('.md-card-list-item-content-wrapper').hide().velocity("reverse");
|
213
|
}
|
214
|
});
|
215
|
}
|
216
|
});
|
217
|
},
|
218
|
// compose message
|
219
|
create_message: function() {
|
220
|
|
221
|
// callback on modal show
|
222
|
$('#mailbox_new_message').on('show.uk.modal',function() {
|
223
|
});
|
224
|
|
225
|
// file upload (check dropzone.js for more complex component)
|
226
|
var progressbar = $("#mail_progressbar"),
|
227
|
bar = progressbar.find('.uk-progress-bar'),
|
228
|
settings = {
|
229
|
action: './upload/', // upload url
|
230
|
single: false,
|
231
|
loadstart: function() {
|
232
|
bar.css("width", "0%").text("0%");
|
233
|
progressbar.removeClass("uk-hidden uk-progress-danger");
|
234
|
},
|
235
|
progress: function(percent) {
|
236
|
percent = Math.ceil(percent);
|
237
|
bar.css("width", percent+"%").text(percent+"%");
|
238
|
if(percent == '100') {
|
239
|
setTimeout(function(){
|
240
|
//progressbar.addClass("uk-hidden");
|
241
|
}, 1500);
|
242
|
}
|
243
|
},
|
244
|
error: function(event) {
|
245
|
progressbar.addClass("uk-progress-danger");
|
246
|
bar.css({'width':'100%'}).text('100%');
|
247
|
},
|
248
|
abort: function(event) {
|
249
|
console.log(event);
|
250
|
},
|
251
|
complete: function(response, xhr) {
|
252
|
console.log(response);
|
253
|
}
|
254
|
};
|
255
|
|
256
|
var select = UIkit.uploadSelect($("#mail_upload-select"), settings),
|
257
|
drop = UIkit.uploadDrop($("#mail_upload-drop"), settings);
|
258
|
|
259
|
}
|
260
|
};
|