mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-20 11:52:37 +09:00
feature #3748: Add confirm dialogs
This commit is contained in:
1 parent
6c9a06af21
commit
a4e445839d
11 files changed
+296
-38
No files matched your search
@@ -9,11 +9,20 @@ define(function(require) {
|
||||
require('tabs/datastores-tab')
|
||||
];
|
||||
|
||||
var _commonDialogs = [
|
||||
require('utils/dialogs/confirm'),
|
||||
require('utils/dialogs/confirm-with-select')
|
||||
]
|
||||
|
||||
Sunstone.addDialogs(_commonDialogs);
|
||||
|
||||
$.each(_tabs, function(index, tab) {
|
||||
Sunstone.addMainTab(tab);
|
||||
});
|
||||
|
||||
$(document).ready(function() {
|
||||
Sunstone.insertTabs();
|
||||
Sunstone.insertDialog(require('utils/dialogs/confirm'))
|
||||
Sunstone.insertDialog(require('utils/dialogs/confirm-with-select'))
|
||||
});
|
||||
});
|
||||
@@ -2,15 +2,19 @@ define(function(require) {
|
||||
require('jquery');
|
||||
require('foundation.reveal');
|
||||
require('foundation.tab');
|
||||
require('foundation.dropdown');
|
||||
|
||||
var Config = require('sunstone-config');
|
||||
var Locale = require('utils/locale');
|
||||
var Notifier = require('utils/notifier');
|
||||
|
||||
var TOP_INTERVAL = 10000; //ms
|
||||
var CONFIRM_DIALOG_ID = require('utils/dialogs/confirm/dialogId');
|
||||
var CONFIRM_WITH_SELECT_DIALOG_ID = require('utils/dialogs/confirm-with-select/dialogId');
|
||||
|
||||
var SunstoneCfg = {
|
||||
"actions" : {},
|
||||
"dialogs" : {},
|
||||
"tabs" : {},
|
||||
"form_panels" : {}
|
||||
};
|
||||
@@ -21,32 +25,45 @@ define(function(require) {
|
||||
SunstoneCfg["tabs"][_tabId] = tabObj;
|
||||
|
||||
var actions = tabObj.actions;
|
||||
if (actions) {
|
||||
$.each(actions, function(actionName, action){
|
||||
SunstoneCfg["actions"][actionName] = action;
|
||||
})
|
||||
if (actions) {
|
||||
_addActions(actions)
|
||||
}
|
||||
|
||||
var panels = tabObj.panels;
|
||||
if (panels) {
|
||||
var indexedPanels = {}
|
||||
$.each(panels, function(index, panel){
|
||||
indexedPanels[panel.panelId] = panel
|
||||
})
|
||||
SunstoneCfg["tabs"][_tabId]['panels'] = indexedPanels;
|
||||
_addPanels(_tabId, panels)
|
||||
}
|
||||
|
||||
var dialogs = tabObj.dialogs;
|
||||
if (dialogs) {
|
||||
var indexedDialogs = {}
|
||||
$.each(dialogs, function(index, dialog){
|
||||
indexedDialogs[dialog.dialogId] = dialog
|
||||
})
|
||||
SunstoneCfg["tabs"][_tabId]['dialogs'] = indexedDialogs;
|
||||
_addDialogs(dialogs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _addActions = function(actions) {
|
||||
$.each(actions, function(actionName, action) {
|
||||
SunstoneCfg["actions"][actionName] = action;
|
||||
})
|
||||
return false;
|
||||
}
|
||||
|
||||
var _addDialogs = function(dialogs) {
|
||||
$.each(dialogs, function(index, dialog) {
|
||||
SunstoneCfg['dialogs'][dialog.dialogId] = dialog
|
||||
})
|
||||
return false;
|
||||
}
|
||||
|
||||
var _addPanels = function(tabId, panels) {
|
||||
var indexedPanels = {}
|
||||
$.each(panels, function(index, panel) {
|
||||
indexedPanels[panel.panelId] = panel
|
||||
})
|
||||
SunstoneCfg["tabs"][tabId]['panels'] = indexedPanels;
|
||||
return false;
|
||||
}
|
||||
|
||||
//Inserts all main tabs in the DOM
|
||||
var _insertTabs = function() {
|
||||
for (tabName in SunstoneCfg["tabs"]) {
|
||||
@@ -327,7 +344,7 @@ define(function(require) {
|
||||
//Listen for .action_buttons
|
||||
//An action buttons runs a predefined action. If it has type
|
||||
//"multiple" it runs that action on the elements of a datatable.
|
||||
$('.action_button').on("click", function() {
|
||||
$(document).on("click", '.action_button', function() {
|
||||
var error = 0;
|
||||
var value = $(this).val()
|
||||
if ($.isEmptyObject(value)) {
|
||||
@@ -356,14 +373,34 @@ define(function(require) {
|
||||
if (!error && !$(this).hasClass("refresh")) {
|
||||
//proceed to close confirm dialog in
|
||||
//case it was open
|
||||
$('div#confirm_dialog').foundation('reveal', 'close');
|
||||
_hideDialog(CONFIRM_DIALOG_ID);
|
||||
};
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
//Listen .confirm_buttons. These buttons show a confirmation dialog
|
||||
//before running the action.
|
||||
$(document).on("click", '.confirm_button', function() {
|
||||
$('#' + CONFIRM_DIALOG_ID).data('buttonAction', $(this).attr('href'));
|
||||
$('#' + CONFIRM_DIALOG_ID).data('buttonTab', $(this).parents('.tab').attr('id'));
|
||||
_showDialog(CONFIRM_DIALOG_ID);
|
||||
return false;
|
||||
});
|
||||
|
||||
//Listen .confirm_buttons. These buttons show a confirmation dialog
|
||||
//with a select box before running the action.
|
||||
$(document).on("click", '.confirm_with_select_button', function() {
|
||||
$('#' + CONFIRM_WITH_SELECT_DIALOG_ID).data('buttonAction', $(this).attr('href'));
|
||||
$('#' + CONFIRM_WITH_SELECT_DIALOG_ID).data('buttonTab', $(this).parents('.tab').attr('id'));
|
||||
_showDialog(CONFIRM_WITH_SELECT_DIALOG_ID);
|
||||
return false;
|
||||
});
|
||||
|
||||
$(document).foundation('reflow', 'dropdown');
|
||||
|
||||
// Button to return to the list view from the detailed view
|
||||
$("a[href='back']").on("click", function(e) {
|
||||
$(document).on("click", "a[href='back']", function(e) {
|
||||
$(".navigation-active-li a", $("#navigation")).click();
|
||||
e.preventDefault();
|
||||
});
|
||||
@@ -528,45 +565,45 @@ define(function(require) {
|
||||
$(document).foundation('reflow', 'tab');
|
||||
}
|
||||
|
||||
var _insertDialog = function(tabName, dialog) {
|
||||
var _insertDialog = function(dialog) {
|
||||
var dialogElement = $(dialog.html()).appendTo('div#dialogs');
|
||||
dialog.setup(dialogElement);
|
||||
dialogElement.foundation('reveal', 'reflow');
|
||||
|
||||
dialogElement.on('opened.fndtn.reveal', function () {
|
||||
dialog.onShow(dialogElement);
|
||||
dialog.onShow(dialog.dialogId);
|
||||
});
|
||||
|
||||
dialogElement.on('click', '.resetDialog', function(){
|
||||
_resetDialog(tabName, dialog.dialogId);
|
||||
_showDialog(tabName, dialog.dialogId);
|
||||
dialogElement.on('click', '.resetDialog', function() {
|
||||
_resetDialog(dialog.dialogId);
|
||||
_showDialog(dialog.dialogId);
|
||||
})
|
||||
|
||||
return dialogElement;
|
||||
}
|
||||
|
||||
var _showDialog = function(tabName, dialogId) {
|
||||
var dialog = SunstoneCfg['tabs'][tabName]['dialogs'][dialogId];
|
||||
var _showDialog = function(dialogId) {
|
||||
var dialog = SunstoneCfg['dialogs'][dialogId];
|
||||
var dialogElement = $('#' + dialog.dialogId);
|
||||
if (dialogElement.length == 0) {
|
||||
dialogElement = _insertDialog(tabName, dialog);
|
||||
dialogElement = _insertDialog(dialog);
|
||||
}
|
||||
|
||||
dialogElement.foundation('reveal', 'open');
|
||||
return false;
|
||||
}
|
||||
|
||||
var _hideDialog = function(tabName, dialogId) {
|
||||
var dialog = SunstoneCfg['tabs'][tabName]['dialogs'][dialogId];
|
||||
var _hideDialog = function(dialogId) {
|
||||
var dialog = SunstoneCfg['dialogs'][dialogId];
|
||||
var dialogElement = $('#' + dialog.dialogId);
|
||||
dialogElement.foundation('reveal', 'close')
|
||||
}
|
||||
|
||||
var _resetDialog = function(tabName, dialogId) {
|
||||
var dialog = SunstoneCfg['tabs'][tabName]['dialogs'][dialogId];
|
||||
var _resetDialog = function(dialogId) {
|
||||
var dialog = SunstoneCfg['dialogs'][dialogId];
|
||||
var dialogElement = $('#' + dialog.dialogId);
|
||||
dialogElement.remove();
|
||||
dialogElement = _insertDialog(tabName, dialog);
|
||||
dialogElement = _insertDialog(dialog);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -764,11 +801,17 @@ define(function(require) {
|
||||
return $(".resource-id", context).text();
|
||||
}
|
||||
|
||||
var _getAction = function(actionId) {
|
||||
return SunstoneCfg["actions"][actionId];
|
||||
}
|
||||
|
||||
var Sunstone = {
|
||||
"addMainTab": _addMainTab,
|
||||
"addDialogs": _addDialogs,
|
||||
|
||||
"insertTabs": _insertTabs,
|
||||
"insertPanels": _insertPanels,
|
||||
"insertDialog": _insertDialog,
|
||||
|
||||
'showTab': _showTab,
|
||||
"showElement" : _showElement,
|
||||
@@ -780,7 +823,9 @@ define(function(require) {
|
||||
"rightListVisible": _rightListVisible,
|
||||
"rightInfoResourceId": _rightInfoResourceId,
|
||||
|
||||
"runAction" : _runAction
|
||||
"runAction" : _runAction,
|
||||
"getAction": _getAction,
|
||||
"getButton": _getButton
|
||||
}
|
||||
|
||||
return Sunstone;
|
||||
|
||||
@@ -15,8 +15,8 @@ define(function(require) {
|
||||
type: "create",
|
||||
call : OpenNebulaDatastore.create,
|
||||
callback : function(request, response) {
|
||||
Sunstone.hideDialog(TAB_ID, CREATE_DIALOG_ID);
|
||||
Sunstone.resetDialog(TAB_ID, CREATE_DIALOG_ID);
|
||||
Sunstone.hideDialog(CREATE_DIALOG_ID);
|
||||
Sunstone.resetDialog(CREATE_DIALOG_ID);
|
||||
DatastoresDataTable.addElement(request, response);
|
||||
Notifier.notifyCustom(Locale.tr("Datastore created"), " ID: " + response.DATASTORE.ID, false);
|
||||
},
|
||||
@@ -26,7 +26,7 @@ define(function(require) {
|
||||
"Datastore.create_dialog" : {
|
||||
type: "custom",
|
||||
call: function() {
|
||||
Sunstone.showDialog(TAB_ID, CREATE_DIALOG_ID);
|
||||
Sunstone.showDialog(CREATE_DIALOG_ID);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ define(function(require) {
|
||||
type: "create",
|
||||
call: OpenNebulaZone.create,
|
||||
callback: function(request, response) {
|
||||
Sunstone.hideDialog(TAB_ID, CREATE_DIALOG_ID);
|
||||
Sunstone.resetDialog(TAB_ID, CREATE_DIALOG_ID);
|
||||
Sunstone.hideDialog(CREATE_DIALOG_ID);
|
||||
Sunstone.resetDialog(CREATE_DIALOG_ID);
|
||||
ZonesDataTable.addElement(request, response);
|
||||
},
|
||||
error: Notifier.onError,
|
||||
@@ -24,7 +24,7 @@ define(function(require) {
|
||||
"Zone.create_dialog" : {
|
||||
type: "custom",
|
||||
call: function() {
|
||||
Sunstone.showDialog(TAB_ID, CREATE_DIALOG_ID);
|
||||
Sunstone.showDialog(CREATE_DIALOG_ID);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
define(function(require) {
|
||||
var TemplateHTML = require('hbs!./confirm-with-select/html');
|
||||
var Sunstone = require('sunstone');
|
||||
var Locale = require('utils/locale');
|
||||
var Notifier = require('utils/notifier');
|
||||
var DIALOG_ID = require('./confirm-with-select/dialogId');
|
||||
|
||||
var ResourceSelect = require('utils/resource-select');
|
||||
|
||||
var _html = function() {
|
||||
return TemplateHTML({dialogId: DIALOG_ID});
|
||||
}
|
||||
|
||||
var _setup = function(dialog) {
|
||||
//when we proceed with a "confirm with select" we need to
|
||||
//find out if we are running an action with a parametre on a datatable
|
||||
//items or if its just an action
|
||||
$('#confirm_with_select_proceed', dialog).click(function() {
|
||||
var action = $(this).val();
|
||||
var action = Sunstone.getActions[action];
|
||||
var param = $('.resource_list_select', dialog).val();
|
||||
|
||||
if (!param.length) {
|
||||
notifyError("You must select a value");
|
||||
return false;
|
||||
};
|
||||
|
||||
if (!action) {
|
||||
notifyError("Action " + action + " not defined.");
|
||||
return false;
|
||||
};
|
||||
|
||||
var error;
|
||||
switch (action.type){
|
||||
case "multiple":
|
||||
error = Sunstone.runAction(action, action.elements(), param);
|
||||
break;
|
||||
default:
|
||||
error = Sunstone.runAction(action, param);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!error) {
|
||||
dialog.foundation('reveal', 'close');
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
var _onShow = function(dialog) {
|
||||
var actionId = dialog.data('buttonAction');
|
||||
var tabId = dialog.data('buttonTab');
|
||||
var button = Sunstone.getButton(tabId, action);
|
||||
|
||||
var tip = Locale.tr("You have to confirm this action");
|
||||
if (button.tip == undefined) {
|
||||
tip = button.tip
|
||||
}
|
||||
|
||||
if (button.custom_select) {
|
||||
$('div#confirm_select', dialog).html(button.custom_select);
|
||||
} else {
|
||||
ResourceSelect.insert('#confirm_select', dialog, button.select, null, true);
|
||||
}
|
||||
|
||||
$('#confirm_with_select_tip', dialog).text(tip);
|
||||
$('#confirm_with_select_proceed', dialog).val(action);
|
||||
|
||||
var action = Sunstone.getAction(action);
|
||||
var elements = action.elements();
|
||||
if (elements) {
|
||||
var str = action.split('.');
|
||||
$(".confirm_action", dialog).html(str[1] + ' ' + str[0] + ': ' + elements.join(', '))
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return {
|
||||
'dialogId': DIALOG_ID,
|
||||
'html': _html,
|
||||
'setup': _setup,
|
||||
'onShow': _onShow
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
define(function(require){
|
||||
return 'confirmWithSelectDialog';
|
||||
})
|
||||
@@ -0,0 +1,25 @@
|
||||
<div id="{{dialogId}}" class="reveal-modal" data-reveal>
|
||||
<div class="row">
|
||||
<h3 class="subheader">
|
||||
{{tr "Confirm"}}
|
||||
<br>
|
||||
 
|
||||
<small class="confirm_action"></small>
|
||||
</h3>
|
||||
</div>
|
||||
<form action="">
|
||||
<div class="row">
|
||||
<div id="confirm_with_select_tip">{{tr "You need to select something."}}</div>
|
||||
</div>
|
||||
<br />
|
||||
<div class="row">
|
||||
<div class="large-12 columns" id="confirm_select"></div>
|
||||
</div>
|
||||
<br />
|
||||
<br />
|
||||
<div class="form_buttons">
|
||||
<button id="confirm_with_select_proceed" class="action_button radius button right" value="">{{tr "OK"}}</button>
|
||||
</div>
|
||||
<a class="close-reveal-modal">×</a>
|
||||
</form>
|
||||
</div>
|
||||
@@ -0,0 +1,46 @@
|
||||
define(function(require) {
|
||||
var TemplateHTML = require('hbs!./confirm/html');
|
||||
var Sunstone = require('sunstone');
|
||||
var Locale = require('utils/locale');
|
||||
var DIALOG_ID = require('./confirm/dialogId');
|
||||
|
||||
var _html = function() {
|
||||
return TemplateHTML({dialogId: DIALOG_ID});
|
||||
}
|
||||
|
||||
var _setup = function(dialog) {
|
||||
// Submit action is configured in sunstone.js since it's an action_button
|
||||
return false;
|
||||
}
|
||||
|
||||
var _onShow = function(dialogId) {
|
||||
var dialog = $('#' + dialogId);
|
||||
var actionId = dialog.data('buttonAction');
|
||||
var tabId = dialog.data('buttonTab');
|
||||
var button = Sunstone.getButton(tabId, actionId);
|
||||
|
||||
var tip = Locale.tr("You have to confirm this action");
|
||||
if (button.tip) {
|
||||
tip = button.tip
|
||||
}
|
||||
|
||||
$('#confirm_proceed', dialog).val(actionId);
|
||||
$('#confirm_tip', dialog).text(tip);
|
||||
|
||||
var action = Sunstone.getAction(actionId);
|
||||
var elements = action.elements();
|
||||
if (elements) {
|
||||
var str = actionId.split('.');
|
||||
$(".confirm_action", dialog).html(str[1] + ' ' + str[0] + ': ' + elements.join(', '))
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return {
|
||||
'dialogId': DIALOG_ID,
|
||||
'html': _html,
|
||||
'setup': _setup,
|
||||
'onShow': _onShow
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
define(function(require){
|
||||
return 'confirmDialog';
|
||||
})
|
||||
@@ -0,0 +1,20 @@
|
||||
<div id="{{dialogId}}" class="reveal-modal" data-reveal>
|
||||
<div class="row">
|
||||
<h3 class="subheader">
|
||||
{{tr "Confirm"}}
|
||||
<br>
|
||||
 
|
||||
<small class="confirm_action"></small>
|
||||
</h3>
|
||||
</div>
|
||||
<form action="">
|
||||
<div id="confirm_tip">{{tr "You have to confirm this action."}}</div>
|
||||
<br />
|
||||
<div id="question">{{tr "Do you want to proceed?"}}</div>
|
||||
<br />
|
||||
<div class="form_buttons">
|
||||
<button id="confirm_proceed" class="action_button radius button right" value="">{{tr "OK"}}</button>
|
||||
</div>
|
||||
<a class="close-reveal-modal">×</a>
|
||||
</form>
|
||||
</div>
|
||||
@@ -269,6 +269,24 @@ define(function(require) {
|
||||
$('tr input.check_item:visible', dataTable).replaceWith(SPINNER);
|
||||
}
|
||||
|
||||
//returns an array of ids of selected elements in a dataTable
|
||||
var _getSelectedNodes = function(dataTable, forceDataTable){
|
||||
var selected_nodes = [];
|
||||
if (dataTable){
|
||||
var tab = dataTable.parents(".tab")
|
||||
if (Sunstone.rightInfoVisible(tab) && !forceDataTable) {
|
||||
selected_nodes.push(Sunstone.rightInfoResourceId(tab));
|
||||
} else {
|
||||
//Which rows of the datatable are checked?
|
||||
var nodes = $('tbody input.check_item:checked',dataTable);
|
||||
$.each(nodes,function(){
|
||||
selected_nodes.push($(this).val());
|
||||
});
|
||||
}
|
||||
};
|
||||
return selected_nodes;
|
||||
}
|
||||
|
||||
return {
|
||||
'infoListener': _infoListener,
|
||||
'addElement': _addElement,
|
||||
@@ -280,6 +298,7 @@ define(function(require) {
|
||||
'updateView': _updateView,
|
||||
'updateSingleElement': _updateSingleElement,
|
||||
'getElementData': _getElementData,
|
||||
'waitingNodes': _waitingNodes
|
||||
'waitingNodes': _waitingNodes,
|
||||
'getSelectedNodes': _getSelectedNodes
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user