2014-04-26 20:42:05 -07:00
|
|
|
|
(function () {
|
|
|
|
|
|
2014-07-02 11:34:08 -07:00
|
|
|
|
var notificationsConfigurationKey = "notifications";
|
|
|
|
|
|
2014-04-27 10:54:43 -07:00
|
|
|
|
function fillItems(elem, items, cssClass, idPrefix, currentList, isEnabledList) {
|
2014-04-26 20:42:05 -07:00
|
|
|
|
|
|
|
|
|
var html = '<div data-role="controlgroup">';
|
|
|
|
|
|
|
|
|
|
html += items.map(function (u) {
|
|
|
|
|
|
|
|
|
|
var id = idPrefix + u.Id;
|
|
|
|
|
|
2014-04-27 10:54:43 -07:00
|
|
|
|
var isChecked = isEnabledList ? currentList.indexOf(u.Id) != -1 : currentList.indexOf(u.Id) == -1;
|
|
|
|
|
|
|
|
|
|
var checkedHtml = isChecked ? ' checked="checked"' : '';
|
2014-04-26 20:42:05 -07:00
|
|
|
|
|
|
|
|
|
return '<label for="' + id + '">' + u.Name + '</label><input class="' + cssClass + '" type="checkbox" data-itemid="' + u.Id + '" data-mini="true" id="' + id + '"' + checkedHtml + ' />';
|
|
|
|
|
|
|
|
|
|
}).join('');
|
|
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
elem.html(html).trigger('create');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function reload(page) {
|
|
|
|
|
|
|
|
|
|
var type = getParameterByName('type');
|
|
|
|
|
|
|
|
|
|
var promise1 = ApiClient.getUsers();
|
2014-07-02 11:34:08 -07:00
|
|
|
|
var promise2 = ApiClient.getNamedConfiguration(notificationsConfigurationKey);
|
2014-07-01 22:16:59 -07:00
|
|
|
|
var promise3 = ApiClient.getJSON(ApiClient.getUrl("Notifications/Types"));
|
|
|
|
|
var promise4 = ApiClient.getJSON(ApiClient.getUrl("Notifications/Services"));
|
2014-04-26 20:42:05 -07:00
|
|
|
|
|
|
|
|
|
$.when(promise1, promise2, promise3, promise4).done(function (response1, response2, response3, response4) {
|
|
|
|
|
|
|
|
|
|
var users = response1[0];
|
2014-07-02 11:34:08 -07:00
|
|
|
|
var notificationOptions = response2[0];
|
2014-04-26 20:42:05 -07:00
|
|
|
|
var types = response3[0];
|
|
|
|
|
var services = response4[0];
|
|
|
|
|
|
2014-07-02 11:34:08 -07:00
|
|
|
|
var notificationConfig = notificationOptions.Options.filter(function (n) {
|
2014-04-26 20:42:05 -07:00
|
|
|
|
|
|
|
|
|
return n.Type == type;
|
|
|
|
|
|
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
|
|
var typeInfo = types.filter(function (n) {
|
|
|
|
|
|
|
|
|
|
return n.Type == type;
|
|
|
|
|
|
|
|
|
|
})[0] || {};
|
|
|
|
|
|
|
|
|
|
if (typeInfo.IsBasedOnUserEvent) {
|
|
|
|
|
$('.monitorUsers', page).show();
|
|
|
|
|
} else {
|
|
|
|
|
$('.monitorUsers', page).hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeInfo.Variables.length) {
|
|
|
|
|
$('.tokenHelp', page).show();
|
|
|
|
|
|
|
|
|
|
$('.tokenList', page).html(typeInfo.Variables.map(function (v) {
|
|
|
|
|
|
|
|
|
|
return '{' + v + '}';
|
|
|
|
|
|
|
|
|
|
}).join(', '));
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
$('.tokenHelp', page).hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('.notificationType', page).html(typeInfo.Name || 'Unknown Notification');
|
|
|
|
|
|
|
|
|
|
if (!notificationConfig) {
|
|
|
|
|
|
|
|
|
|
notificationConfig = {
|
|
|
|
|
DisabledMonitorUsers: [],
|
2014-04-27 10:54:43 -07:00
|
|
|
|
SendToUsers: [],
|
2014-04-27 11:09:16 -07:00
|
|
|
|
DisabledServices: [],
|
|
|
|
|
SendToUserMode: 'Admins'
|
2014-04-26 20:42:05 -07:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fillItems($('.monitorUsersList', page), users, 'chkMonitor', 'chkMonitor', notificationConfig.DisabledMonitorUsers);
|
2014-04-27 10:54:43 -07:00
|
|
|
|
fillItems($('.sendToUsersList', page), users, 'chkSendTo', 'chkSendTo', notificationConfig.SendToUsers, true);
|
2014-04-26 20:42:05 -07:00
|
|
|
|
fillItems($('.servicesList', page), services, 'chkService', 'chkService', notificationConfig.DisabledServices);
|
|
|
|
|
|
|
|
|
|
$('#chkEnabled', page).checked(notificationConfig.Enabled || false).checkboxradio('refresh');
|
|
|
|
|
|
|
|
|
|
$('#txtTitle', page).val(notificationConfig.Title || typeInfo.DefaultTitle);
|
|
|
|
|
|
2014-04-27 10:54:43 -07:00
|
|
|
|
$('#selectUsers', page).val(notificationConfig.SendToUserMode).selectmenu('refresh').trigger('change');
|
|
|
|
|
|
2014-04-26 20:42:05 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function save(page) {
|
|
|
|
|
|
|
|
|
|
var type = getParameterByName('type');
|
|
|
|
|
|
2014-07-02 11:34:08 -07:00
|
|
|
|
var promise1 = ApiClient.getNamedConfiguration(notificationsConfigurationKey);
|
2014-07-01 22:16:59 -07:00
|
|
|
|
var promise2 = ApiClient.getJSON(ApiClient.getUrl("Notifications/Types"));
|
2014-04-26 20:42:05 -07:00
|
|
|
|
|
|
|
|
|
$.when(promise1, promise2).done(function (response1, response2) {
|
|
|
|
|
|
2014-07-02 11:34:08 -07:00
|
|
|
|
var notificationOptions = response1[0];
|
2014-04-26 20:42:05 -07:00
|
|
|
|
var types = response2[0];
|
|
|
|
|
|
2014-07-02 11:34:08 -07:00
|
|
|
|
var notificationConfig = notificationOptions.Options.filter(function (n) {
|
2014-04-26 20:42:05 -07:00
|
|
|
|
|
|
|
|
|
return n.Type == type;
|
|
|
|
|
|
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
|
|
if (!notificationConfig) {
|
|
|
|
|
notificationConfig = {
|
|
|
|
|
Type: type
|
|
|
|
|
};
|
|
|
|
|
notificationOptions.Options.push(notificationConfig);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var typeInfo = types.filter(function (n) {
|
|
|
|
|
|
|
|
|
|
return n.Type == type;
|
|
|
|
|
|
|
|
|
|
})[0] || {};
|
|
|
|
|
|
|
|
|
|
notificationConfig.Enabled = $('#chkEnabled', page).checked();
|
|
|
|
|
notificationConfig.Title = $('#txtTitle', page).val();
|
2014-04-27 10:54:43 -07:00
|
|
|
|
notificationConfig.SendToUserMode = $('#selectUsers', page).val();
|
2014-04-26 20:42:05 -07:00
|
|
|
|
|
|
|
|
|
// Don't persist if it's just the default
|
|
|
|
|
if (notificationConfig.Title == typeInfo.DefaultTitle) {
|
|
|
|
|
notificationConfig.Title = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
notificationConfig.DisabledMonitorUsers = $('.chkMonitor:not(:checked)', page).get().map(function (c) {
|
|
|
|
|
return c.getAttribute('data-itemid');
|
|
|
|
|
});
|
|
|
|
|
|
2014-04-27 10:54:43 -07:00
|
|
|
|
notificationConfig.SendToUsers = $('.chkSendTo:checked', page).get().map(function (c) {
|
2014-04-26 20:42:05 -07:00
|
|
|
|
return c.getAttribute('data-itemid');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
notificationConfig.DisabledServices = $('.chkService:not(:checked)', page).get().map(function (c) {
|
|
|
|
|
return c.getAttribute('data-itemid');
|
|
|
|
|
});
|
|
|
|
|
|
2014-07-02 11:34:08 -07:00
|
|
|
|
ApiClient.updateNamedConfiguration(notificationsConfigurationKey, notificationOptions).done(function (r) {
|
2014-04-26 20:42:05 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.navigate('notificationsettings.html');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-27 10:54:43 -07:00
|
|
|
|
$(document).on('pageinit', "#notificationSettingPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
$('#selectUsers', page).on('change', function () {
|
|
|
|
|
|
|
|
|
|
if (this.value == 'Custom') {
|
|
|
|
|
$('.selectCustomUsers', page).show();
|
|
|
|
|
} else {
|
|
|
|
|
$('.selectCustomUsers', page).hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}).on('pageshow', "#notificationSettingPage", function () {
|
2014-04-26 20:42:05 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
reload(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.NotificationSettingPage = {
|
|
|
|
|
|
|
|
|
|
onSubmit: function () {
|
|
|
|
|
|
|
|
|
|
var page = $(this).parents('.page');
|
|
|
|
|
save(page);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
})(jQuery, window);
|