Permalink
Browse files

Merge commit '5d099fe415996979ceb2deb15e9558e7e6c962f4' into amd-impr…

…ovements

Conflicts:
	distribution/backbone-forms.amd.min.js
	distribution/backbone-forms.min.js
	test/editors/list.js
	test/form.js

Closes #89, closes #77
  • Loading branch information...
1 parent d78524a commit ebfdc6ce4724bdd918106190fcedb049be90f3fd @powmedia committed Jul 26, 2012
View
407 README.md

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -46,6 +46,8 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
dateFormat: 'dd/mm/yy',
showButtonPanel: true
});
+
+ this._observeDatepickerEvents();
//Make sure setValue of this object is called, not of any objects extending it (e.g. DateTime)
exports['jqueryui.Date'].prototype.setValue.call(this, this.value);
@@ -65,6 +67,35 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
setValue: function(value) {
$('input', this.el).datepicker('setDate', value);
+ },
+
+ focus: function() {
+ if (this.hasFocus) return;
+
+ this.$('input').datepicker('show');
+ },
+
+ blur: function() {
+ if (!this.hasFocus) return;
+
+ this.$('input').datepicker('hide');
+ },
+
+ _observeDatepickerEvents: function() {
+ var self = this;
+ this.$('input').datepicker('option', 'onSelect', function() {
+ self.trigger('change', self);
+ })
+ this.$('input').datepicker('option', 'onClose', function() {
+ if (!self.hasFocus) return;
+ self.trigger('blur', self);
+ });
+ this.$('input').datepicker('option', 'beforeShow', function() {
+ if (self.hasFocus) return {};
+ self.trigger('focus', self);
+
+ return {};
+ });
}
});
@@ -107,6 +138,8 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
hours: hoursOptions.join(),
mins: minsOptions.join()
}));
+
+ this._observeDatepickerEvents();
//Store references to selects
this.$hours = $('select:eq(0)', this.el);
@@ -239,6 +272,8 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
text: false,
icons: { primary: 'ui-icon-trash' }
});
+
+ if (this.hasFocus) this.trigger('blur', this);
return this;
},
@@ -271,13 +306,13 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
* Add a new item to the list if it is completed in the editor
*/
addNewItem: function(event) {
- event.preventDefault();
+ if (event) event.preventDefault();
var self = this;
- this.openEditor(null, function(value) {
+ this.openEditor(null, function(value, editor) {
//Fire 'addItem' cancellable event
- triggerCancellableEvent(self, 'addItem', [value], function() {
+ triggerCancellableEvent(self, 'addItem', [value, editor], function() {
var text = self.itemToString(value);
//Create DOM element
@@ -300,6 +335,10 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
text: false,
icons: { primary: 'ui-icon-trash' }
});
+
+ self.trigger('add', self, value);
+ self.trigger('item:change', self, editor);
+ self.trigger('change', self);
});
});
},
@@ -314,14 +353,17 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
li = $(event.target).closest('li'),
originalValue = $.data(li[0], 'data');
- this.openEditor(originalValue, function(newValue) {
+ this.openEditor(originalValue, function(newValue, editor) {
//Fire 'editItem' cancellable event
- triggerCancellableEvent(self, 'editItem', [newValue], function() {
+ triggerCancellableEvent(self, 'editItem', [newValue, editor], function() {
//Update display
$('.bbf-list-text', li).html(self.itemToString(newValue));
//Store data
$.data(li[0], 'data', newValue);
+
+ self.trigger('item:change', self, editor);
+ self.trigger('change', self);
});
});
},
@@ -339,6 +381,9 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
function remove() {
triggerCancellableEvent(self, 'removeItem', [data], function() {
li.remove();
+
+ self.trigger('remove', self, data);
+ self.trigger('change', self);
});
}
@@ -365,24 +410,15 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
value: data
}).render();
- var container = $(this.editorTemplate());
+ var container = this.editorContainer = $(this.editorTemplate());
$('.bbf-list-editor', container).html(editor.el);
- var close = function() {
- $(document).unbind('keydown', handleEnterPressed);
-
- container.dialog('close');
-
- editor.remove();
- container.remove();
- };
-
var saveAndClose = function() {
var errs = editor.validate();
if (errs) return;
- callback(editor.getValue());
- close();
+ callback(editor.getValue(), editor);
+ container.dialog('close');
}
var handleEnterPressed = function(event) {
@@ -398,9 +434,27 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
title: data ? 'Edit item' : 'New item',
buttons: {
'OK': saveAndClose,
- 'Cancel': close
+ 'Cancel': function() {
+ container.dialog('close');
+ }
+ },
+ close: function() {
+ self.editorContainer = null;
+
+ $(document).unbind('keydown', handleEnterPressed);
+
+ editor.remove();
+ container.remove();
+
+ self.trigger('item:close', self, editor);
+ self.trigger('item:blur', self, editor);
+ self.trigger('blur', self);
}
});
+
+ this.trigger('item:open', this, editor);
+ this.trigger('item:focus', this, editor);
+ this.trigger('focus', this);
//Save and close dialog on Enter keypress
$(document).bind('keydown', handleEnterPressed);
@@ -419,6 +473,24 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
setValue: function(value) {
this.value = value;
this.render();
+ },
+
+ focus: function() {
+ if (this.hasFocus) return;
+
+ var item = this.$('li .bbf-list-edit').first();
+ if (item.length > 0) {
+ item.click();
+ }
+ else {
+ this.addNewItem();
+ }
+ },
+
+ blur: function() {
+ if (!this.hasFocus) return;
+
+ if (this.editorContainer) this.editorContainer.dialog('close');
}
});
Oops, something went wrong.

0 comments on commit ebfdc6c

Please sign in to comment.