Skip to content

Instantly share code, notes, and snippets.

@hatched
Created July 10, 2014 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hatched/dbdf85c23eeafb9daa44 to your computer and use it in GitHub Desktop.
Save hatched/dbdf85c23eeafb9daa44 to your computer and use it in GitHub Desktop.
commit 01a5436b73538edbb9537a6db318ac176dec2caa
Author: Jeff Pihach <jeff.pihach@canonical.com>
Date: Wed Jul 9 09:43:53 2014 -0600
Adding manually placed units calls env add_unit method
diff --git a/app/templates/scale-up.handlebars b/app/templates/scale-up.handlebars
index 6ad5de0..740caa7 100644
--- a/app/templates/scale-up.handlebars
+++ b/app/templates/scale-up.handlebars
@@ -4,12 +4,12 @@
<i class="sprite scale-up-open"></i>
</div>
<i class="sprite inspector-units units-icon"></i>
- xx units
+ <span data-bind="unit_count"></span> units
</div>
<div class="placement">
<form>
<span class="units-number-wrap">
- <input class="units-number" type="text" name="units-number" />
+ <input class="units-number" type="text" name="units-number"/>
</span>
<span class="text-in-input">Units</span>
<div class="cancel button inverse">
diff --git a/app/views/viewlets/scale-up.js b/app/views/viewlets/scale-up.js
index 622f507..a67304e 100644
--- a/app/views/viewlets/scale-up.js
+++ b/app/views/viewlets/scale-up.js
@@ -31,6 +31,7 @@ YUI.add('scale-up-view', function(Y) {
'.add.button': { click: '_showScaleUp' },
'.placement .cancel.button': { click: '_hideScaleUp' },
'input[name="placement"]': { change: '_toggleConstraints' },
+ 'form': { submit: '_preventFormSubmit' },
'.edit.link': { click: '_toggleEditConstraints' },
'.inspector-buttons .cancel': { click: '_hideScaleUp' },
'.inspector-buttons .confirm': { click: '_submitScaleUp' }
@@ -49,6 +50,17 @@ YUI.add('scale-up-view', function(Y) {
},
/**
+ This prevents the placement forms from submitting without the user
+ clicking the Confirm button manually.
+
+ @method _preventFormSubmit
+ @param {Object} e Submit event facade.
+ */
+ _preventFormSubmit: function(e) {
+ e.preventDefault();
+ },
+
+ /**
Updates the state class on the viewlet templates container. See
scale-up.less for available classes.
@@ -121,6 +133,22 @@ YUI.add('scale-up-view', function(Y) {
*/
_submitScaleUp: function(e) {
e.preventDefault();
+ var container = this.get('container');
+ var env = this.get('env');
+ var type = container.one('input[name="placement"]:checked').get('id');
+ var numUnits = container.one('input[name="units-number"]').get('value');
+ if (type === 'manually-place') {
+ env.add_unit(
+ this.get('serviceId'), numUnits);
+ } else {
+
+ }
+ }
+
+ }, {
+ ATTRS: {
+ serviceId: {},
+ env: {}
}
});
diff --git a/app/views/viewlets/service-overview.js b/app/views/viewlets/service-overview.js
index 62cb4ff..d81f670 100644
--- a/app/views/viewlets/service-overview.js
+++ b/app/views/viewlets/service-overview.js
@@ -435,7 +435,10 @@ YUI.add('inspector-overview-view', function(Y) {
*/
_instantiateScaleUp: function() {
if (!this.scaleUp) {
- this.scaleUp = new ns.ScaleUp();
+ this.scaleUp = new ns.ScaleUp({
+ env: this.options.env,
+ serviceId: this.viewletManager.get('model').get('id')
+ });
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment