Class: LabelsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- LabelsController
- Defined in:
- app/controllers/labels_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/labels_controller.rb', line 58 def create :create, Iqvoc::XLLabel.base_class @label = Iqvoc::XLLabel.base_class.new(label_params) @label.lock_by_user(current_user.id) if @label.valid? if @label.save flash[:success] = I18n.t('txt.controllers.versioned_label.success') redirect_to label_path(published: 0, id: @label.origin) else flash.now[:error] = I18n.t('txt.controllers.versioned_label.error') render :new end else flash.now[:error] = I18n.t('txt.controllers.versioned_label.error') render :new end end |
#destroy ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/controllers/labels_controller.rb', line 118 def destroy @new_label = Iqvoc::XLLabel.base_class.by_origin(params[:id]).unpublished.last! :destroy, @new_label if @new_label.destroy flash[:success] = I18n.t('txt.controllers.label_versions.delete') redirect_to dashboard_path else flash[:error] = I18n.t('txt.controllers.label_versions.delete_error') redirect_to label_path(published: 0, id: @new_label) end end |
#edit ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/controllers/labels_controller.rb', line 78 def edit @label = Iqvoc::XLLabel.base_class.by_origin(params[:id]).unpublished.last! :update, @label if params[:check_associations_in_editing_mode] @association_objects_in_editing_mode = @label.associated_objects_in_editing_mode end # @pref_labelings = PrefLabeling.by_label(@label).all(:include => {:owner => :pref_labels}).sort # @alt_labelings = AltLabeling.by_label(@label).all(:include => {:owner => :pref_labels}).sort if params[:full_consistency_check] @label.publishable? end Iqvoc::XLLabel.note_class_names.each do |note_class_name| @label.send(note_class_name.to_relation_name).build if @label.send(note_class_name.to_relation_name).empty? end end |
#index ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/labels_controller.rb', line 4 def index :read, Iqvoc::XLLabel.base_class scope = Iqvoc::XLLabel.base_class.by_query_value("#{params[:query]}%") if params[:language] # NB: this is not the same as :lang, which is supplied via route scope = scope.by_language(params[:language]) end @labels = scope.published.order('LOWER(value)').all respond_to do |format| format.html do redirect_to action: 'index', format: 'txt' end format.text do render content_type: 'text/plain', text: @labels.map { |label| "#{label.origin}: #{label.value}" }.join("\n") end format.json do response = [] @labels.each { |label| response << (label) } render json: response end end end |
#new ⇒ Object
53 54 55 56 |
# File 'app/controllers/labels_controller.rb', line 53 def new :create, Iqvoc::XLLabel.base_class @label = Iqvoc::XLLabel.base_class.new end |
#show ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/labels_controller.rb', line 30 def show scope = Iqvoc::XLLabel.base_class.by_origin(params[:id]).with_associations @published = params[:published] == '1' || !params[:published] if @published scope = scope.published @new_label_version = Iqvoc::XLLabel.base_class.by_origin(params[:id]).unpublished.last else scope = scope.unpublished end @label = scope.last! :read, @label respond_to do |format| format.html do @published ? render('show_published') : render('show_unpublished') end format.ttl end end |
#update ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/controllers/labels_controller.rb', line 98 def update @label = Iqvoc::XLLabel.base_class.by_origin(params[:id]).unpublished.last! :update, @label # set to_review to false if someone edits a label label_params["to_review"] = "false" respond_to do |format| format.html do if @label.update_attributes(label_params) flash[:success] = I18n.t('txt.controllers.versioned_label.update_success') redirect_to label_path(published: 0, id: @label) else flash.now[:error] = I18n.t('txt.controllers.versioned_label.update_error') render action: :edit end end end end |