[#356] fix changing the update type of the build list

This commit is contained in:
Alexander Machehin 2014-02-19 14:24:15 +06:00
parent 782eef0664
commit bbaa67d674
4 changed files with 43 additions and 7 deletions

View File

@ -10,6 +10,7 @@ RosaABF.controller('BuildListController', ['$scope', '$http', '$timeout', 'Sound
$scope.search_status = 'continue_input';
$scope.term = '';
$scope.advisory = null;
$scope.update_type_errors = null;
$scope.getBuildList = function() {
$http.get(Routes.build_list_path($scope.id, {format: 'json'})).success(function(results) {
@ -60,13 +61,28 @@ RosaABF.controller('BuildListController', ['$scope', '$http', '$timeout', 'Sound
} else {
$scope.attach_advisory = 'no';
}
$scope.updateUpdateType();
}
$scope.attachAdvisoryChanged = function() {
if (!_.contains($scope.advisoriable_types, $scope.build_list.update_type)) {
$scope.build_list.update_type = $scope.advisoriable_types[0];
$scope.updateUpdateType();
}
$('#build_list_update_type .nonadvisoriable').attr('disabled', ($scope.attach_advisory != 'no'));
}
$scope.updateUpdateType = function() {
$http.put(
Routes.update_type_build_list_path($scope.id),
{update_type: $scope.build_list.update_type, format: 'json'}
).success(function(results) {
$scope.update_type_errors = null;
$timeout(function() {
$('#build_list_update_type').effect('highlight', {}, 1000);
}, 100);
}).error(function(data, status, headers, config) {
$scope.update_type_errors = data.message;
});
}
}]);

View File

@ -166,6 +166,20 @@ class Projects::BuildListsController < Projects::BaseController
render partial: 'build_lists_ajax', layout: false
end
def update_type
respond_to do |format|
format.html { render nothing: true }
format.json do
@build_list.update_type = params[:update_type]
if @build_list.save
render json: 'success', status: :ok
else
render json: { message: @build_list.errors.full_messages.join('. ') },
status: :unprocessable_entity
end
end
end
end
protected

View File

@ -51,6 +51,11 @@
@build_list.update_type), {}, 'ng-model' => 'build_list.update_type',
'ng-change' => 'updateTypeChanged()', 'ng-show' => 'build_list.can_publish'
%div{'ng-hide' => 'build_list.can_publish'}= @build_list.update_type
.ng-hide{ 'ng-show' => 'update_type_errors' }
.flash_notify
.alert{ 'ng-class' => "{ 'alert-error': update_type_errors }" }
{{ update_type_errors }}
.both
.both
.leftlist= t("activerecord.attributes.build_list.auto_publish")
.rightlist= t("layout.#{@build_list.auto_publish}_")

View File

@ -282,6 +282,7 @@ Rosa::Application.routes.draw do
put :publish
put :reject_publish
put :publish_into_testing
put :update_type
end
end