Skip to content

Commit

Permalink
Revert "In backlog, transitions of state restricted to only those all…
Browse files Browse the repository at this point in the history
…owed by workflows."

This reverts commit 00b7cf6.
  • Loading branch information
maser committed Apr 15, 2011
1 parent 115baee commit c90e697
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 75 deletions.
15 changes: 0 additions & 15 deletions app/controllers/rb_stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,4 @@ def update
end
end


def transitions
transitions = Hash.new
@project.trackers.each do |tid|
tracker = Tracker.find_by_id(tid)
transitions[tracker.id] = Hash.new
IssueStatus.find(:all, :order => "position ASC").each do |status|
allowed = status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), tracker)
to = transitions[tracker.id]["from-#{status.id}"] = allowed << status
end
end
respond_to do |format|
format.json { render :json => transitions }
end
end
end
12 changes: 3 additions & 9 deletions app/views/rb_server_variables/show.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ RB.constants = {
sprint_id: <%= @sprint ? @sprint.id : "null" %>,
protect_against_forgery: <%= protect_against_forgery? ? "true" : "false" %>,
request_forgery_protection_token: '<%= request_forgery_protection_token %>',
form_authenticity_token: '<%= form_authenticity_token %>',
transitions: {}
form_authenticity_token: '<%= form_authenticity_token %>'
}
$.getJSON("/rb/transitions/" + RB.constants.project_id, function(data) {
RB.constants.transitions = data
});


