From a01315e30dd20fc489f0b2536070163ff3f4069c Mon Sep 17 00:00:00 2001 From: Mark Maglana Date: Wed, 4 Aug 2010 23:28:49 +0800 Subject: [PATCH] Implement sprint date validation in the client --- app/controllers/backlogs_controller.rb | 6 +++++- app/models/sprint.rb | 5 +++-- app/views/shared/_validation_errors.html.erb | 7 +++++++ assets/javascripts/backlog.js | 13 +++++++++++-- assets/javascripts/common.js | 6 +++--- assets/stylesheets/index.css | 6 +++++- config/locales/en.yml | 6 +++++- 7 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 app/views/shared/_validation_errors.html.erb diff --git a/app/controllers/backlogs_controller.rb b/app/controllers/backlogs_controller.rb index b6e5339493..d17d34f8a5 100755 --- a/app/controllers/backlogs_controller.rb +++ b/app/controllers/backlogs_controller.rb @@ -173,7 +173,11 @@ class BacklogsController < ApplicationController attribs = params.select{|k,v| k != 'id' and Sprint.column_names.include? k } attribs = Hash[*attribs.flatten] result = sprint.update_attributes attribs - render :text => result, :status => (result ? 200 : 400) + if result + render :text => 'successfully updated sprint', :status => 200 + else + render :partial => 'shared/validation_errors', :object => sprint.errors, :status => 400 + end end def wiki_page diff --git a/app/models/sprint.rb b/app/models/sprint.rb index afd7dad978..4cbb5e0cc2 100755 --- a/app/models/sprint.rb +++ b/app/models/sprint.rb @@ -170,8 +170,9 @@ end class Sprint < Version unloadable - validate :correctness - def correctness + validate :start_and_end_dates + + def start_and_end_dates errors.add_to_base("Sprint cannot end before it starts") if self.effective_date && self.sprint_start_date && self.sprint_start_date >= self.effective_date end diff --git a/app/views/shared/_validation_errors.html.erb b/app/views/shared/_validation_errors.html.erb new file mode 100644 index 0000000000..1043304017 --- /dev/null +++ b/app/views/shared/_validation_errors.html.erb @@ -0,0 +1,7 @@ +<%= validation_errors.length > 1 ? l(:error_intro_plural) : l(:error_intro_singular) %> + +<%= l(:error_outro ) %> \ No newline at end of file diff --git a/assets/javascripts/backlog.js b/assets/javascripts/backlog.js index c5ed225a08..9fe03bdefe 100755 --- a/assets/javascripts/backlog.js +++ b/assets/javascripts/backlog.js @@ -184,6 +184,10 @@ RB.Backlog = RB.Object.create(RB.Model, { }); }, + markError: function(){ + this.$.addClass('error'); + }, + markSaving: function(){ this.$.addClass('saving'); }, @@ -235,8 +239,9 @@ RB.Backlog = RB.Object.create(RB.Model, { type: "POST", url: RB.urlFor['update_backlog'], data: editors.serialize() + "&id=" + j.find('.id').text(), - beforeSend: function(xhr){ me.markSaving() }, - complete: function(xhr, textStatus){ me.unmarkSaving(); /* RB.dialog.msg(xhr.responseText) */ } + beforeSend: function(xhr){ me.unmarkError(); me.markSaving() }, + success: function(d,t,x){ me.unmarkSaving(); me.unmarkError() }, + error: function(x,t,e){ RB.Dialog.msg(x.responseText); me.markError() } }); me.endEdit(); }, @@ -253,6 +258,10 @@ RB.Backlog = RB.Object.create(RB.Model, { width: 710 }); }, + + unmarkError: function(){ + this.$.removeClass('error'); + }, unmarkSaving: function(){ this.$.removeClass('saving'); diff --git a/assets/javascripts/common.js b/assets/javascripts/common.js index f1e7670dec..12086f0657 100755 --- a/assets/javascripts/common.js +++ b/assets/javascripts/common.js @@ -35,9 +35,9 @@ RB.Model = RB.Object.create({}); RB.Dialog = RB.Object.create({ msg: function(msg){ dialog = $('#msgBox').size()==0 ? $(document.createElement('div')).attr('id', 'msgBox').appendTo('#content') : $('#msgBox'); - dialog.text(msg); - dialog.dialog({ title: 'Backlog Plugin', - buttons: { "Ok": function() { $(this).dialog("close"); } }, + dialog.html(msg); + dialog.dialog({ title: 'Backlogs Plugin', + buttons: { "OK": function() { $(this).dialog("close"); } }, modal: true }); }, diff --git a/assets/stylesheets/index.css b/assets/stylesheets/index.css index 277d94fc23..239f8bd45f 100755 --- a/assets/stylesheets/index.css +++ b/assets/stylesheets/index.css @@ -27,9 +27,13 @@ top:8px; width:16px; } -.backlog.saving .header .pureCssMenu{ +.backlog.saving .header .pureCssMenu, +.backlog.error .header .pureCssMenu{ display:none; } +.backlog.error .header .spinner{ + background-image:url('../images/warning.png'); +} .backlog .header .name{ font-size:14px; font-weight:bold; diff --git a/config/locales/en.yml b/config/locales/en.yml index ba98aa101e..5e9f70e1ec 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -72,4 +72,8 @@ en: todo_issue_summary: "{{type}}: {{summary}}" todo_issue_description: "{{summary}}: {{url}}\n{{description}}" - label_chart_options: "Chart Options" \ No newline at end of file + label_chart_options: "Chart Options" + + error_intro_singular: "The following error was encountered:" + error_intro_plural: "The following errors were encountered:" + error_outro: "Please correct the above errors before submitting again." \ No newline at end of file