You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by se...@apache.org on 2013/07/18 18:34:38 UTC
[03/39] Format JS
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ad69bc8d/ui/scripts/ui/widgets/notifications.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui/widgets/notifications.js b/ui/scripts/ui/widgets/notifications.js
index 0299603..fec64c5 100644
--- a/ui/scripts/ui/widgets/notifications.js
+++ b/ui/scripts/ui/widgets/notifications.js
@@ -15,356 +15,367 @@
// specific language governing permissions and limitations
// under the License.
(function($, cloudStack, _l) {
- /**
- * Notification handling
- */
- var notifications = {
- activeTasks: [],
- cornerAlert: function(args, options) {
- if (!options) options = {};
-
- var $container = $('#container'); // Put in main container box
- var $cornerAlert = $('<div>').addClass('notification corner-alert')
- .hide()
- .appendTo($container)
- .append(
- $('<div>').addClass('title').append(
- $('<span>').html(
- options.error ? options.error : _l('label.task.completed')
- )
- )
+ /**
+ * Notification handling
+ */
+ var notifications = {
+ activeTasks: [],
+ cornerAlert: function(args, options) {
+ if (!options) options = {};
+
+ var $container = $('#container'); // Put in main container box
+ var $cornerAlert = $('<div>').addClass('notification corner-alert')
+ .hide()
+ .appendTo($container)
+ .append(
+ $('<div>').addClass('title').append(
+ $('<span>').html(
+ options.error ? options.error : _l('label.task.completed')
+ )
+ )
)
- .append(
- $('<div>').addClass('message')
.append(
- $('<span>').html(_l(args.message))
- )
+ $('<div>').addClass('message')
+ .append(
+ $('<span>').html(_l(args.message))
+ )
);
- if (options.error) {
- $cornerAlert.addClass('error');
- }
-
- return $cornerAlert
- .css({
- opacity: 0,
- position: 'absolute',
- top: $($container).height(),
- left: $($container).width() - $cornerAlert.width()
- })
- .animate({
- opacity: 1,
- top: $container.height() - $cornerAlert.height()
- }, {
- complete: function() {
- setTimeout(function() {
- $cornerAlert.fadeOut('fast', function() {
- $cornerAlert.remove();
- });
- }, 5000);
- }
- })
- .show();
- },
- add: function(args, $popup, $total) {
- var currentTotal = parseInt($total.html());
- var newTotal = currentTotal + 1;
- var desc = args.desc;
- var section = $('html body')
- .find('[cloudStack-container]')
- .data('cloudStack-args')
- .sections[args.section];
- var _custom = args._custom;
-
- var $item = $('<li>')
- .append(
- $('<span>').html(_l(args.desc))
+ if (options.error) {
+ $cornerAlert.addClass('error');
+ }
+
+ return $cornerAlert
+ .css({
+ opacity: 0,
+ position: 'absolute',
+ top: $($container).height(),
+ left: $($container).width() - $cornerAlert.width()
+ })
+ .animate({
+ opacity: 1,
+ top: $container.height() - $cornerAlert.height()
+ }, {
+ complete: function() {
+ setTimeout(function() {
+ $cornerAlert.fadeOut('fast', function() {
+ $cornerAlert.remove();
+ });
+ }, 5000);
+ }
+ })
+ .show();
+ },
+ add: function(args, $popup, $total) {
+ var currentTotal = parseInt($total.html());
+ var newTotal = currentTotal + 1;
+ var desc = args.desc;
+ var section = $('html body')
+ .find('[cloudStack-container]')
+ .data('cloudStack-args')
+ .sections[args.section];
+ var _custom = args._custom;
+
+ var $item = $('<li>')
+ .append(
+ $('<span>').html(_l(args.desc))
)
- .append(
- $('<div>').addClass('remove')
+ .append(
+ $('<div>').addClass('remove')
);
- var additionalComplete = args.complete;
-
- // Get information for specified section path
- $item.data('notification-section', args.section);
- $item.data('notification-custom', _custom);
- $popup.find('ul').append($item);
- $total.html(newTotal);
- $total.parent().addClass('pending');
- $item.addClass('pending');
-
- // Setup timer
- var pollTimer = setInterval(function() {
- args.poll({
- _custom: _custom,
- pollTimer: pollTimer,
- complete: function(args) {
- clearInterval(pollTimer);
-
- notifications.cornerAlert({ message: $item.html() });
- notifications.activeTasks.pop(pollTimer);
- $item.removeClass('pending');
-
- if (additionalComplete) additionalComplete();
- },
- incomplete: function(args) {},
- error: function(args) {
- if (args.message) {
- cloudStack.dialog.notice({ message: _s(args.message) });
+ var additionalComplete = args.complete;
+
+ // Get information for specified section path
+ $item.data('notification-section', args.section);
+ $item.data('notification-custom', _custom);
+ $popup.find('ul').append($item);
+ $total.html(newTotal);
+ $total.parent().addClass('pending');
+ $item.addClass('pending');
+
+ // Setup timer
+ var pollTimer = setInterval(function() {
+ args.poll({
+ _custom: _custom,
+ pollTimer: pollTimer,
+ complete: function(args) {
+ clearInterval(pollTimer);
+
+ notifications.cornerAlert({
+ message: $item.html()
+ });
+ notifications.activeTasks.pop(pollTimer);
+ $item.removeClass('pending');
+
+ if (additionalComplete) additionalComplete();
+ },
+ incomplete: function(args) {},
+ error: function(args) {
+ if (args.message) {
+ cloudStack.dialog.notice({
+ message: _s(args.message)
+ });
+ }
+
+ clearInterval(pollTimer);
+ notifications.activeTasks.pop(pollTimer);
+ notifications.cornerAlert({
+ message: $item.html()
+ }, {
+ error: _l('label.error')
+ });
+ $item.removeClass('pending').addClass('error');
+
+ if (additionalComplete) additionalComplete();
+ }
+ });
+ }, args.interval);
+ notifications.activeTasks.push(pollTimer);
+
+ return $total;
+ },
+
+ /**
+ * Set total to 0
+ */
+ resetTotal: function($popup) {
+ var $total = $popup.data('notifications-attach-to').find('div.total span');
+ var $items = $popup.find('ul li');
+ var total = $items.size();
+ var completed = $items.filter(':not(.pending)').size();
+ var newTotal = total - completed;
+
+ if (newTotal < 0) newTotal = completed;
+
+ $total.html(newTotal);
+
+ if (!newTotal)
+ $total.parent().removeClass('pending');
+ },
+
+ /**
+ * Remove item from notification list
+ */
+ removeItem: function($popup, $item) {
+ if ($item.closest('li').hasClass('pending')) return false;
+
+ $item.remove();
+
+ return true;
+ },
+
+ /**
+ * Remove all completed notifications
+ */
+ clear: function($popup) {
+ $popup.find('ul li').each(function() {
+ var $item = $(this);
+
+ if (!$item.hasClass('pending')) {
+ notifications.removeItem($popup, $item);
+ }
+ });
+ },
+ popup: {
+ create: function($attachTo) {
+ var $popup = $('<div>')
+ .addClass('notification-box')
+ .append(
+ // Header
+ $('<h3>').html(_l('label.notifications'))
+ )
+ .append(
+ // Container
+ $('<div>').addClass('container')
+ .append(
+ // Notification list
+ $('<ul>')
+ )
+ )
+ .append(
+ // Buttons
+ $('<div>').addClass('buttons')
+ .append(
+ // Clear list
+ $('<div>').addClass('button clear-list')
+ .append(
+ $('<span>').html(_l('label.clear.list'))
+ )
+ )
+ .append(
+ $('<div>').addClass('button close')
+ .append(
+ $('<span>').html(_l('label.close'))
+ )
+ )
+ )
+ .css({
+ position: 'absolute'
+ })
+ .data('notifications-attach-to', $attachTo)
+ .hide();
+
+ if (!$attachTo.hasClass('notifications')) $attachTo.addClass('notifications');
+ $attachTo.data('notifications-popup', $popup);
+
+ return $popup;
+ },
+ show: function($popup, $attachTo) {
+ notifications.resetTotal($popup);
+ return notifications.popup.reposition($popup, $attachTo)
+ .overlay({
+ closeAction: function() {
+ notifications.popup.hide($popup);
+ }
+ })
+ .fadeIn();
+ },
+ hide: function($popup) {
+ $popup.fadeOut();
+ },
+ reposition: function($popup, $attachTo) {
+ return $popup
+ .css({
+ zIndex: 10000,
+ top: $attachTo.offset().top + $attachTo.height() + 10,
+ left: $attachTo.offset().left - $attachTo.width()
+ });
}
+ }
+ };
- clearInterval(pollTimer);
- notifications.activeTasks.pop(pollTimer);
- notifications.cornerAlert({ message: $item.html() }, {
- error: _l('label.error')
- });
- $item.removeClass('pending').addClass('error');
+ /**
+ * Define notification widget -- this is basically represented in a
+ * notifications icon, that contains a pop-up list of notifications
+ */
+ $.fn.notifications = function(method, args) {
+ var $attachTo = this;
+ var $total = $attachTo.find('div.total span');
+ var $popup;
- if (additionalComplete) additionalComplete();
- }
- });
- }, args.interval);
- notifications.activeTasks.push(pollTimer);
+ var init = function() {
+ $popup = notifications.popup.create($attachTo).appendTo('html body');
+ };
- return $total;
- },
+ if (method == 'add')
+ notifications.add(args, $attachTo.data('notifications-popup'), $total);
+ else
+ init();
+
+ return this;
+ };
/**
- * Set total to 0
+ * Notifications UI helpers
*/
- resetTotal: function($popup) {
- var $total = $popup.data('notifications-attach-to').find('div.total span');
- var $items = $popup.find('ul li');
- var total = $items.size();
- var completed = $items.filter(':not(.pending)').size();
- var newTotal = total - completed;
+ cloudStack.ui.notifications = {
+ add: function(notification, success, successArgs, error, errorArgs) {
+ if (!notification) {
+ success(successArgs);
+
+ return false;
+ };
+
+ var $notifications = $('div.notifications');
+
+ if (!notification.poll) {
+ cloudStack.ui.event.call('addNotification', {
+ section: notification.section,
+ desc: notification.desc,
+ interval: 0,
+ poll: function(args) {
+ success(successArgs);
+ args.complete();
+ }
+ });
+ } else {
+ cloudStack.ui.event.call('addNotification', {
+ section: notification.section,
+ desc: notification.desc,
+ interval: notification.interval ? notification.interval : g_queryAsyncJobResultInterval,
+ _custom: notification._custom,
+ poll: function(args) {
+ var complete = args.complete;
+ var notificationError = args.error;
+
+ notification.poll({
+ _custom: args._custom,
+ complete: function(args) {
+ success($.extend(successArgs, args));
+ complete(args);
+ },
+ error: function(args) {
+ error($.extend(errorArgs, args));
+ notificationError(args);
+ }
+ });
+ }
+ });
+ }
- if (newTotal < 0) newTotal = completed;
+ return true;
+ }
+ };
- $total.html(newTotal);
+ // Setup notification listener -- accepts same args as
+ $(window).bind('cloudStack.addNotification', function(event, data) {
+ $('.notifications').notifications('add', data);
+ });
- if (!newTotal)
- $total.parent().removeClass('pending');
- },
+ $(document).click(function(event) {
+ var $target = $(event.target);
+ var $attachTo, $popup;
- /**
- * Remove item from notification list
- */
- removeItem: function($popup, $item) {
- if ($item.closest('li').hasClass('pending')) return false;
+ // Notifications header area
+ if ($target.closest('.notifications').size()) {
+ $attachTo = $target.closest('.notifications');
+ $popup = $attachTo.data('notifications-popup');
+ notifications.popup.show($popup, $attachTo);
- $item.remove();
+ return false;
+ }
- return true;
- },
+ // Notification item
+ if ($target.is('.notification-box li span')) {
+ var $li = $target.closest('.notification-box li');
- /**
- * Remove all completed notifications
- */
- clear: function($popup) {
- $popup.find('ul li').each(function() {
- var $item = $(this);
+ $('#navigation ul li').filter(function() {
+ return $(this).hasClass($li.data('notification-section'));
+ }).click();
+ $('div.overlay').click();
- if (!$item.hasClass('pending')) {
- notifications.removeItem($popup, $item);
+ return false;
}
- });
- },
- popup: {
- create: function($attachTo) {
- var $popup = $('<div>')
- .addClass('notification-box')
- .append(
- // Header
- $('<h3>').html(_l('label.notifications'))
- )
- .append(
- // Container
- $('<div>').addClass('container')
- .append(
- // Notification list
- $('<ul>')
- )
- )
- .append(
- // Buttons
- $('<div>').addClass('buttons')
- .append(
- // Clear list
- $('<div>').addClass('button clear-list')
- .append(
- $('<span>').html(_l('label.clear.list'))
- )
- )
- .append(
- $('<div>').addClass('button close')
- .append(
- $('<span>').html(_l('label.close'))
- )
- )
- )
- .css({ position: 'absolute' })
- .data('notifications-attach-to', $attachTo)
- .hide();
-
- if (!$attachTo.hasClass('notifications')) $attachTo.addClass('notifications');
- $attachTo.data('notifications-popup', $popup);
-
- return $popup;
- },
- show: function($popup, $attachTo) {
- notifications.resetTotal($popup);
- return notifications.popup.reposition($popup, $attachTo)
- .overlay({
- closeAction: function() {
- notifications.popup.hide($popup);
+
+ // Popup
+ if ($target.closest('div.notification-box').size()) {
+ $popup = $target.closest('div.notification-box');
+
+ // Clear list
+ if ($target.closest('.button.clear-list').size()) {
+ notifications.clear($popup);
}
- })
- .fadeIn();
- },
- hide: function($popup) {
- $popup.fadeOut();
- },
- reposition: function($popup, $attachTo) {
- return $popup
- .css({
- zIndex: 10000,
- top: $attachTo.offset().top + $attachTo.height() + 10,
- left: $attachTo.offset().left - $attachTo.width()
- });
- }
- }
- };
-
- /**
- * Define notification widget -- this is basically represented in a
- * notifications icon, that contains a pop-up list of notifications
- */
- $.fn.notifications = function(method, args) {
- var $attachTo = this;
- var $total = $attachTo.find('div.total span');
- var $popup;
-
- var init = function() {
- $popup = notifications.popup.create($attachTo).appendTo('html body');
- };
- if (method == 'add')
- notifications.add(args, $attachTo.data('notifications-popup'), $total);
- else
- init();
-
- return this;
- };
-
- /**
- * Notifications UI helpers
- */
- cloudStack.ui.notifications = {
- add: function(notification, success, successArgs, error, errorArgs) {
- if (!notification) {
- success(successArgs);
-
- return false;
- };
-
- var $notifications = $('div.notifications');
-
- if (!notification.poll) {
- cloudStack.ui.event.call('addNotification', {
- section: notification.section,
- desc: notification.desc,
- interval: 0,
- poll: function(args) { success(successArgs); args.complete(); }
- });
- } else {
- cloudStack.ui.event.call('addNotification', {
- section: notification.section,
- desc: notification.desc,
- interval: notification.interval ? notification.interval : g_queryAsyncJobResultInterval,
- _custom: notification._custom,
- poll: function(args) {
- var complete = args.complete;
- var notificationError = args.error;
-
- notification.poll({
- _custom: args._custom,
- complete: function(args) {
- success($.extend(successArgs, args));
- complete(args);
- },
- error: function(args) {
- error($.extend(errorArgs, args));
- notificationError(args);
- }
- });
- }
- });
- }
-
- return true;
- }
- };
-
- // Setup notification listener -- accepts same args as
- $(window).bind('cloudStack.addNotification', function(event, data) {
- $('.notifications').notifications('add', data);
- });
-
- $(document).click(function(event) {
- var $target = $(event.target);
- var $attachTo, $popup;
-
- // Notifications header area
- if ($target.closest('.notifications').size()) {
- $attachTo = $target.closest('.notifications');
- $popup = $attachTo.data('notifications-popup');
- notifications.popup.show($popup, $attachTo);
-
- return false;
- }
-
- // Notification item
- if ($target.is('.notification-box li span')) {
- var $li = $target.closest('.notification-box li');
-
- $('#navigation ul li').filter(function() {
- return $(this).hasClass($li.data('notification-section'));
- }).click();
- $('div.overlay').click();
-
- return false;
- }
-
- // Popup
- if ($target.closest('div.notification-box').size()) {
- $popup = $target.closest('div.notification-box');
-
- // Clear list
- if ($target.closest('.button.clear-list').size()) {
- notifications.clear($popup);
- }
-
- // Remove instance item
- else if ($target.hasClass('remove')) {
- notifications.removeItem($popup, $target.closest('li'));
- }
-
- // Close button
- else if ($target.closest('.button.close')) {
- $('div.overlay').click();
- }
-
- return false;
- }
-
- return true;
- });
-
- $(window).resize(function(event) {
- var $popup = $('div.notification-box:visible');
-
- if ($popup.size())
- notifications.popup.reposition($popup, $popup.data('notifications-attach-to'));
- });
+ // Remove instance item
+ else if ($target.hasClass('remove')) {
+ notifications.removeItem($popup, $target.closest('li'));
+ }
+
+ // Close button
+ else if ($target.closest('.button.close')) {
+ $('div.overlay').click();
+ }
+
+ return false;
+ }
+
+ return true;
+ });
+
+ $(window).resize(function(event) {
+ var $popup = $('div.notification-box:visible');
+
+ if ($popup.size())
+ notifications.popup.reposition($popup, $popup.data('notifications-attach-to'));
+ });
})(window.jQuery, window.cloudStack, window._l);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ad69bc8d/ui/scripts/ui/widgets/overlay.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui/widgets/overlay.js b/ui/scripts/ui/widgets/overlay.js
index ecf12e6..95db303 100644
--- a/ui/scripts/ui/widgets/overlay.js
+++ b/ui/scripts/ui/widgets/overlay.js
@@ -15,36 +15,36 @@
// specific language governing permissions and limitations
// under the License.
(function($) {
- /**
- * Create a dark overlay, for modal dialogs, etc.
- */
- $.fn.overlay = function(args) {
- var $topElem = this;
- var $overlay = $('<div class="overlay">').hide().appendTo('html body').css({
- position: 'absolute',
- background: 'black',
- opacity: 0.5,
- width: '100%',
- height: '100%',
- top: $(window).scrollTop(),
- left: 0,
- zIndex: $topElem.css('z-index') - 1
- }).show();
+ /**
+ * Create a dark overlay, for modal dialogs, etc.
+ */
+ $.fn.overlay = function(args) {
+ var $topElem = this;
+ var $overlay = $('<div class="overlay">').hide().appendTo('html body').css({
+ position: 'absolute',
+ background: 'black',
+ opacity: 0.5,
+ width: '100%',
+ height: '100%',
+ top: $(window).scrollTop(),
+ left: 0,
+ zIndex: $topElem.css('z-index') - 1
+ }).show();
- // Events
- $overlay.click(function(event) {
- if (!args || !args.closeAction) return false;
+ // Events
+ $overlay.click(function(event) {
+ if (!args || !args.closeAction) return false;
- args.closeAction();
- $overlay.fadeOut(function() {
- $overlay.remove();
- });
- });
+ args.closeAction();
+ $overlay.fadeOut(function() {
+ $overlay.remove();
+ });
+ });
+
+ return this;
+ };
- return this;
- };
-
- $(window).bind('resize scroll', function() {
- $('.overlay').css( 'top', $(window).scrollTop());
- });
+ $(window).bind('resize scroll', function() {
+ $('.overlay').css('top', $(window).scrollTop());
+ });
})(window.jQuery);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ad69bc8d/ui/scripts/ui/widgets/tagger.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui/widgets/tagger.js b/ui/scripts/ui/widgets/tagger.js
index 9af6fb7..4a02d8b 100644
--- a/ui/scripts/ui/widgets/tagger.js
+++ b/ui/scripts/ui/widgets/tagger.js
@@ -16,220 +16,236 @@
// under the License.
(function($, cloudStack) {
- var isFormValid = function($form) {
- var key = $form.find('input[name=key]').val();
- var value = $form.find('input[name=value]').val();
-
- if (!key || !value) {
- cloudStack.dialog.notice({ message: 'Please specify a tag key and value' });
- return false;
- }
-
- if($form.find('div.field.key').find('label.error').css('display') == 'block' || $form.find('div.field.value').find('label.error').css('display') == 'block')
- return false;
-
- return true;
- };
-
- var elems = {
- inputArea: function(args) {
- var $form = $('<form>').addClass('tag-input');
- var $keyField = $('<div>').addClass('field key');
- var $keyLabel = $('<label>').attr('for', 'key').html(_l('label.key') + ':');
- var $key = $('<input>').addClass('key disallowSpecialCharacters').attr('name', 'key');
- var $valueField = $('<div>').addClass('field value');
- var $valueLabel = $('<label>').attr('for', 'value').html(_l('label.value') + ':');
- var $value = $('<input>').addClass('value disallowSpecialCharacters').attr('name', 'value');
- var $submit = $('<input>').attr('type', 'submit').val('Add');
-
- $keyField.append($keyLabel, $key);
- $valueField.append($valueLabel, $value);
- $form.append(
- $keyField, $valueField,
- $submit
- );
-
- $form.validate();
-
- $form.submit(
- args.onSubmit ?
- function() {
- if (!isFormValid($form)) return false;
-
- args.onSubmit({
- data: cloudStack.serializeForm($form),
- response: {
- success: function() {
- // Restore editing of input
- $key.attr('disabled', false);
- $value.attr('disabled', false);
-
- // Clear out old data
- $key.val(''); $value.val('');
- $key.focus();
- },
- error: function() {
- // Restore editing of input
- $key.attr('disabled', false);
- $value.attr('disabled', false);
- $key.focus();
- }
- }
+ var isFormValid = function($form) {
+ var key = $form.find('input[name=key]').val();
+ var value = $form.find('input[name=value]').val();
+
+ if (!key || !value) {
+ cloudStack.dialog.notice({
+ message: 'Please specify a tag key and value'
});
-
- // Prevent input during submission
- $key.attr('disabled', 'disabled');
- $value.attr('disabled', 'disabled');
-
return false;
- } :
- function() { return false; }
- );
-
- return $form;
- },
- tagItem: function(title, onRemove, data) {
- var $li = $('<li>');
- var $label = $('<span>').addClass('label').html(_s(title));
- var $remove = $('<span>').addClass('remove').html('X');
-
- $remove.click(function() {
- if (onRemove) onRemove($li, data);
- });
-
- $li.append($remove, $label);
-
- return $li;
- },
-
- info: function(text) {
- var $info = $('<div>').addClass('tag-info');
- var $text = $('<span>').html(text);
-
- $text.appendTo($info);
-
- return $info;
- }
- };
-
- $.widget('cloudStack.tagger', {
- _init: function(args) {
- var context = this.options.context;
- var jsonObj = this.options.jsonObj;
- var dataProvider = this.options.dataProvider;
- var actions = this.options.actions;
- var $container = this.element.addClass('tagger');
- var $tagArea = $('<ul>').addClass('tags');
- var $title = elems.info(_l('label.tags')).addClass('title');
- var $loading = $('<div>').addClass('loading-overlay');
-
- var onRemoveItem = function($item, data) {
- $loading.appendTo($container);
- actions.remove({
- context: $.extend(true, {}, context, {
- tagItems: [data]
- }),
- response: {
- success: function(args) {
- var notification = $.extend(true, {} , args.notification, {
- interval: 500,
- _custom: args._custom
- });
-
- cloudStack.ui.notifications.add(
- notification,
-
- // Success
- function() {
- $loading.remove();
- $item.remove();
- }, {},
+ }
+
+ if ($form.find('div.field.key').find('label.error').css('display') == 'block' || $form.find('div.field.value').find('label.error').css('display') == 'block')
+ return false;
- // Error
+ return true;
+ };
+
+ var elems = {
+ inputArea: function(args) {
+ var $form = $('<form>').addClass('tag-input');
+ var $keyField = $('<div>').addClass('field key');
+ var $keyLabel = $('<label>').attr('for', 'key').html(_l('label.key') + ':');
+ var $key = $('<input>').addClass('key disallowSpecialCharacters').attr('name', 'key');
+ var $valueField = $('<div>').addClass('field value');
+ var $valueLabel = $('<label>').attr('for', 'value').html(_l('label.value') + ':');
+ var $value = $('<input>').addClass('value disallowSpecialCharacters').attr('name', 'value');
+ var $submit = $('<input>').attr('type', 'submit').val('Add');
+
+ $keyField.append($keyLabel, $key);
+ $valueField.append($valueLabel, $value);
+ $form.append(
+ $keyField, $valueField,
+ $submit
+ );
+
+ $form.validate();
+
+ $form.submit(
+ args.onSubmit ?
function() {
- $loading.remove();
- }, {}
- );
- },
- error: function(message) {
- $loading.remove();
- cloudStack.dialog.notice({ message: message });
- }
- }
- });
- };
-
- var $inputArea = elems.inputArea({
- onSubmit: function(args) {
- var data = args.data;
- var success = args.response.success;
- var error = args.response.error;
- var title = data.key + ' = ' + data.value;
-
- $loading.appendTo($container);
- actions.add({
- data: data,
- context: context,
- response: {
- success: function(args) {
- var notification = $.extend(true, {} , args.notification, {
- interval: 500,
- _custom: args._custom
- });
+ if (!isFormValid($form)) return false;
+
+ args.onSubmit({
+ data: cloudStack.serializeForm($form),
+ response: {
+ success: function() {
+ // Restore editing of input
+ $key.attr('disabled', false);
+ $value.attr('disabled', false);
+
+ // Clear out old data
+ $key.val('');
+ $value.val('');
+ $key.focus();
+ },
+ error: function() {
+ // Restore editing of input
+ $key.attr('disabled', false);
+ $value.attr('disabled', false);
+ $key.focus();
+ }
+ }
+ });
+
+ // Prevent input during submission
+ $key.attr('disabled', 'disabled');
+ $value.attr('disabled', 'disabled');
+
+ return false;
+ } :
+ function() {
+ return false;
+ }
+ );
- cloudStack.ui.notifications.add(
- notification,
-
- // Success
- function() {
- $loading.remove();
- elems.tagItem(title, onRemoveItem, data).appendTo($tagArea);
- success();
- }, {},
-
- // Error
- function() {
- $loading.remove();
- error();
- }, {}
- );
- },
- error: function(message) {
- $loading.remove();
- error();
- cloudStack.dialog.notice({ message: message });
- }
- }
- });
+ return $form;
+ },
+ tagItem: function(title, onRemove, data) {
+ var $li = $('<li>');
+ var $label = $('<span>').addClass('label').html(_s(title));
+ var $remove = $('<span>').addClass('remove').html('X');
+
+ $remove.click(function() {
+ if (onRemove) onRemove($li, data);
+ });
+
+ $li.append($remove, $label);
+
+ return $li;
+ },
+
+ info: function(text) {
+ var $info = $('<div>').addClass('tag-info');
+ var $text = $('<span>').html(text);
+
+ $text.appendTo($info);
+
+ return $info;
}
- });
-
- $container.append($title, $inputArea, $tagArea);
-
- // Get data
- $loading.appendTo($container);
- dataProvider({
- context: context,
- jsonObj: jsonObj,
- response: {
- success: function(args) {
- var data = args.data;
-
- $loading.remove();
- $(data).map(function(index, item) {
- var key = item.key;
- var value = item.value;
- var data = { key: key, value: value };
-
- elems.tagItem(key + ' = ' + value, onRemoveItem, data).appendTo($tagArea);
+ };
+
+ $.widget('cloudStack.tagger', {
+ _init: function(args) {
+ var context = this.options.context;
+ var jsonObj = this.options.jsonObj;
+ var dataProvider = this.options.dataProvider;
+ var actions = this.options.actions;
+ var $container = this.element.addClass('tagger');
+ var $tagArea = $('<ul>').addClass('tags');
+ var $title = elems.info(_l('label.tags')).addClass('title');
+ var $loading = $('<div>').addClass('loading-overlay');
+
+ var onRemoveItem = function($item, data) {
+ $loading.appendTo($container);
+ actions.remove({
+ context: $.extend(true, {}, context, {
+ tagItems: [data]
+ }),
+ response: {
+ success: function(args) {
+ var notification = $.extend(true, {}, args.notification, {
+ interval: 500,
+ _custom: args._custom
+ });
+
+ cloudStack.ui.notifications.add(
+ notification,
+
+ // Success
+
+ function() {
+ $loading.remove();
+ $item.remove();
+ }, {},
+
+ // Error
+
+ function() {
+ $loading.remove();
+ }, {}
+ );
+ },
+ error: function(message) {
+ $loading.remove();
+ cloudStack.dialog.notice({
+ message: message
+ });
+ }
+ }
+ });
+ };
+
+ var $inputArea = elems.inputArea({
+ onSubmit: function(args) {
+ var data = args.data;
+ var success = args.response.success;
+ var error = args.response.error;
+ var title = data.key + ' = ' + data.value;
+
+ $loading.appendTo($container);
+ actions.add({
+ data: data,
+ context: context,
+ response: {
+ success: function(args) {
+ var notification = $.extend(true, {}, args.notification, {
+ interval: 500,
+ _custom: args._custom
+ });
+
+ cloudStack.ui.notifications.add(
+ notification,
+
+ // Success
+
+ function() {
+ $loading.remove();
+ elems.tagItem(title, onRemoveItem, data).appendTo($tagArea);
+ success();
+ }, {},
+
+ // Error
+
+ function() {
+ $loading.remove();
+ error();
+ }, {}
+ );
+ },
+ error: function(message) {
+ $loading.remove();
+ error();
+ cloudStack.dialog.notice({
+ message: message
+ });
+ }
+ }
+ });
+ }
+ });
+
+ $container.append($title, $inputArea, $tagArea);
+
+ // Get data
+ $loading.appendTo($container);
+ dataProvider({
+ context: context,
+ jsonObj: jsonObj,
+ response: {
+ success: function(args) {
+ var data = args.data;
+
+ $loading.remove();
+ $(data).map(function(index, item) {
+ var key = item.key;
+ var value = item.value;
+ var data = {
+ key: key,
+ value: value
+ };
+
+ elems.tagItem(key + ' = ' + value, onRemoveItem, data).appendTo($tagArea);
+ });
+ },
+ error: function(message) {
+ $loading.remove();
+ $container.find('ul').html(message);
+ }
+ }
});
- },
- error: function(message) {
- $loading.remove();
- $container.find('ul').html(message);
- }
}
- });
- }
- });
+ });
}(jQuery, cloudStack));
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ad69bc8d/ui/scripts/ui/widgets/toolTip.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui/widgets/toolTip.js b/ui/scripts/ui/widgets/toolTip.js
index 6967acc..747c448 100644
--- a/ui/scripts/ui/widgets/toolTip.js
+++ b/ui/scripts/ui/widgets/toolTip.js
@@ -14,151 +14,157 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-(function($,cloudStack) {
- $.widget("cloudStack.toolTip", {
- _init: function(args) {
- var context = this.options.context;
- var dataProvider = this.options.dataProvider;
- var actions = this.options.actions;
- var docID = this.options.docID;
- var text = cloudStack.docs[docID].desc;
- var $tooltip = $('<div>').addClass('tooltip-box');
- var $text = $('<p>').html(text).appendTo($tooltip);
- var $container = $('#cloudStack3-container');
+(function($, cloudStack) {
+ $.widget("cloudStack.toolTip", {
+ _init: function(args) {
+ var context = this.options.context;
+ var dataProvider = this.options.dataProvider;
+ var actions = this.options.actions;
+ var docID = this.options.docID;
+ var text = cloudStack.docs[docID].desc;
+ var $tooltip = $('<div>').addClass('tooltip-box');
+ var $text = $('<p>').html(text).appendTo($tooltip);
+ var $container = $('#cloudStack3-container');
+
+ $tooltip.appendTo($container);
+
+ if (this.options.mode == 'hover') {
+ $(this.element).hover(hoverHandler, outHandler);
+ } else if (this.options.mode == 'focus') {
+ $(this.element).focus(hoverHandler);
+ $(this.element).blur(outHandler);
+ } else if (this.options.mode == 'manual') {}
+
+ $(this.element).data('$tooltip', $tooltip);
+
+ // Add arrow
+ $tooltip.append($('<div></div>').addClass('arrow'));
+
+ $tooltip.hide();
+ },
+
+ show: function() {
+ var o = this.options;
+
+ if (o.mode == 'manual') {
+ prepare(this.element, o);
+ }
+
+ $(o.toolTip).show();
+ },
+
+ hide: function() {
+ var o = this.options;
+ $(o.toolTip).hide();
+ }
+ });
+
+ $.extend($.cloudStack.toolTip, {
+ defaults: {
+ toolTip: '',
+ onShow: function(sender) {
+ //Flipping arrow and text
+
+ var $tooltip = $('.tooltip-box');
+
+ //Switch styles based on how close to viewport border
+
+ if ($(window).width() - sender.target.offset().left <= $tooltip.width()) {
+
+ $('.tooltiptextleft', $tooltip).removeClass('tooltiptextleft').addClass('tooltiptextright');
+ $('.tooltiparrowleft', $tooltip).removeClass('tooltiparrowleft').addClass('tooltiparrowright');
- $tooltip.appendTo($container);
+ } else {
+ $('.tooltiptextright', $tooltip).removeClass('tooltiptextright').addClass('tooltiptextleft');
+ $('.tooltiparrowright', $tooltip).removeClass('tooltiparrowright').addClass('tooltiparrowleft');
+ }
- if (this.options.mode == 'hover'){
- $(this.element).hover(hoverHandler,outHandler);
- } else if (this.options.mode == 'focus'){
- $(this.element).focus(hoverHandler);
- $(this.element).blur(outHandler);
- } else if (this.options.mode == 'manual'){}
+ },
+ onHide: undefined,
+ mode: 'hover',
+ // provide a speed for the animation
+ speed: 1000,
+ // provide a period for the popup to keep showing
+ period: 2000,
+ // default the animation algorithm to the basic slide
+ animation: 'slide'
+ },
+ animations: {
+ slide: function(e, options) {
- $(this.element).data('$tooltip', $tooltip);
+ },
+ fade: function(e, options) {
- // Add arrow
- $tooltip.append($('<div></div>').addClass('arrow'));
+ }
+ }
+ });
- $tooltip.hide();
- },
+ function hoverHandler(event) {
+ //Fetch Options
+ var o = $.data(this, 'toolTip').options;
- show: function(){
- var o = this.options;
+ //Element who raised the event
+ var $this = $(this);
- if(o.mode=='manual'){
- prepare(this.element,o);
- }
+ //Helper functon for Positioning and Calling Callback function
+ prepare($this, o);
- $(o.toolTip).show();
- },
+ //Call Show method of the tooltip Widget,
+ //Show method should play on any required animations
+ $.data(this, '$tooltip').show();
+ };
- hide: function(){
- var o = this.options;
- $(o.toolTip).hide();
- }
- });
+ function outHandler(event) {
+ //Fetch Options
+ var o = $.data(this, 'toolTip').options;
- $.extend($.cloudStack.toolTip, {
- defaults: {
- toolTip: '',
- onShow: function(sender){
- //Flipping arrow and text
+ //Get tooptip Element
+ var $tooltip = $(o.toolTip);
- var $tooltip = $('.tooltip-box');
+ //If call back method defined, initiate the call
+ if ($.data(this, 'toolTip').options.onHide) {
+ $.data(this, 'toolTip').options.onHide.call(this, {
+ target: $(this)
+ });
+ }
- //Switch styles based on how close to viewport border
+ //Call Hide method of the tooltip Widget,
+ //Hide method should play on any required animations
+ $.data(this, '$tooltip').hide();
+ };
- if($(window).width()-sender.target.offset().left <= $tooltip.width()) {
+ function prepare(jObj, options) {
+ var $tooltip = $(options.tooltip);
+ var element = options.attachTo ?
+ jObj.closest(options.attachTo) : jObj;
+ var offset = element.offset();
- $('.tooltiptextleft',$tooltip).removeClass('tooltiptextleft').addClass('tooltiptextright');
- $('.tooltiparrowleft',$tooltip).removeClass('tooltiparrowleft').addClass('tooltiparrowright');
+ var left = offset.left + element.width();
+ var top = offset.top - 5;
+ if (options.onShow) {
+ options.onShow.call(this, {
+ target: jObj
+ });
}
- else{
- $('.tooltiptextright',$tooltip).removeClass('tooltiptextright').addClass('tooltiptextleft');
- $('.tooltiparrowright',$tooltip).removeClass('tooltiparrowright').addClass('tooltiparrowleft');
+
+ if ($(window).width() - offset.left <= $tooltip.width()) {
+ left = offset.left - $tooltip.width();
+ } else {
+ left += 35;
}
+ $tooltip.css({
+ position: 'absolute',
+ top: top + 'px',
+ left: left + 'px'
+ });
+
+ // Fix overlay
+ setTimeout(function() {
+ $('.tooltip-box').zIndex($(':ui-dialog').zIndex() + 10);
+ });
+
+ };
+
- },
- onHide: undefined,
- mode: 'hover',
- // provide a speed for the animation
- speed: 1000,
- // provide a period for the popup to keep showing
- period: 2000,
- // default the animation algorithm to the basic slide
- animation:'slide'
- },
- animations: {
- slide: function(e, options) {
-
- },
- fade: function(e, options) {
-
- }
- }
- });
-
- function hoverHandler(event)
- {
- //Fetch Options
- var o = $.data(this,'toolTip').options;
-
- //Element who raised the event
- var $this = $(this);
-
- //Helper functon for Positioning and Calling Callback function
- prepare($this,o);
-
- //Call Show method of the tooltip Widget,
- //Show method should play on any required animations
- $.data(this,'$tooltip').show();
- };
- function outHandler(event)
- {
- //Fetch Options
- var o = $.data(this,'toolTip').options;
-
- //Get tooptip Element
- var $tooltip = $(o.toolTip);
-
- //If call back method defined, initiate the call
- if($.data(this,'toolTip').options.onHide){
- $.data(this,'toolTip').options.onHide.call(this, {target:$(this)});
- }
-
- //Call Hide method of the tooltip Widget,
- //Hide method should play on any required animations
- $.data(this,'$tooltip').hide();
- };
- function prepare(jObj, options)
- {
- var $tooltip = $(options.tooltip);
- var element = options.attachTo ?
- jObj.closest(options.attachTo) : jObj;
- var offset = element.offset();
-
- var left = offset.left + element.width();
- var top = offset.top-5;
-
- if(options.onShow){
- options.onShow.call(this, {target:jObj});
- }
-
- if($(window).width()-offset.left <= $tooltip.width()) {
- left = offset.left - $tooltip.width();
- }
- else{
- left += 35;
- }
- $tooltip.css({position:'absolute', top:top+'px', left:left+'px'});
-
- // Fix overlay
- setTimeout(function() {
- $('.tooltip-box').zIndex($(':ui-dialog').zIndex() + 10); });
-
- };
-
-
-})(jQuery,cloudStack);
+})(jQuery, cloudStack);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ad69bc8d/ui/scripts/ui/widgets/treeView.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui/widgets/treeView.js b/ui/scripts/ui/widgets/treeView.js
index fa1ceb6..80a03e2 100644
--- a/ui/scripts/ui/widgets/treeView.js
+++ b/ui/scripts/ui/widgets/treeView.js
@@ -15,130 +15,136 @@
// specific language governing permissions and limitations
// under the License.
(function($, cloudStack, _s) {
- /**
- * Make <ul> of tree items
- */
- var makeTreeList = function(args) {
- var $treeList = $('<ul>');
+ /**
+ * Make <ul> of tree items
+ */
+ var makeTreeList = function(args) {
+ var $treeList = $('<ul>');
- args.dataProvider({
- context: $.extend(args.context, {
- parentDomain: args.parent
- }),
- response: {
- success: function(successArgs) {
- $(successArgs.data).each(function() {
- $('<li>')
- .data('tree-view-item-id', this.id)
- .data('tree-view-item-obj', this)
- .append(
- $('<div>')
- .addClass('expand')
- )
- .append(
- $('<div>').addClass('name')
- .html(_s(this.name))
- )
- .appendTo($treeList);
- });
- }
- }
- });
+ args.dataProvider({
+ context: $.extend(args.context, {
+ parentDomain: args.parent
+ }),
+ response: {
+ success: function(successArgs) {
+ $(successArgs.data).each(function() {
+ $('<li>')
+ .data('tree-view-item-id', this.id)
+ .data('tree-view-item-obj', this)
+ .append(
+ $('<div>')
+ .addClass('expand')
+ )
+ .append(
+ $('<div>').addClass('name')
+ .html(_s(this.name))
+ )
+ .appendTo($treeList);
+ });
+ }
+ }
+ });
- return $treeList;
- };
+ return $treeList;
+ };
- /**
- * Define an infinite 'tree' list
- */
- $.fn.treeView = function(args) {
- var $treeView = $('<div>')
- .appendTo(this)
- .addClass('view tree-view');
- var $toolbar = $('<div>')
- .addClass('toolbar')
- .append(
- $('<div>')
- .addClass('text-search')
- .append(
+ /**
+ * Define an infinite 'tree' list
+ */
+ $.fn.treeView = function(args) {
+ var $treeView = $('<div>')
+ .appendTo(this)
+ .addClass('view tree-view');
+ var $toolbar = $('<div>')
+ .addClass('toolbar')
+ .append(
$('<div>')
- .addClass('search-bar').attr('style', 'display:none') //no place to show search result in a tree, so hide it for now
- .append(
- $('<input>').attr('type', 'text')
- )
- )
- .append(
- $('<div>').addClass('button search').attr('style', 'display:none') //no place to show search result in a tree, so hide it for now
- )
- )
- .prependTo($treeView);
- var treeViewArgs = args.treeView;
- var $browser = args.$browser;
+ .addClass('text-search')
+ .append(
+ $('<div>')
+ .addClass('search-bar').attr('style', 'display:none') //no place to show search result in a tree, so hide it for now
+ .append(
+ $('<input>').attr('type', 'text')
+ )
+ )
+ .append(
+ $('<div>').addClass('button search').attr('style', 'display:none') //no place to show search result in a tree, so hide it for now
+ )
+ )
+ .prependTo($treeView);
+ var treeViewArgs = args.treeView;
+ var $browser = args.$browser;
- makeTreeList({
- parent: null,
- dataProvider: treeViewArgs.dataProvider,
- context: args.context
- }).appendTo($treeView);
+ makeTreeList({
+ parent: null,
+ dataProvider: treeViewArgs.dataProvider,
+ context: args.context
+ }).appendTo($treeView);
- setTimeout(function() {
- $treeView.find('li:first div.name').click();
- }, 100);
+ setTimeout(function() {
+ $treeView.find('li:first div.name').click();
+ }, 100);
- this.click(function(event) {
- var $target = $(event.target);
- var $li = $target.closest('li');
+ this.click(function(event) {
+ var $target = $(event.target);
+ var $li = $target.closest('li');
- if ($target.is('li div.expand') && $li.data('tree-view-item-obj')) {
- if ($li.find('ul').size()) {
- $li.find('ul').remove();
- $li.removeClass('expanded');
+ if ($target.is('li div.expand') && $li.data('tree-view-item-obj')) {
+ if ($li.find('ul').size()) {
+ $li.find('ul').remove();
+ $li.removeClass('expanded');
- return false;
- }
+ return false;
+ }
- makeTreeList({
- parent: $li.data('tree-view-item-obj'),
- dataProvider: treeViewArgs.dataProvider
- }).appendTo($li);
- $li.addClass('expanded');
+ makeTreeList({
+ parent: $li.data('tree-view-item-obj'),
+ dataProvider: treeViewArgs.dataProvider
+ }).appendTo($li);
+ $li.addClass('expanded');
- return false;
- }
+ return false;
+ }
- if ($target.is('li .name')) {
- $treeView.find('li .name').removeClass('selected');
- $target.addClass('selected');
- $browser.cloudBrowser('addPanel', {
- title: $target.html(),
- data: '',
- parent: $treeView.closest('div.panel'),
- complete: function($panel) {
- $panel.detailView($.extend(treeViewArgs.detailView, {
- id: $li.data('tree-view-item-id'),
- $browser: $browser,
- context: { domains: [ $li.data('tree-view-item-obj') ] }
- }));
- }
- });
- }
+ if ($target.is('li .name')) {
+ $treeView.find('li .name').removeClass('selected');
+ $target.addClass('selected');
+ $browser.cloudBrowser('addPanel', {
+ title: $target.html(),
+ data: '',
+ parent: $treeView.closest('div.panel'),
+ complete: function($panel) {
+ $panel.detailView($.extend(treeViewArgs.detailView, {
+ id: $li.data('tree-view-item-id'),
+ $browser: $browser,
+ context: {
+ domains: [$li.data('tree-view-item-obj')]
+ }
+ }));
+ }
+ });
+ }
- return true;
- });
+ return true;
+ });
- // Action events
- $(window).bind('cloudstack.view-item-action', function(event, data) {
- var actionName = data.actionName;
- var $li = $treeView.find('li').filter(function() {
- return $(this).data('tree-view-item-id') == data.id;
- });
+ // Action events
+ $(window).bind('cloudstack.view-item-action', function(event, data) {
+ var actionName = data.actionName;
+ var $li = $treeView.find('li').filter(function() {
+ return $(this).data('tree-view-item-id') == data.id;
+ });
- if (actionName == 'destroy') {
- $li.animate({ opacity: 0.5 });
- $li.bind('click', function() { return false; });
- }
- });
+ if (actionName == 'destroy') {
+ $li.animate({
+ opacity: 0.5
+ });
+ $li.bind('click', function() {
+ return false;
+ });
+ }
+ });
- return this;
- };
+ return this;
+ };
})(jQuery, cloudStack, cloudStack.sanitize);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ad69bc8d/ui/scripts/vm_snapshots.js
----------------------------------------------------------------------
diff --git a/ui/scripts/vm_snapshots.js b/ui/scripts/vm_snapshots.js
index c50c7e1..d7b312c 100644
--- a/ui/scripts/vm_snapshots.js
+++ b/ui/scripts/vm_snapshots.js
@@ -15,182 +15,185 @@
// specific language governing permissions and limitations
// under the License.
(function($, cloudStack) {
- cloudStack.sections.vmsnapshots = {
- title: 'label.vmsnapshot',
- id: 'vmsnapshots',
- listView: {
- id: 'vmsnapshots',
- isMaximized: true,
- fields: {
- displayname: {
- label: 'label.name'
- },
- state: {
- label: 'label.state',
- indicator: {
- 'Ready': 'on',
- 'Error': 'off'
- }
- },
- type:{
- label: 'label.vmsnapshot.type'
- },
- current:{
- label: 'label.vmsnapshot.current',
- converter: cloudStack.converters.toBooleanText
- },
- parentName:{
- label: 'label.vmsnapshot.parentname'
- },
- created: {
- label: 'label.date',
- converter: cloudStack.converters.toLocalDate
- }
- },
-
- dataProvider: function(args) {
- var apiCmd = "listVMSnapshot&listAll=true";
- if (args.context != null) {
- if ("instances" in args.context) {
- apiCmd += "&virtualmachineid=" + args.context.instances[0].id;
- }
- }
- $.ajax({
- url: createURL(apiCmd),
- dataType: "json",
- async: true,
- success: function(json) {
- var jsonObj;
- jsonObj = json.listvmsnapshotresponse.vmSnapshot;
- args.response.success({
- data: jsonObj
- });
- }
- });
- },
- //dataProvider end
- detailView: {
- tabs: {
- details: {
- title: 'label.details',
+ cloudStack.sections.vmsnapshots = {
+ title: 'label.vmsnapshot',
+ id: 'vmsnapshots',
+ listView: {
+ id: 'vmsnapshots',
+ isMaximized: true,
fields: {
- id: {
- label: 'label.id'
- },
- name: {
- label: 'label.name'
- },
- displayname: {
- label: 'label.display.name',
- },
- type: {
- label: 'label.vmsnapshot.type',
- },
- description: {
- label: 'label.description',
- },
- state: {
- label: 'label.state',
- indicator: {
- 'Ready': 'on',
- 'Error': 'off'
+ displayname: {
+ label: 'label.name'
+ },
+ state: {
+ label: 'label.state',
+ indicator: {
+ 'Ready': 'on',
+ 'Error': 'off'
+ }
+ },
+ type: {
+ label: 'label.vmsnapshot.type'
+ },
+ current: {
+ label: 'label.vmsnapshot.current',
+ converter: cloudStack.converters.toBooleanText
+ },
+ parentName: {
+ label: 'label.vmsnapshot.parentname'
+ },
+ created: {
+ label: 'label.date',
+ converter: cloudStack.converters.toLocalDate
}
- },
- current: {
- label: 'label.vmsnapshot.current',
- converter: cloudStack.converters.toBooleanText
- },
- parentName: {
- label: 'label.vmsnapshot.parentname'
- },
- created: {
- label: 'label.date',
- converter: cloudStack.converters.toLocalDate
- },
-
},
+
dataProvider: function(args) {
- $.ajax({
- url: createURL("listVMSnapshot&listAll=true&id=" + args.context.vmsnapshots[0].id),
- dataType: "json",
- async: true,
- success: function(json) {
- var jsonObj;
- jsonObj = json.listvmsnapshotresponse.vmSnapshot[0];
- args.response.success({
- //actionFilter: vmActionfilter,
- data: jsonObj
- });
- }
- });
- },
- tags: cloudStack.api.tags({ resourceType: 'VMSnapshot', contextId: 'vmsnapshots' })
- }
- },
- actions: {
- //delete a snapshot
- remove: {
- label: 'label.action.vmsnapshot.delete',
- messages: {
- confirm: function(args) {
- return 'message.action.vmsnapshot.delete';
- },
- notification: function(args) {
- return 'label.action.vmsnapshot.delete';
- }
- },
- action: function(args) {
- $.ajax({
- url: createURL("deleteVMSnapshot&vmsnapshotid=" + args.context.vmsnapshots[0].id),
- dataType: "json",
- async: true,
- success: function(json) {
- var jid = json.deletevmsnapshotresponse.jobid;
- args.response.success(
- {_custom:
- {jobId: jid}
+ var apiCmd = "listVMSnapshot&listAll=true";
+ if (args.context != null) {
+ if ("instances" in args.context) {
+ apiCmd += "&virtualmachineid=" + args.context.instances[0].id;
}
- );
}
- });
- },
- notification: {
- poll: pollAsyncJobResult
- }
- },
- restart: {
- label: 'label.action.vmsnapshot.revert',
- messages: {
- confirm: function(args) {
- return 'label.action.vmsnapshot.revert';
- },
- notification: function(args) {
- return 'message.action.vmsnapshot.revert';
- }
+ $.ajax({
+ url: createURL(apiCmd),
+ dataType: "json",
+ async: true,
+ success: function(json) {
+ var jsonObj;
+ jsonObj = json.listvmsnapshotresponse.vmSnapshot;
+ args.response.success({
+ data: jsonObj
+ });
+ }
+ });
},
- action: function(args) {
- $.ajax({
- url: createURL("revertToVMSnapshot&vmsnapshotid=" + args.context.vmsnapshots[0].id),
- dataType: "json",
- async: true,
- success: function(json) {
- var jid = json.reverttovmsnapshotresponse.jobid;
- args.response.success({
- _custom: {
- jobId: jid
+ //dataProvider end
+ detailView: {
+ tabs: {
+ details: {
+ title: 'label.details',
+ fields: {
+ id: {
+ label: 'label.id'
+ },
+ name: {
+ label: 'label.name'
+ },
+ displayname: {
+ label: 'label.display.name',
+ },
+ type: {
+ label: 'label.vmsnapshot.type',
+ },
+ description: {
+ label: 'label.description',
+ },
+ state: {
+ label: 'label.state',
+ indicator: {
+ 'Ready': 'on',
+ 'Error': 'off'
+ }
+ },
+ current: {
+ label: 'label.vmsnapshot.current',
+ converter: cloudStack.converters.toBooleanText
+ },
+ parentName: {
+ label: 'label.vmsnapshot.parentname'
+ },
+ created: {
+ label: 'label.date',
+ converter: cloudStack.converters.toLocalDate
+ },
+
+ },
+ dataProvider: function(args) {
+ $.ajax({
+ url: createURL("listVMSnapshot&listAll=true&id=" + args.context.vmsnapshots[0].id),
+ dataType: "json",
+ async: true,
+ success: function(json) {
+ var jsonObj;
+ jsonObj = json.listvmsnapshotresponse.vmSnapshot[0];
+ args.response.success({
+ //actionFilter: vmActionfilter,
+ data: jsonObj
+ });
+ }
+ });
+ },
+ tags: cloudStack.api.tags({
+ resourceType: 'VMSnapshot',
+ contextId: 'vmsnapshots'
+ })
}
- });
- }
- });
+ },
+ actions: {
+ //delete a snapshot
+ remove: {
+ label: 'label.action.vmsnapshot.delete',
+ messages: {
+ confirm: function(args) {
+ return 'message.action.vmsnapshot.delete';
+ },
+ notification: function(args) {
+ return 'label.action.vmsnapshot.delete';
+ }
+ },
+ action: function(args) {
+ $.ajax({
+ url: createURL("deleteVMSnapshot&vmsnapshotid=" + args.context.vmsnapshots[0].id),
+ dataType: "json",
+ async: true,
+ success: function(json) {
+ var jid = json.deletevmsnapshotresponse.jobid;
+ args.response.success({
+ _custom: {
+ jobId: jid
+ }
+ });
+ }
+ });
+ },
+ notification: {
+ poll: pollAsyncJobResult
+ }
+ },
+ restart: {
+ label: 'label.action.vmsnapshot.revert',
+ messages: {
+ confirm: function(args) {
+ return 'label.action.vmsnapshot.revert';
+ },
+ notification: function(args) {
+ return 'message.action.vmsnapshot.revert';
+ }
+ },
+ action: function(args) {
+ $.ajax({
+ url: createURL("revertToVMSnapshot&vmsnapshotid=" + args.context.vmsnapshots[0].id),
+ dataType: "json",
+ async: true,
+ success: function(json) {
+ var jid = json.reverttovmsnapshotresponse.jobid;
+ args.response.success({
+ _custom: {
+ jobId: jid
+ }
+ });
+ }
+ });
- },
- notification: {
- poll: pollAsyncJobResult
+ },
+ notification: {
+ poll: pollAsyncJobResult
+ }
+ }
+ }
}
- }
+ //detailview end
}
- }
- //detailview end
}
- }
})(jQuery, cloudStack);