1 |
efrain |
1 |
define(['core/str', 'core/modal_factory', 'core/modal_events',
|
|
|
2 |
'core/fragment', 'core/templates', 'core/notification', 'core_message/toggle_contact_button'],
|
|
|
3 |
function(Str, Modal, ModalEvents, Fragment, Templates, Notification, Contact) {
|
|
|
4 |
|
|
|
5 |
return {
|
|
|
6 |
init: function(contextID) {
|
|
|
7 |
var groupModal = document.getElementsByClassName('contact-widget-viewgroup');
|
|
|
8 |
var contactUser;
|
|
|
9 |
Array.from(groupModal).forEach(function(element) {
|
|
|
10 |
element.addEventListener('click', function(e) {
|
|
|
11 |
e.preventDefault();
|
|
|
12 |
var target = e.target.closest('a');
|
|
|
13 |
contactUser = target.getAttribute('data-userid');
|
|
|
14 |
Modal.create({
|
|
|
15 |
title: Str.get_string('groups', 'core')
|
|
|
16 |
}).then(function(modal) {
|
|
|
17 |
modal.show();
|
|
|
18 |
|
|
|
19 |
var args = JSON.stringify({contactuser: contactUser});
|
|
|
20 |
var params = {widget: 'contacts', method: 'load_groups', args: args};
|
|
|
21 |
Fragment.loadFragment('block_dash', 'loadwidget', contextID, params).then((html, js) => {
|
|
|
22 |
modal.setBody(html);
|
|
|
23 |
Templates.runTemplateJS(js);
|
|
|
24 |
return html;
|
|
|
25 |
}).catch(Notification.exception);
|
|
|
26 |
|
|
|
27 |
modal.getRoot().on(ModalEvents.hidden, function() {
|
|
|
28 |
modal.destroy();
|
|
|
29 |
});
|
|
|
30 |
return modal;
|
|
|
31 |
}).catch(Notification.exception);
|
|
|
32 |
});
|
|
|
33 |
});
|
|
|
34 |
|
|
|
35 |
var contactModal = document.getElementsByClassName('toggle-contact-button');
|
|
|
36 |
Array.from(contactModal).forEach(function(element) {
|
|
|
37 |
element.addEventListener('click', function(e) {
|
|
|
38 |
e.preventDefault();
|
|
|
39 |
if (e.target.dataset.userid != undefined) {
|
|
|
40 |
Contact.enhance(e.target);
|
|
|
41 |
}
|
|
|
42 |
});
|
|
|
43 |
});
|
|
|
44 |
}
|
|
|
45 |
};
|
|
|
46 |
});
|