RB.buildImageTag = function(name){
return "<img src='<%= Engines::RailsExtensions::AssetHelpers.plugin_asset_path('redmine_backlogs', 'images', nil) %>" + name + "'/>"
Expand All @@ -29,10 +24,10 @@ RB.urlFor = function(route_name, options){

RB.routes = {
update_sprint: '<%= url_for(:controller => 'rb_sprints', :action => 'update', :sprint_id => ":id") %>',

create_story: '<%= url_for(:controller => 'rb_stories', :action => 'create') %>',
update_story: '<%= url_for(:controller => 'rb_stories', :action => 'update', :id => ":id") %>',

create_task: '<%= url_for(:controller => 'rb_tasks', :action => 'create') %>',
update_task: '<%= url_for(:controller => 'rb_tasks', :action => 'update', :id => ":id") %>',

Expand All @@ -44,4 +39,3 @@ RB.routes = {
}

if(typeof console != "undefined" && console != null) console.log('*** server variables loaded ***');

77 changes: 30 additions & 47 deletions assets/javascripts/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RB.Model = RB.Object.create({
initialize: function(el){
var j; // This ensures that we use a local 'j' variable, not a global one.
var self = this;

this.$ = j = $(el);
this.el = el;
},
Expand All @@ -30,7 +30,7 @@ RB.Model = RB.Object.create({
this.afterUpdate(data, textStatus, xhr);
}
},

afterUpdate: function(data, textStatus, xhr){
// Do nothing. Child objects may optionally override this
},
Expand All @@ -45,7 +45,7 @@ RB.Model = RB.Object.create({
this.$.hide('blind');
}
},

close: function(){
this.$.addClass('closed');
},
Expand All @@ -60,7 +60,7 @@ RB.Model = RB.Object.create({
displayEditor: function(editor){
var pos = this.$.offset();
var self = this;

editor.dialog({
buttons: {
"Cancel" : function(){ self.cancelEdit(); $(this).dialog("close") },
Expand All @@ -78,16 +78,16 @@ RB.Model = RB.Object.create({

edit: function(){
var editor = this.getEditor();

// 'this' can change below depending on the context.
var self = this;

this.$.find('.editable').each(function(index){
var field = $(this);
var fieldType = field.attr('fieldtype')!=null ? field.attr('fieldtype') : 'input';
var fieldName = field.attr('fieldname');
var input;

$(document.createElement("label")).text(fieldName.replace(/_/ig, " ").replace(/ id$/ig,"")).appendTo(editor);
input = fieldType=='select' ? $('#' + fieldName + '_options').clone(true) : $(document.createElement(fieldType));
input.removeAttr('id');
Expand All @@ -101,7 +101,7 @@ RB.Model = RB.Object.create({
input.datepicker({ changeMonth: true,
changeYear: true,
closeText: 'Close',
dateFormat: 'yy-mm-dd',
dateFormat: 'yy-mm-dd',
firstDay: 1,
onClose: function(){ $(this).focus() },
selectOtherMonths: true,
Expand All @@ -112,60 +112,44 @@ RB.Model = RB.Object.create({
// So that we won't need a datepicker button to re-show it
input.bind('mouseup', function(event){ $(this).datepicker("show") });
}

// Copy the value in the field to the input element
value = ( fieldType=='select' ? field.children('.v').first().text() : field.text() );
input.val(value);

// Record in the model's root element which input field had the last focus. We will
// use this information inside RB.Model.refresh() to determine where to return the
// focus after the element has been refreshed with info from the server.
input.focus( function(){ self.$.data('focus', $(this).attr('name')) } )
.blur( function(){ self.$.data('focus', '') } );

if ( fieldType=='select' && fieldName == 'status_id' ) {
story_id = field.parents('.model').first().attr('id').replace('story_','')
tracker_id = field.parents('.model').find('.tracker_id').first().children('.v').text()
status_id = field.children('.v').first().text()
status_name = field.children('.t').first().text()
transitions = RB.constants.transitions[tracker_id]['from-'+status_id]
input.html("");
used = new Array();
for (i=0; i<transitions.length; i++) {
if (used[transitions[i]] == null) {
selected = (status_id==transitions[i].id)?'selected="true"':'';
input.append('<option '+selected+' value="'+transitions[i].id+'">'+transitions[i].name+'</option>');
used[transitions[i].id] = true;
}
}
}

input.appendTo(editor);
});

this.displayEditor(editor);
this.editorDisplayed(editor);
return editor;
},

// Override this method to change the dialog title
editDialogTitle: function(){
return "Edit " + this.getType()
},

editorDisplayed: function(editor){
// Do nothing. Child objects may override this.
},

endEdit: function(){
this.$.removeClass('editing');
},

error: function(xhr, textStatus, error){
this.markError();
RB.Dialog.msg($(xhr.responseText).find('.errors').html());
this.processError(xhr, textStatus, error);
},

getEditor: function(){
// Create the model editor if it does not yet exist
var editor_id = this.getType().toLowerCase() + "_editor";
Expand All @@ -177,15 +161,15 @@ RB.Model = RB.Object.create({
}
return editor;
},

getID: function(){
return this.$.children('.id').children('.v').text();
},

getType: function(){
throw "Child objects must override getType()";
},

handleClick: function(event){
var field = $(this);
var model = field.parents('.model').first().data('this');
Expand All @@ -200,7 +184,7 @@ RB.Model = RB.Object.create({
var j = $(this);
var self = j.data('this');

if(!$(event.target).hasClass('editable') &&
if(!$(event.target).hasClass('editable') &&
!$(event.target).hasClass('checkbox') &&
!j.hasClass('editing') &&
event.target.tagName!='A' &&
Expand All @@ -212,19 +196,19 @@ RB.Model = RB.Object.create({
isClosed: function(){
return this.$.hasClass('closed');
},

isNew: function(){
return this.getID()=="";
},

markError: function(){
this.$.addClass('error');
},

markIfClosed: function(){
throw "Child objects must override markIfClosed()";
},

markSaving: function(){
this.$.addClass('saving');
},
Expand All @@ -233,7 +217,7 @@ RB.Model = RB.Object.create({
newDialogTitle: function(){
return "New " + this.getType()
},

open: function(){
this.$.removeClass('closed');
},
Expand All @@ -244,15 +228,15 @@ RB.Model = RB.Object.create({

refresh: function(obj){
this.$.html(obj.$.html());

if(obj.isClosed()){
this.close();
} else {
this.open();
}
this.refreshed();
},

refreshed: function(){
// Override as needed
},
Expand All @@ -265,7 +249,7 @@ RB.Model = RB.Object.create({
var j = this.$;
var self = this;
var editors = j.find('.editor');

// Copy the values from the fields to the proper html elements
editors.each(function(index){
editor = $(this);
Expand Down Expand Up @@ -300,14 +284,13 @@ RB.Model = RB.Object.create({
});
self.endEdit();
},

unmarkError: function(){
this.$.removeClass('error');
},

unmarkSaving: function(){
this.$.removeClass('saving');
}

});

});
2 changes: 0 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
rb.resources :release, :only => :destroy, :controller => :rb_releases, :as => "release/:release_id"
rb.resources :releases, :only => :index, :controller => :rb_releases, :as => "releases/:project_id"
rb.resources :releases, :only => :snapshot, :controller => :rb_releases, :as => "releases/:project_id"
rb.connect "transitions/:project_id", :controller => :rb_stories, :action => 'transitions'
end

end

3 changes: 1 addition & 2 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@
# Story permissions
# :show_stories and :list_stories are implicit in :view_master_backlog permission
permission :create_stories, { :rb_stories => :create }
permission :update_stories, { :rb_stories => [:update, :transitions] }

permission :update_stories, { :rb_stories => :update }

# Task permissions
# :show_tasks and :list_tasks are implicit in :view_sprints
Expand Down

0 comments on commit c90e697

Please sign in to comment.