From 16ebeedef225db60e1f62d43e5152a04c29fd289 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Fri, 26 Dec 2014 15:37:04 +0100 Subject: [PATCH] Update branch status with ajax call. --- .../javascripts/protected_branches.js.coffee | 19 +++++++++++++++++++ .../projects/protected_branches_controller.rb | 13 +++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 app/assets/javascripts/protected_branches.js.coffee diff --git a/app/assets/javascripts/protected_branches.js.coffee b/app/assets/javascripts/protected_branches.js.coffee new file mode 100644 index 0000000000..e03bd148dc --- /dev/null +++ b/app/assets/javascripts/protected_branches.js.coffee @@ -0,0 +1,19 @@ +$ -> + $(":checkbox").change -> + id = $(this).val() + checked = $(this).is(":checked") + url = $(this).data("url") + $.ajax + type: "PUT" + url: url + dataType: "json" + data: + id: id + developers_can_push: checked + + success: -> + new Flash("Branch updated.", "notice") + location.reload true + + error: -> + new Flash("Failed to update branch!", "alert") diff --git a/app/controllers/projects/protected_branches_controller.rb b/app/controllers/projects/protected_branches_controller.rb index ac68992faa..02160d973b 100644 --- a/app/controllers/projects/protected_branches_controller.rb +++ b/app/controllers/projects/protected_branches_controller.rb @@ -22,13 +22,14 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController protected_branch.update_attributes( developers_can_push: params[:developers_can_push] ) - flash[:notice] = 'Branch was successfully updated.' - else - flash[:alert] = 'Could not update the branch.' - end - respond_to do |format| - format.html { redirect_to project_protected_branches_path } + respond_to do |format| + format.json { render :json => protected_branch, status: :ok } + end + else + respond_to do |format| + format.json { render json: protected_branch.errors, status: :unprocessable_entity } + end end end