(function($, cloudStack) { /** * Add 'pending' notification */ var addNotification = function(notification, success, successArgs, error, errorArgs) { if (!notification) { success(successArgs); return false; }; var $notifications = $('div.notifications'); if (!notification.poll) { $notifications.notifications('add', { section: notification.section, desc: notification.desc, interval: 0, poll: function(args) { success(successArgs); args.complete(); } }); } else { $notifications.notifications('add', { section: notification.section, desc: notification.desc, interval: 5000, _custom: notification._custom, poll: function(args) { var complete = args.complete; notification.poll({ _custom: args._custom, complete: function(args) { success($.extend(successArgs, args)); complete(args); }, error: function(args) { if (args.message) { if (args.message) { cloudStack.dialog.notice({ message: args.message }); } error($.extend(errorArgs, args)); complete(args); } } }); } }); } return true; }; /** * Available UI actions to perform for buttons */ var uiActions = { /** * Default behavior for actions -- just show a confirmation popup and add notification */ standard: function($detailView, args, additional) { var action = args.actions[args.actionName]; var notification = action.notification; var messages = action.messages; var messageArgs = { name: $detailView.find('tr.name td.value').html() }; var id = args.id; var context = $detailView.data('view-args').context; var externalLinkAction = action.action.externalLink; if (externalLinkAction) { // Show popup immediately, do not proceed through normal action process window.open( // URL externalLinkAction.url({ context: context }), // Title externalLinkAction.title({ context: context }), // Window options 'menubar=0,resizable=0,' + 'width=' + externalLinkAction.width + ',' + 'height=' + externalLinkAction.height ); return; } notification.desc = messages.notification(messageArgs); notification.section = 'instances'; var performAction = function(data, options) { if (!options) options = {}; var $form = options.$form; action.action({ data: data, ref: options.ref, context: $detailView.data('view-args').context, $form: $form, response: { success: function(args) { args = args ? args : {}; notification._custom = args._custom; // Set loading appearance $detailView.prepend( $('