SHIMADA Koji
null+****@clear*****
Wed Sep 19 23:40:54 JST 2012
SHIMADA Koji 2012-09-19 23:40:54 +0900 (Wed, 19 Sep 2012) New Revision: 32fb084c7b2ed1169e0039f811bd22a9e0d96289 https://github.com/logaling/logaling-server/commit/32fb084c7b2ed1169e0039f811bd22a9e0d96289 Merged c5d082c: Merge pull request #13 from logaling/enable-creating-user-glossary Log: Enable update term in user glossary Modified files: app/controllers/terms_controller.rb app/models/user_glossary.rb app/views/terms/edit.html.haml app/views/user_glossaries/show.html.haml Modified: app/controllers/terms_controller.rb (+5 -0) =================================================================== --- app/controllers/terms_controller.rb 2012-09-19 23:14:52 +0900 (6ace06b) +++ app/controllers/terms_controller.rb 2012-09-19 23:40:54 +0900 (04fb83e) @@ -17,9 +17,14 @@ class TermsController < ApplicationController end def edit + @term = Term.find(params[:id]) end def update + @term = Term.find(params[:id]) + new_term = Term.new(params[:term]) + @user_glossary.update(@term, new_term) + redirect_to user_glossary_path(current_user, @user_glossary), notice: 'Term was successfully updated.' end def destroy Modified: app/models/user_glossary.rb (+15 -0) =================================================================== --- app/models/user_glossary.rb 2012-09-19 23:14:52 +0900 (3eb2ca7) +++ app/models/user_glossary.rb 2012-09-19 23:40:54 +0900 (b0d4921) @@ -28,6 +28,21 @@ class UserGlossary < ActiveRecord::Base LogalingServer.repository.index end + def update(term, new_term) + project = LogalingServer.repository.find_project(glossary_name) + raise Logaling::ProjectNotFound unless project + raise Logaling::ProjectNotFound if project.class.name == 'Logaling::ImportedProject' + + raise Logaling::TermError unless term.valid? + glossary = project.glossary(source_language, target_language) + unless glossary.bilingual_pair_exists?(term.source_term, term.target_term) + raise Logaling::TermError, "term '#{term.source_term}: #{term.target_term}' doesn't exist in '#{name}'" + end + + glossary.update(term.source_term, term.target_term, new_term.target_term, new_term.note) + LogalingServer.repository.index + end + def delete(term) project = LogalingServer.repository.find_project(glossary_name) raise Logaling::ProjectNotFound unless project Modified: app/views/terms/edit.html.haml (+20 -2) =================================================================== --- app/views/terms/edit.html.haml 2012-09-19 23:14:52 +0900 (a06c814) +++ app/views/terms/edit.html.haml 2012-09-19 23:40:54 +0900 (eaf491c) @@ -1,2 +1,20 @@ -%h1 Terms#edit -%p Find me in app/views/terms/edit.html.haml \ No newline at end of file +%h1 Edit Term += form_for @term, url: user_glossary_term_path(current_user, @user_glossary, @term.id), method: :put do |f| + -if****@term*****? + #error_explanation + %h2= "#{pluralize(@term.errors.count, "error")} prohibited this term from being saved:" + %ul + -****@term*****_messages.each do |msg| + %li= msg + + .well + = f.label :source_term, "Source term:" + = f.text_field :source_term + = f.label :target_term, "Target term:" + = f.text_field :target_term + = f.label :note, "Note:" + = f.text_field :note + + .actions + = f.submit 'Save', :class => 'btn btn-primary' + Modified: app/views/user_glossaries/show.html.haml (+1 -0) =================================================================== --- app/views/user_glossaries/show.html.haml 2012-09-19 23:14:52 +0900 (e827cac) +++ app/views/user_glossaries/show.html.haml 2012-09-19 23:40:54 +0900 (8b530f2) @@ -11,4 +11,5 @@ = term.source_term = term.target_term = term.note + = link_to "Edit", edit_user_glossary_term_path(current_user, @user_glossary, term.id) = link_to "Delete", user_glossary_term_path(current_user, @user_glossary, term.id), method: :delete -------------- next part -------------- An HTML attachment was scrubbed... Download