From 5761e0f7a43418d1749cd2a20ca4f2753381d201 Mon Sep 17 00:00:00 2001 From: Ana Date: Fri, 5 Aug 2016 20:04:26 +0200 Subject: [PATCH] Using flash instead of alerts in the schedule Using flash instead of alerts in the schedule to notify errors. Also, a message shown when a schedule is successfully created. --- app/assets/javascripts/application.js | 2 +- app/assets/javascripts/osem-schedule.js | 13 +++++++++---- app/assets/javascripts/osem-switch.js | 2 +- app/controllers/admin/event_schedules_controller.rb | 6 +++--- app/controllers/admin/programs_controller.rb | 2 +- app/controllers/admin/schedules_controller.rb | 3 ++- app/views/admin/schedules/show.html.haml | 2 ++ 7 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 14c70269..995af428 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -37,12 +37,12 @@ //= require osem-datatables //= require osem-tickets //= require bootstrap-switch +//= require osem-schedule //= require osem-switch //= require osem-bootstrap //= require osem-commercials //= require unobtrusive_flash //= require unobtrusive_flash_bootstrap -//= require osem-schedule $(document).ready(function() { $('a[disabled=disabled]').click(function(event){ diff --git a/app/assets/javascripts/osem-schedule.js b/app/assets/javascripts/osem-schedule.js index 85018aaa..80b38bc8 100644 --- a/app/assets/javascripts/osem-schedule.js +++ b/app/assets/javascripts/osem-schedule.js @@ -1,7 +1,12 @@ var url; // Should be initialize in Schedule.initialize var schedule_id; // Should be initialize in Schedule.initialize -var error_remove = "The event couldn't be unscheduled"; +function showError(error){ + // Delete other error messages before showing the new one + $('.unobtrusive-flash-container').empty(); + UnobtrusiveFlash.showFlashMessage(error, {type: 'error'}); +} + var Schedule = { initialize: function(url_param, schedule_id_param) { url = url_param; @@ -20,7 +25,7 @@ var Schedule = { e.find(".schedule-event-delete-button").hide(); } else{ - alert(error_remove); + showError(data.status); } } $.ajax({ @@ -31,7 +36,7 @@ var Schedule = { }); } else{ - alert(error_remove); + showError("The event couldn't be unscheduled"); } }, add: function (previous_parent, new_parent, event) { @@ -57,7 +62,7 @@ var Schedule = { } else{ event.appendTo(previous_parent); - alert("The event couldn't been scheduled"); + showError("The event couldn't been scheduled"); } } $.ajax({ diff --git a/app/assets/javascripts/osem-switch.js b/app/assets/javascripts/osem-switch.js index 7b97589f..e2d2c405 100644 --- a/app/assets/javascripts/osem-switch.js +++ b/app/assets/javascripts/osem-switch.js @@ -24,7 +24,7 @@ $(function () { var callback = function(data) { if(data.status != 'ok'){ - alert("The schedule couldn't been updated"); + showError(data.status); } } $.ajax({ diff --git a/app/controllers/admin/event_schedules_controller.rb b/app/controllers/admin/event_schedules_controller.rb index 739e3f58..ad7b89ff 100644 --- a/app/controllers/admin/event_schedules_controller.rb +++ b/app/controllers/admin/event_schedules_controller.rb @@ -6,7 +6,7 @@ module Admin if @event_schedule.save render json: { 'status' => 'ok', event_schedule_id: @event_schedule.id } else - render json: { 'status' => 'error' } + render json: { 'status' => "The event couldn't be scheduled" } end end @@ -14,7 +14,7 @@ module Admin if @event_schedule.update(event_schedule_params) render json: { 'status' => 'ok', event_schedule_id: @event_schedule.id } else - render json: { 'status' => 'error' } + render json: { 'status' => "The event couldn't be scheduled" } end end @@ -22,7 +22,7 @@ module Admin if @event_schedule.destroy render json: { 'status' => 'ok' } else - render json: { 'status' => 'error' } + render json: { 'status' => "The event couldn't be unscheduled" } end end diff --git a/app/controllers/admin/programs_controller.rb b/app/controllers/admin/programs_controller.rb index 64abee65..409cd3da 100644 --- a/app/controllers/admin/programs_controller.rb +++ b/app/controllers/admin/programs_controller.rb @@ -26,7 +26,7 @@ module Admin flash[:error] = "Updating program failed. #{@program.errors.to_a.join('. ')}." render :new end - format.js { render json: { 'status' => 'error' } } + format.js { render json: { 'status' => "The selected schedule couldn't been updated" } } end end end diff --git a/app/controllers/admin/schedules_controller.rb b/app/controllers/admin/schedules_controller.rb index ffb4feb1..74706575 100644 --- a/app/controllers/admin/schedules_controller.rb +++ b/app/controllers/admin/schedules_controller.rb @@ -13,7 +13,8 @@ module Admin def create if @schedule.save - redirect_to action: 'show', id: @schedule.id + redirect_to admin_conference_schedule_path(@conference.short_title, @schedule.id), + notice: 'Schedule was successfully created.' else redirect_to admin_conference_schedules_path(conference_id: @conference.short_title), error: 'Could not create schedule' diff --git a/app/views/admin/schedules/show.html.haml b/app/views/admin/schedules/show.html.haml index 70cf158e..d4233224 100644 --- a/app/views/admin/schedules/show.html.haml +++ b/app/views/admin/schedules/show.html.haml @@ -1,3 +1,5 @@ +.unobtrusive-flash-container + .row .col-md-12 .page-header