+
+
+var AbstractDialog = Class.extend({
+ _className: 'AbstractDialog',
+
+ init: function($element, modal, overlay)
+ {
+ this.$window = $element;
+ this.$window.jqm({
+ modal: modal || true,
+ overlay: overlay || 80,
+ // toTop: true,
+ onShow: this.onShow.bind(this),
+ onHide: this.onHide.bind(this)
+ });
+
+ this.reset();
+
+ $('.cancel-button', this.$window).click(this.cancel.bind(this));
+ $('.save-button', this.$window).click(this.accept.bind(this));
+ },
+
+ onShow: function(hash)
+ {
+ hash.w.show();
+ },
+
+ onHide: function(hash)
+ {
+ hash.w.hide();
+ hash.o.remove();
+ },
+
+ reset: function() {
+ this.acceptCallback = null;
+ this.cancelCallback = null;
+ this.errors = [];
+
+ $('.error-messages-box', this.$window).html('').hide();
+
+ this.userData = {};
+ },
+
+ show: function(acall, ccall) {
+ this.acceptCallback = acall;
+ this.cancelCallback = ccall;
+
+ // do the show
+ this.$window.jqmShow();
+ },
+
+ cancel: function() {
+ this.$window.jqmHide();
+ if(this.cancelCallback) this.cancelCallback(this);
+ this.reset();
+ },
+
+ accept: function()
+ {
+ this.errors = [];
+
+ if(!this.validate()) {
+ this.displayErrors();
+ return;
+ }
+
+ this.$window.jqmHide();
+
+ if(this.acceptCallback)
+ this.acceptCallback(this);
+
+ this.reset();
+ },
+
+ validate: function() {
+ return true;
+ },
+
+ displayErrors: function() {
+ var errorDiv = $('.error-messages-box', this.$window);
+ if(errorDiv.length > 0) {
+ var html = '';
+ $.each(this.errors, function() {
+ html += '<li>' + this + '</li>';
+ });
+ errorDiv.html('<ul>' + html + '</ul>');
+ errorDiv.show();
+ console.log('Validation errors:', html);
+ }
+ else
+ throw this.errors;
+ }
+
+});
+
+var CommitDialog = AbstractDialog.extend({
+ _className: 'CommitDialog',
+
+ validate: function()
+ {
+ var message = $('textarea.commit-message', this.$window).val();
+
+ if( message.match(/^\s*$/) ) {
+ this.errors.push("Message can't be empty.");
+ return false;
+ }
+
+ // append refs
+ $('.related-issues-fields input:checked', this.$window).each(function() {
+ message += ' refs #' + $(this).val();
+ });
+
+ this.userData.message = message;
+ return this._super();
+ }
+ });
+
+
\ No newline at end of file