Modal confirm dialogs for dangerous actions.

Squashed commit of the following:

commit 80513dd206
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Aug 31 08:26:39 2013 +0100

    use blockquote to make dialog more readable

commit bab8e4d00c
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Aug 31 08:16:49 2013 +0100

    add confirm dialog to user delete

commit 46c7d54973
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Aug 31 07:46:52 2013 +0100

    add confirm dialog to pseudo device delete

commit 00f26b92a9
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Aug 31 07:41:41 2013 +0100

    restore aria header ref

commit 1c04d32cd2
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Aug 31 07:38:39 2013 +0100

    add confirm dialog to topo link delete

commit 914a03a19c
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Aug 31 07:12:59 2013 +0100

    tidy dialogs

commit e4c3978ba8
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Aug 30 23:37:55 2013 +0100

    remove attr("data-

commit 626c8c3fdd
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Aug 30 23:36:47 2013 +0100

    log message for port controls

commit b614669c0c
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Aug 30 21:23:22 2013 +0100

    swap attr for data

commit 79ce5ec47d
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Aug 30 21:09:41 2013 +0100

    improve delete modal and add log message

commit 601671b383
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Aug 27 22:46:43 2013 +0100

    modal dialog which calls ajax
This commit is contained in:
Oliver Gorwits
2013-08-31 08:29:41 +01:00
parent aa2a5e3b20
commit c75167fe27
9 changed files with 213 additions and 52 deletions

View File

@@ -1,51 +1,64 @@
// to tell whether bootstrap's modal had Submit button pressed :(
var nd_save_ok = false;
// user clicked or asked for port changes to be submitted via ajax
function port_control (e) {
var td = $(e).closest('td');
var td = $(e).closest('td'),
logmessage = $('#nd_portlog_log').val();
$('#nd_portlog_log').val('');
if (nd_save_ok == false) {
td.find('.nd_editable-cell-content').text(td.data('default'));
td.blur();
return;
}
nd_save_ok = false;
$.ajax({
type: 'POST'
,url: uri_base + '/ajax/portcontrol'
,data: {
device: td.attr('data-for-device')
,port: td.attr('data-for-port')
,field: td.attr('data-field')
,action: td.attr('data-action')
device: td.data('for-device')
,port: td.data('for-port')
,field: td.data('field')
,action: td.data('action')
,value: td.text().trim()
,log: logmessage,
}
,success: function() {
toastr.info('Submitted change request');
// update all the screen furniture for port up/down control
if ($.trim(td.attr('data-action')) == 'down') {
if ($.trim(td.data('action')) == 'down') {
td.prev('td').html('<span class="label">S</span>');
$(e).toggleClass('icon-hand-down');
$(e).toggleClass('icon-hand-up');
$(e).data('tooltip').options.title = 'Click to Enable';
td.attr('data-action', 'up');
td.data('action', 'up');
}
else if ($.trim(td.attr('data-action')) == 'up') {
else if ($.trim(td.data('action')) == 'up') {
td.prev('td').html('<span class="label"><i class="icon-refresh"></i></span>');
$(e).toggleClass('icon-hand-up');
$(e).toggleClass('icon-hand-down');
$(e).data('tooltip').options.title = 'Click to Disable';
td.attr('data-action', 'down');
td.data('action', 'down');
}
else if ($.trim(td.attr('data-action')) == 'false') {
else if ($.trim(td.data('action')) == 'false') {
$(e).next('span').text('');
$(e).toggleClass('nd_power-on');
$(e).data('tooltip').options.title = 'Click to Enable';
td.attr('data-action', 'true');
td.data('action', 'true');
}
else if ($.trim(td.attr('data-action')) == 'true') {
else if ($.trim(td.data('action')) == 'true') {
$(e).toggleClass('nd_power-on');
$(e).data('tooltip').options.title = 'Click to Disable';
td.attr('data-action', 'false');
td.data('action', 'false');
}
}
,error: function() {
toastr.error('Failed to submit change request');
document.execCommand('undo');
$(e).blur();
td.find('.nd_editable-cell-content').text(td.data('default'));
td.blur();
}
});
}
@@ -95,34 +108,49 @@ $(document).ready(function() {
$(this).siblings('td').find('.nd_device-details-edit').hide(); // details
});
// activity for port up/down control
$('#ports_pane').on('click', '.icon-hand-up', function() {
port_control(this); // save
});
$('#ports_pane').on('click', '.icon-hand-down', function() {
port_control(this); // save
// to tell whether bootstrap's modal had Submit button pressed :(
$('#ports_pane').on('click', '#nd_portlog_submit', function() {
nd_save_ok = true;
});
// activity for power enable/disable control
$('#ports_pane').on('click', '.nd_power-icon', function() {
port_control(this); // save
// activity for port up/down control, power enable/disable control
$('#ports_pane').on('click', '.icon-hand-up,.icon-hand-down,.nd_power-icon', function() {
var clicked = this; // create a closure
$('#nd_portlog').one('hidden', function() {
port_control(clicked); // save
});
$('#nd_portlog').modal('show');
});
// has cell content changed?
var dirty = false;
// activity for contenteditable control
$('.tab-content').on('keydown', '[contenteditable=true]', function(event) {
var esc = event.which == 27,
var cell = this,
td = $(cell).closest('td'),
esc = event.which == 27,
nl = event.which == 13;
if (esc) {
$(this).blur();
$(cell).blur();
}
else if (nl) {
event.preventDefault();
port_control(this); // save
if (td.data('field') == 'c_vlan') {
$('#nd_portlog').one('hidden', function() {
port_control(cell); // save
});
$('#nd_portlog').modal('show');
}
else {
// no confirm for port descr change
port_control(cell); // save
}
dirty = false;
$(this).blur();
$(cell).blur();
}
else {
dirty = true;