1
|
$(function() {
|
2
|
// user edit
|
3
|
altair_user_edit.init();
|
4
|
});
|
5
|
|
6
|
altair_user_edit = {
|
7
|
init: function() {
|
8
|
// user edit form
|
9
|
altair_user_edit.edit_form();
|
10
|
// user languages
|
11
|
altair_user_edit.user_languages();
|
12
|
// user groups
|
13
|
altair_user_edit.user_groups();
|
14
|
// user todo_list
|
15
|
altair_user_edit.user_todo();
|
16
|
},
|
17
|
edit_form: function() {
|
18
|
// form variables
|
19
|
var $user_edit_form = $('#user_edit_form'),
|
20
|
$user_edit_submit_btn = $('#user_edit_submit'),
|
21
|
user_name = $('#user_edit_uname'),
|
22
|
user_name_control= $('#user_edit_uname_control'),
|
23
|
user_position = $('#user_edit_position'),
|
24
|
user_position_control = $('#user_edit_position_control');
|
25
|
|
26
|
user_name_control
|
27
|
// insert user name into form input
|
28
|
.val(user_name.text())
|
29
|
// change user name on keyup
|
30
|
.on('keyup',function() {
|
31
|
user_name.text(user_name_control.val())
|
32
|
});
|
33
|
// update inputs
|
34
|
altair_md.update_input(user_name_control);
|
35
|
|
36
|
|
37
|
user_position_control
|
38
|
// insert user position into form input
|
39
|
.val(user_position.text())
|
40
|
// change user position on keyup
|
41
|
.on('keyup',function() {
|
42
|
user_position.text(user_position_control.val())
|
43
|
});
|
44
|
// update inputs
|
45
|
altair_md.update_input(user_position_control);
|
46
|
|
47
|
// submit form
|
48
|
$user_edit_submit_btn.on('click',function(e) {
|
49
|
e.preventDefault();
|
50
|
var form_serialized = JSON.stringify( $user_edit_form.serializeObject(), null, 2 );
|
51
|
UIkit.modal.alert('<p>User data:</p><pre>' + form_serialized + '</pre>');
|
52
|
})
|
53
|
},
|
54
|
user_languages: function() {
|
55
|
|
56
|
$('#user_edit_languages').selectize({
|
57
|
plugins: {
|
58
|
'remove_button': {
|
59
|
label : ''
|
60
|
}
|
61
|
},
|
62
|
placeholder: 'Select language(s)',
|
63
|
options: [
|
64
|
{id: 1, title: 'English', value: 'gb'},
|
65
|
{id: 2, title: 'French', value: 'fr'},
|
66
|
{id: 3, title: 'Chinese', value: 'cn'},
|
67
|
{id: 4, title: 'Dutch', value: 'nl'},
|
68
|
{id: 5, title: 'Italian', value: 'it'},
|
69
|
{id: 6, title: 'Spanish', value: 'es'},
|
70
|
{id: 7, title: 'German', value: 'de'},
|
71
|
{id: 8, title: 'Polish', value: 'pl'}
|
72
|
],
|
73
|
render: {
|
74
|
option: function(data, escape) {
|
75
|
return '<div class="option">' +
|
76
|
'<i class="item-icon flag-' + escape(data.value).toUpperCase() + '"></i>' +
|
77
|
'<span>' + escape(data.title) + '</span>' +
|
78
|
'</div>';
|
79
|
},
|
80
|
item: function(data, escape) {
|
81
|
return '<div class="item"><i class="item-icon flag-' + escape(data.value).toUpperCase() + '"></i>' + escape(data.title) + '</div>';
|
82
|
}
|
83
|
},
|
84
|
maxItems: null,
|
85
|
valueField: 'value',
|
86
|
labelField: 'title',
|
87
|
searchField: 'title',
|
88
|
create: false,
|
89
|
onDropdownOpen: function($dropdown) {
|
90
|
$dropdown
|
91
|
.hide()
|
92
|
.velocity('slideDown', {
|
93
|
begin: function() {
|
94
|
$dropdown.css({'margin-top':'0'})
|
95
|
},
|
96
|
duration: 200,
|
97
|
easing: easing_swiftOut
|
98
|
})
|
99
|
},
|
100
|
onDropdownClose: function($dropdown) {
|
101
|
$dropdown
|
102
|
.show()
|
103
|
.velocity('slideUp', {
|
104
|
complete: function() {
|
105
|
$dropdown.css({'margin-top':''})
|
106
|
},
|
107
|
duration: 200,
|
108
|
easing: easing_swiftOut
|
109
|
})
|
110
|
}
|
111
|
});
|
112
|
},
|
113
|
user_groups: function() {
|
114
|
|
115
|
var $user_groups = $('#user_groups'),
|
116
|
$all_groups = $('#all_groups'),
|
117
|
$user_groups_control = $('#user_groups_control'),
|
118
|
serialize_user_group = function() {
|
119
|
var serialized_data = $user_groups.data("sortable").serialize();
|
120
|
$user_groups_control.val( JSON.stringify(serialized_data) );
|
121
|
};
|
122
|
|
123
|
|
124
|
var sortable_user_groups = UIkit.sortable($user_groups, {
|
125
|
group: '.groups_connected',
|
126
|
handleClass: 'sortable-handler'
|
127
|
});
|
128
|
|
129
|
UIkit.sortable($all_groups, {
|
130
|
group: '.groups_connected',
|
131
|
handleClass: 'sortable-handler'
|
132
|
});
|
133
|
|
134
|
// serialize user group on change
|
135
|
$user_groups.on('change.uk.sortable',function() {
|
136
|
serialize_user_group();
|
137
|
});
|
138
|
|
139
|
// serialize group on init
|
140
|
serialize_user_group();
|
141
|
|
142
|
},
|
143
|
user_todo: function() {
|
144
|
var $user_todo = $('#user_todo');
|
145
|
$user_todo.find('input:checkbox')
|
146
|
.on('ifChecked', function(){
|
147
|
$(this).closest('li').addClass('md-list-item-disabled');
|
148
|
})
|
149
|
.on('ifUnchecked', function(){
|
150
|
$(this).closest('li').removeClass('md-list-item-disabled');
|
151
|
});
|
152
|
}
|
153
|
};
|