Merge branch 'maint/7.0'
[ninja.git] / modules / lsfilter / media / js / LSFilterMultiselect.js
blob728065bc391c065c31fc7dada53241b63f06a09d
1 var lsfilter_multiselect = {
2 on: {
3 'update_ok': function(data) {
4 if (data.source == 'multiselect')
5 return;
6 if (!this.elem_select)
7 return;
8 if (data.metadata.table && data.metadata.table != this.selection_table) {
9 this.selection_table = data.metadata.table;
10 this.selection = {};
12 if (this.commands[this.selection_table]) {
13 this.populate_select(this.elem_select,
14 this.commands[this.selection_table]);
15 } else {
16 this.populate_select(this.elem_select, this.commands['other']);
19 this.elem_objtype.attr('value', this.selection_table);
23 update: function() {
24 // TODO temporary alias, it's only used in extra_objects.js,
25 // which should be modified somehow, by someone who
26 // understands that construct
27 this.on.update_ok.apply(this, arguments);
29 init : function(elem) {
30 var self = this; // To be able to access it from within handlers
31 lsfilter_main.add_listener(self);
33 this.elem_select = elem;
34 this.elem_objtype = $('#listview_multi_action_obj_type');
35 $(document).on('click', 'a.multi-action-send-link', function(e) {
36 e.preventDefault();
37 self.do_send($(this));
38 return false;
39 });
42 elem_select : false,
43 elem_objtype : false,
45 selection : {},
46 selection_table : false,
48 commands : {
49 'hosts' : {
50 '' : _('Select action'),
51 'SCHEDULE_HOST_DOWNTIME' : _('Schedule downtime'),
52 'DEL_HOST_DOWNTIME' : _('Cancel Scheduled downtime'),
53 'ACKNOWLEDGE_HOST_PROBLEM' : _('Acknowledge'),
54 'REMOVE_HOST_ACKNOWLEDGEMENT' : _('Remove problem acknowledgement'),
55 'DISABLE_HOST_NOTIFICATIONS' : _('Disable host notifications'),
56 'ENABLE_HOST_NOTIFICATIONS' : _('Enable host notifications'),
57 'DISABLE_HOST_SVC_NOTIFICATIONS' : _('Disable notifications for all services'),
58 'DISABLE_HOST_CHECK' : _('Disable active checks'),
59 'ENABLE_HOST_CHECK' : _('Enable active checks'),
60 'SCHEDULE_HOST_CHECK' : _('Reschedule host checks'),
61 'ADD_HOST_COMMENT' : _('Add host comment'),
62 'NACOMA_DEL_HOST' : _('Delete hosts')
64 'services' : {
65 '' : _('Select action'),
66 'SCHEDULE_SVC_DOWNTIME' : _('Schedule downtime'),
67 'DEL_SVC_DOWNTIME' : _('Cancel Scheduled downtime'),
68 'ACKNOWLEDGE_SVC_PROBLEM' : _('Acknowledge'),
69 'REMOVE_SVC_ACKNOWLEDGEMENT' : _('Remove problem acknowledgement'),
70 'DISABLE_SVC_NOTIFICATIONS' : _('Disable service notifications'),
71 'ENABLE_SVC_NOTIFICATIONS' : _('Enable service notifications'),
72 'DISABLE_SVC_CHECK' : _('Disable active checks'),
73 'ENABLE_SVC_CHECK' : _('Enable active checks'),
74 'SCHEDULE_SVC_CHECK' : _('Reschedule service checks'),
75 'ADD_SVC_COMMENT' : _('Add service comment'),
76 'NACOMA_DEL_SERVICE' : _('Delete services')
78 'comments' : {
79 '' : _('Select action'),
80 // This is actually a macro of delete svc comments, which can handle
81 // both hosts and service comments
82 'DEL_COMMENT' : _('Delete comments')
84 'downtimes' : {
85 '' : _('Select action'),
86 // This is actually a macro of delete svc comments, which can handle
87 // both hosts and service comments
88 'DEL_DOWNTIME' : _('Delete downtimes')
90 'other' : {
91 '' : _('Table doesn\'t support multi action')
95 populate_select : function(elem, values) {
96 elem.empty();
97 for ( var val in values) {
98 var tag = values[val];
99 elem.append($('<li />').append($('<a href="#" />').text(tag).attr('data-value', val).addClass('multi-action-send-link')));
103 do_send : function(link) {
104 var action = link.data('value');
105 var selcount = $('.listview_multiselect_checkbox:checked').length;
106 if (selcount == 0) {
107 this.notice('No items selected');
108 } else if (!action) {
109 this.notice('No action selected');
110 } else {
111 $('#listview_multi_action_obj_action').attr('value', action);
112 $('#listview_multi_action_form').submit();
115 box_register : function(key, value) {
116 this.selection[key] = value;
118 box_selected : function(key) {
119 if (this.selection[key])
120 return true;
121 return false;
124 notice_timeout : false,
126 notice : function(msg) {
127 var notice_container = $('#multi-action-message');
128 var self = this;
129 if (this.notice_timeout) {
130 clearTimeout(this.notice_timeout);
132 notice_container.text(msg);
133 this.notice_timeout = setTimeout(function() {
134 this.notice_timeout = false;
135 notice_container.empty();
136 }, 3000);