Commit 25388dec by cahrens

Minor cleanup.

parent 2020923f
...@@ -158,24 +158,27 @@ CMS.Views.Metadata.Number = CMS.Views.Metadata.AbstractEditor.extend({ ...@@ -158,24 +158,27 @@ CMS.Views.Metadata.Number = CMS.Views.Metadata.AbstractEditor.extend({
render: function () { render: function () {
CMS.Views.Metadata.AbstractEditor.prototype.render.apply(this); CMS.Views.Metadata.AbstractEditor.prototype.render.apply(this);
if (!this.initialized) { if (!this.initialized) {
var numToString = function (val) {
return val.toFixed(4);
};
var min = "min"; var min = "min";
var max = "max"; var max = "max";
var step = "step"; var step = "step";
var options = this.model.getOptions(); var options = this.model.getOptions();
if (options.hasOwnProperty(min)) { if (options.hasOwnProperty(min)) {
this.min = Number(options[min]); this.min = Number(options[min]);
this.$el.find('input').attr(min, this.min.toFixed(4)); this.$el.find('input').attr(min, numToString(this.min));
} }
if (options.hasOwnProperty(max)) { if (options.hasOwnProperty(max)) {
this.max = Number(options[max]); this.max = Number(options[max]);
this.$el.find('input').attr(max, this.max.toFixed(4)); this.$el.find('input').attr(max, numToString(this.max.toFixed));
} }
var stepValue = undefined; var stepValue = undefined;
if (options.hasOwnProperty(step)) { if (options.hasOwnProperty(step)) {
// Parse step and convert to String. Polyfill doesn't like float values like ".1" (expects "0.1"). // Parse step and convert to String. Polyfill doesn't like float values like ".1" (expects "0.1").
stepValue = Number(options[step]).toFixed(4); stepValue = numToString(Number(options[step]));
} }
else if (this.model.getType() === 'Integer') { else if (this.isIntegerField()) {
stepValue = "1"; stepValue = "1";
} }
if (stepValue !== undefined) { if (stepValue !== undefined) {
...@@ -201,6 +204,10 @@ CMS.Views.Metadata.Number = CMS.Views.Metadata.AbstractEditor.extend({ ...@@ -201,6 +204,10 @@ CMS.Views.Metadata.Number = CMS.Views.Metadata.AbstractEditor.extend({
this.$el.find('input').val(value); this.$el.find('input').val(value);
}, },
isIntegerField : function () {
return this.model.getType() === 'Integer';
},
keyPressed: function (e) { keyPressed: function (e) {
this.showClearButton(); this.showClearButton();
// This first filtering if statement is take from polyfill to prevent // This first filtering if statement is take from polyfill to prevent
...@@ -212,7 +219,7 @@ CMS.Views.Metadata.Number = CMS.Views.Metadata.AbstractEditor.extend({ ...@@ -212,7 +219,7 @@ CMS.Views.Metadata.Number = CMS.Views.Metadata.AbstractEditor.extend({
e.preventDefault(); e.preventDefault();
} }
// For integers, prevent decimal points. // For integers, prevent decimal points.
if (this.model.getType() === 'Integer' && e.keyCode === 46) { if (this.isIntegerField() && e.keyCode === 46) {
e.preventDefault(); e.preventDefault();
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment