From 1632e5479ea30dba3453706fedfa3bd9e5b4f613 Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 26 Aug 2014 12:10:45 +0200 Subject: [PATCH] wp update looks for optional back url after update. --- .../controllers/work-packages-list-controller.js | 5 +---- .../work-package-details-toolbar-directive.js | 3 ++- app/controllers/work_packages_controller.rb | 13 +++++++++++-- app/views/work_packages/_edit.html.erb | 1 + app/views/work_packages/edit.html.erb | 3 ++- public/templates/work_packages.list.details.html | 4 +++- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/angular/work_packages/controllers/work-packages-list-controller.js b/app/assets/javascripts/angular/work_packages/controllers/work-packages-list-controller.js index be6da7efe2..bdb63358df 100644 --- a/app/assets/javascripts/angular/work_packages/controllers/work-packages-list-controller.js +++ b/app/assets/javascripts/angular/work_packages/controllers/work-packages-list-controller.js @@ -188,10 +188,7 @@ angular.module('openproject.workPackages.controllers') // Updates $scope.maintainUrlQueryState = function(){ - var relativeUrl = "/work_packages"; - if ($scope.projectIdentifier){ - relativeUrl = "/projects/" + $scope.projectIdentifier + relativeUrl; - } + var relativeUrl = decodeURIComponent($state.href($state.$current)); // ui-router escapes some of this string for whatever reason if($scope.query) { var queryString = UrlParamsHelper.encodeQueryJsonParams($scope.query); diff --git a/app/assets/javascripts/angular/work_packages/directives/work-package-details-toolbar-directive.js b/app/assets/javascripts/angular/work_packages/directives/work-package-details-toolbar-directive.js index a2be29c73b..d3eaa23404 100644 --- a/app/assets/javascripts/angular/work_packages/directives/work-package-details-toolbar-directive.js +++ b/app/assets/javascripts/angular/work_packages/directives/work-package-details-toolbar-directive.js @@ -89,6 +89,7 @@ angular.module('openproject.workPackages.directives') templateUrl: '/templates/work_packages/work_package_details_toolbar.html', scope: { workPackage: '=', + backUrl: '=' }, link: function(scope, element, attributes) { var authorization = new WorkPackageAuthorization(scope.workPackage); @@ -100,7 +101,7 @@ angular.module('openproject.workPackages.directives') scope.editWorkPackage = function() { // TODO: Temporarily going to the old edit dialog until we get in-place editing done - window.location = PathHelper.staticEditWorkPackagePath(scope.workPackage.props.id); + window.location = PathHelper.staticEditWorkPackagePath(scope.workPackage.props.id) + '?back_url=' + encodeURIComponent(scope.backUrl); }; scope.triggerMoreMenuAction = function(action, link) { diff --git a/app/controllers/work_packages_controller.rb b/app/controllers/work_packages_controller.rb index 8fc132ad72..69ea62cff3 100644 --- a/app/controllers/work_packages_controller.rb +++ b/app/controllers/work_packages_controller.rb @@ -159,7 +159,8 @@ class WorkPackagesController < ApplicationController :project => project, :priorities => priorities, :time_entry => time_entry, - :user => current_user } + :user => current_user, + :back_url => params[:back_url] } respond_to do |format| format.html do @@ -184,7 +185,7 @@ class WorkPackagesController < ApplicationController flash[:notice] = l(:notice_successful_update) - redirect_to(work_package_path(work_package)) + redirect_to_back_url_or_work_package(work_package) else edit end @@ -438,6 +439,14 @@ class WorkPackagesController < ApplicationController private + def redirect_to_back_url_or_work_package(work_package) + if !params[:back_url].blank? + redirect_to(params[:back_url]) + else + redirect_to(work_package_path(work_package)) + end + end + def load_work_packages sort_init(@query.sort_criteria.empty? ? [DEFAULT_SORT_ORDER] : @query.sort_criteria) sort_update(@query.sortable_columns) diff --git a/app/views/work_packages/_edit.html.erb b/app/views/work_packages/_edit.html.erb index e1aeca65f3..cb848d0b50 100644 --- a/app/views/work_packages/_edit.html.erb +++ b/app/views/work_packages/_edit.html.erb @@ -36,6 +36,7 @@ See doc/COPYRIGHT.rdoc for more details. :multipart => true } do |f| %> + <%= hidden_field_tag 'back_url', back_url %> <%= error_messages_for work_package %> <% if edit_allowed || !allowed_statuses.empty? %> diff --git a/app/views/work_packages/edit.html.erb b/app/views/work_packages/edit.html.erb index e4fa9c3723..653203fec9 100644 --- a/app/views/work_packages/edit.html.erb +++ b/app/views/work_packages/edit.html.erb @@ -36,7 +36,8 @@ See doc/COPYRIGHT.rdoc for more details. :project => project, :priorities => priorities, :time_entry => time_entry, - :user => user } %> + :user => user, + :back_url => back_url } %> <% content_for :header_tags do %> <%= robot_exclusion_tag %> <% end %> diff --git a/public/templates/work_packages.list.details.html b/public/templates/work_packages.list.details.html index bad1ba54a5..cede62040a 100644 --- a/public/templates/work_packages.list.details.html +++ b/public/templates/work_packages.list.details.html @@ -47,5 +47,7 @@
- + +