From ac09d4265233efc6ebd30aad422ce1eb52bfdcf5 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Mon, 8 Sep 2014 16:30:44 +0200 Subject: [PATCH] WEBUI JS: Add delete/abort confirm dialogs, improve idnode_form_grid --- src/webui/static/app/dvr.js | 5 ++-- src/webui/static/app/idnode.js | 42 ++++++++++++++++++++++--------- src/webui/static/app/tvheadend.js | 11 ++++++++ 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/webui/static/app/dvr.js b/src/webui/static/app/dvr.js index 6071c7aa..a76b4745 100644 --- a/src/webui/static/app/dvr.js +++ b/src/webui/static/app/dvr.js @@ -102,14 +102,15 @@ tvheadend.dvr_upcoming = function(panel, index) { var uuids = []; for (var i = 0; i < r.length; i++) uuids.push(r[i].id); - tvheadend.Ajax({ + tvheadend.AjaxConfirm({ url: 'api/dvr/entry/cancel', params: { uuid: Ext.encode(uuids) }, success: function(d) { store.reload(); - } + }, + question: 'Do you really want to abort/unschedule the selection?' }); } } diff --git a/src/webui/static/app/idnode.js b/src/webui/static/app/idnode.js index b636d919..d41f4308 100644 --- a/src/webui/static/app/idnode.js +++ b/src/webui/static/app/idnode.js @@ -992,7 +992,7 @@ tvheadend.idnode_grid = function(panel, conf) var uuids = []; for (var i = 0; i < r.length; i++) uuids.push(r[i].id); - tvheadend.Ajax({ + tvheadend.AjaxConfirm({ url: 'api/idnode/delete', params: { uuid: Ext.encode(uuids) @@ -1342,6 +1342,7 @@ tvheadend.idnode_form_grid = function(panel, conf) var abuttons = {}; var plugins = conf.plugins || []; var current = null; + var selectuuid = null; /* Store */ store = new Ext.data.JsonStore({ @@ -1363,9 +1364,18 @@ tvheadend.idnode_form_grid = function(panel, conf) } }); - store.on('load', function(st) { - if (!current) - grid.getSelectionModel().selectFirstRow(); + store.on('load', function(records) { + var s = false; + if (selectuuid) { + records.each(function(r) { + if (r.id === selectuuid) { + select.selectRecords([r]); + s = true; + } + }); + selectuuid = null; + } else if (!current && !select.getSelected()) + select.selectFirstRow(); }); /* Model */ @@ -1407,7 +1417,9 @@ tvheadend.idnode_form_grid = function(panel, conf) node: Ext.encode(node) }, success: function() { - store.reload() + selectuuid = current.uuid; + roweditor_destroy(); + store.reload(); } }); } @@ -1445,15 +1457,14 @@ tvheadend.idnode_form_grid = function(panel, conf) disabled: true, handler: function() { if (current) { - tvheadend.Ajax({ + tvheadend.AjaxConfirm({ url: 'api/idnode/delete', params: { uuid: current.uuid }, - success: function(d) - { + success: function(d) { + roweditor_destroy(); store.reload(); - grid.getSelectionModel().selectFirstRow(); } }); } @@ -1493,9 +1504,17 @@ tvheadend.idnode_form_grid = function(panel, conf) }); } + function roweditor_destroy() { + if (current) + mpanel.remove(current.editor); + current = null; + } + function roweditor(r) { if (!r || !r.id) return; + if (current && current.uuid == r.id) + return; tvheadend.Ajax({ url: 'api/idnode/load', params: { @@ -1504,8 +1523,7 @@ tvheadend.idnode_form_grid = function(panel, conf) }, success: function(d) { d = json_decode(d); - if (current) - mpanel.remove(current.editor); + roweditor_destroy(); var editor = new tvheadend.idnode_editor(d[0], { title: 'Parameters', labelWidth: 300, @@ -1547,7 +1565,7 @@ tvheadend.idnode_form_grid = function(panel, conf) render : { fn : function() { if (!current) - grid.getSelectionModel().selectFirstRow(); + select.selectFirstRow(); } } } diff --git a/src/webui/static/app/tvheadend.js b/src/webui/static/app/tvheadend.js index 4a3c2ea8..87b2b6c0 100644 --- a/src/webui/static/app/tvheadend.js +++ b/src/webui/static/app/tvheadend.js @@ -72,6 +72,17 @@ tvheadend.Ajax = function(conf) { Ext.Ajax.request(conf); }; +tvheadend.AjaxConfirm = function(conf) { + Ext.MessageBox.confirm( + conf.title || 'Message', + conf.question || 'Do you really want to delete the selection?', + function (btn) { + if (btn == 'yes') + tvheadend.Ajax(conf); + } + ); +}; + tvheadend.loading = function(on) { if (on) Ext.getBody().mask('Loading... Please, wait...', 'loading');