Newer
Older
scp.js
osTicket SCP
Copyright (c) osTicket.com
function checkbox_checker(formObj, min, max) {
var max = max || 0;
var min = min || 1;
var checked=$('input:checkbox:checked', formObj).length;
var action= action?action:"process";
if (max>0 && checked > max ){
msg=__("You're limited to only {0} selections.\n") .replace('{0}', max);
msg=msg + __("You have made {0} selections.\n").replace('{0}', checked);
msg=msg + __("Please remove {0} selection(s).").replace('{0}', checked-max);
$.sysAlert( __('Alert'),
__("Please make at least {0} selections. {1} checked so far.")
.replace('{0}', min)
.replace('{1}', checked)
);
$("input[autofocus]:visible:enabled:first").each(function() {
if ($(this).val())
$(this).blur();
});
$('table.list input:checkbox').bind('click, change', function() {
$(this)
.parents("tr:first")
.toggleClass("highlight", this.checked);
});
$('table.list input:checkbox:checked').trigger('change');
$('#selectAll').click(function(e) {
e.preventDefault();
var target = $(this).attr('href').substr(1, $(this).attr('href').length);
$(this).closest('form')
.find('input:enabled:checkbox.'+target)
.prop('checked', true)
.trigger('change');
return false;
});
$('#selectNone').click(function(e) {
e.preventDefault();
var target = $(this).attr('href').substr(1, $(this).attr('href').length);
$(this).closest('form')
.find('input:enabled:checkbox.'+target)
.prop('checked', false)
.trigger('change');
return false;
});
$('#selectToggle').click(function(e) {
e.preventDefault();
var target = $(this).attr('href').substr(1, $(this).attr('href').length);
$(this).closest('form')
.find('input:enabled:checkbox.'+target)
.each(function() {
$(this)
.prop('checked', !$(this).is(':checked'))
.trigger('change');
});
return false;
});
Nathan Febuary
committed
$('#actions:submit, #actions :submit.button:not(.no-confirm), #actions .confirm').bind('click', function(e) {
if ($(this).data('formId'))
formObj = $('#' + $(this).data('formId'));
else
formObj = $(this).closest('form');
if($('.dialog#confirm-action p#'+name+'-confirm').length === 0) {
Michael
committed
alert('Unknown action '+name+' - Get technical help!');
} else if(checkbox_checker(formObj, 1)) {
$('.dialog#confirm-action').undelegate('.confirm');
$('.dialog#confirm-action').delegate('input.confirm', 'click.confirm', function(e) {
e.preventDefault();
$('.dialog#confirm-action').hide();
$('input#action', formObj).val(action);
formObj.submit();
return false;
});
$('.dialog#confirm-action .confirm-action').hide();
$('.dialog#confirm-action p#'+name+'-confirm')
.show()
.parent('div').show().trigger('click');
$('a.confirm-action').click(function(e) {
$dialog = $('.dialog#confirm-action');
if ($($(this).attr('href')+'-confirm', $dialog).length) {
e.preventDefault();
var action = $(this).attr('href').substr(1, $(this).attr('href').length);
$('input#action', $dialog).val(action);
$('.confirm-action', $dialog).hide();
$('p'+$(this).attr('href')+'-confirm', $dialog)
.show()
.parent('div').show().trigger('click');
return false;
}
});
var warnOnLeave = function (el) {
var fObj = el.closest('form');
if(!fObj.data('changed')){
fObj.data('changed', true);
Nathan Febuary
committed
$('input[type=submit], button[type=submit]', fObj).addClass('save pending');
$(window).bind('beforeunload', function(e) {
return __('Are you sure you want to leave? Any changes or info you\'ve entered will be discarded!');
});
$(document).on('pjax:beforeSend.changed', function(e) {
return confirm(__('Are you sure you want to leave? Any changes or info you\'ve entered will be discarded!'));
$("form.save").on('change', ':input[name], :button[name]', function() {
if (!$(this).is('.nowarn')) warnOnLeave($(this));
$("form.save").on('click', ':input[type=reset], :button[type=reset]', function() {
var fObj = $(this).closest('form');
if(fObj.data('changed')){
Nathan Febuary
committed
$('input[type=submit], button[type=submit]', fObj).removeClass('save pending');
$('label', fObj).removeAttr('style');
$('label', fObj).removeClass('strike');
fObj.data('changed', false);
$(window).unbind('beforeunload');
$(window).unbind('beforeunload');
return true;
});
$('select#tpl_options').change(function() {
var $this = $(this), form = $this.closest('form');
if ($this.val() % 1 !== 0) {
$('[name="a"]', form).val('implement');
$this.attr('name', 'code_name');
}
form.submit();
$(document).on('click', ".clearrule",function() {
$(this).closest("tr").find(":input").val('');
return false;
});
//Canned attachments.
$('.canned_attachments, .faq_attachments').delegate('input:checkbox', 'click', function(e) {
if(!$(this).is(':checked') && confirm(__("Are you sure you want to remove this attachment?"))==true) {
elem.parent().addClass('strike');
} else {
elem.attr('checked', 'checked');
elem.parent().removeClass('strike');
}
});
$('form select#cannedResp').select2({width: '300px'});
$('form select#cannedResp').change(function() {
var fObj = $(this).closest('form');
Loading
Loading full blame...