Revision 1077:9b5b4e7970cd vendor/plugins/redmine_bibliography/app/controllers

View differences:

vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb
5 5
  unloadable
6 6

  
7 7
  model_object Publication
8
  before_filter :find_model_object, :except => [:new, :create, :index, :get_bibtex_required_fields, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ]  
8
  before_filter :find_model_object, :except => [:new, :create, :index, :get_bibtex_required_fields, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ]
9 9
  before_filter :find_project_by_project_id, :authorize, :only => [ :edit, :new, :update, :create ]
10 10

  
11 11
  def new
......
16 16
    @publication.build_bibtex_entry
17 17

  
18 18
    # and at least one author
19
    # @publication.authorships.build.build_author        
19
    # @publication.authorships.build.build_author
20 20
    @author_options = [["#{User.current.name} (@#{User.current.mail.partition('@')[2]})", "#{User.current.class.to_s}_#{User.current.id.to_s}"]]
21

  
22

  
23 21
  end
24 22

  
25
  def create    
23
  def create
26 24
    @project = Project.find(params[:project_id])
27 25

  
28 26
    @author_options = []
......
30 28
    @publication = Publication.new(params[:publication])
31 29
    @publication.projects << @project unless @project.nil?
32 30

  
33
    if @publication.save 
31
    if @publication.save
34 32
      @publication.notify_authors_publication_added(@project)
35 33

  
36 34
      flash[:notice] = "Successfully created publication."
......
58 56

  
59 57
    # method for creating "pasted" bibtex entries
60 58
    if bibtex_entry
61
      parse_bibtex_list bibtex_entry    
59
      parse_bibtex_list bibtex_entry
62 60
    end
63 61
  end
64 62

  
65 63
  def get_bibtex_required_fields
66 64

  
67 65
    unless params[:value].empty?
68
      fields = BibtexEntryType.fields(params[:value]) 
66
      fields = BibtexEntryType.fields(params[:value])
69 67
    end
70 68

  
71 69
    respond_to do |format|
72 70
      format.js {
73
        render(:update) {|page|       
71
        render(:update) {|page|
74 72
          if params[:value].empty?
75 73
            page << "hideOnLoad();"
76 74
          else
......
92 90
    end
93 91
  end
94 92

  
95
  def edit   
93
  def edit
96 94
    find_project_by_project_id unless params[:project_id].nil?
97 95

  
98 96
    @edit_view = true;
99 97
    @publication = Publication.find(params[:id])
100 98
    @selected_bibtex_entry_type_id = @publication.bibtex_entry.entry_type
101 99

  
102
    @author_options = []  
100
    @author_options = []
103 101

  
104
    @bibtype_fields = BibtexEntryType.fields(@selected_bibtex_entry_type_id)    
102
    @bibtype_fields = BibtexEntryType.fields(@selected_bibtex_entry_type_id)
105 103
  end
106 104

  
107
  def update    
108
    @publication = Publication.find(params[:id])        
109

  
105
  def update
106
    @publication = Publication.find(params[:id])
110 107
    @author_options = []
111 108

  
112
    logger.error { "INSIDE THE UPDATE ACTION IN THE PUBLICATION CONTROLLER" }
113

  
114 109
    if @publication.update_attributes(params[:publication])
115 110
      flash[:notice] = "Successfully updated Publication."
116 111

  
112
      # expires the previosly cached entries
113
      Rails.cache.delete "publication-#{@publication.id}-ieee"
114
      Rails.cache.delete "publication-#{@publication.id}-bibtex"
115

  
117 116
      if !params[:project_id].nil?
118 117
        redirect_to :action => :show, :id => @publication, :project_id => params[:project_id]
119 118
      else
......
121 120
      end
122 121
    else
123 122
      render :action => 'edit'
124
    end   
123
    end
125 124
  end
126 125

  
127 126

  
......
143 142
    return authors_entry.split(" and ")
144 143
  end
145 144

  
146
  # parses a list of bibtex 
145
  # parses a list of bibtex
147 146
  def parse_bibtex_list(bibtex_list)
148 147
    bibliography = BibTeX.parse bibtex_list
149 148

  
......
156 155
        create_bibtex_entry d
157 156
      end
158 157
    end
159
  end 
158
  end
160 159

  
161
  def create_bibtex_entry(d)        
160
  def create_bibtex_entry(d)
162 161
    @publication = Publication.new
163
    @bentry = BibtexEntry.new        
162
    @bentry = BibtexEntry.new
164 163
    authors = []
165 164
    institution = ""
166 165
    email = ""
......
178 177
      else
179 178
        @bentry[field] = d[field]
180 179
      end
181
    end 
180
    end
182 181

  
183 182
    @publication.bibtex_entry = @bentry
184 183
    @publication.save
185 184

  
186
    # what is this for??? 
185
    # what is this for???
187 186
    # @created_publications << @publication.id
188 187

  
189 188
    # need to save all authors
190
    #   and establish the author-publication association 
191
    #   via the authorships table 
189
    #   and establish the author-publication association
190
    #   via the authorships table
192 191
    authors.each_with_index.map do |authorname, idx|
193 192
      author = Author.new(:name => authorname)
194 193
      if author.save!
......
220 219
  def autocomplete_for_project
221 220
    @publication = Publication.find(params[:id])
222 221

  
223
    @projects = Project.active.like(params[:q]).find(:all, :limit => 100) - @publication.projects            
222
    @projects = Project.active.like(params[:q]).find(:all, :limit => 100) - @publication.projects
224 223
    logger.debug "Query for \"#{params[:q]}\" returned \"#{@projects.size}\" results"
225 224
    render :layout => false
226 225
  end
227 226

  
228
  def autocomplete_for_author    
227
  def autocomplete_for_author
229 228
    @results = []
230 229

  
231 230
    object_id = params[:object_id]
......
239 238

  
240 239
    @results = users_list
241 240

  
242
    # TODO: can be optimized…    
243
    authorships_list.each do |authorship|      
241
    # TODO: can be optimized…
242
    authorships_list.each do |authorship|
244 243
      flag = true
245 244

  
246 245
      users_list.each do |user|
......
254 253
      @results << authorship if flag
255 254
    end
256 255

  
257
    render :layout => false    
256
    render :layout => false
258 257
  end
259 258

  
260 259
  def get_user_info
......
272 271

  
273 272
    respond_to do |format|
274 273
      format.js {
275
        render(:update) {|page| 
274
        render(:update) {|page|
276 275
          page[name_field].value = item.name
277 276
          page[email_field].value = item.mail
278 277
          page[institution_field].value = item.institution
......
294 293
  end
295 294

  
296 295
  def add_project
297
    @projects = Project.find(params[:publication][:project_ids])    
296
    @projects = Project.find(params[:publication][:project_ids])
298 297
    @publication.projects << @projects
299
    @project = Project.find(params[:project_id])    
298
    @project = Project.find(params[:project_id])
300 299

  
301
    # TODO luisf should also respond to HTML??? 
300
    # TODO luisf should also respond to HTML???
302 301
    respond_to do |format|
303 302
      format.html { redirect_to :back }
304
      format.js { 
305
        render(:update) {|page| 
306
          page[:add_project_form].reset          
303
      format.js {
304
        render(:update) {|page|
305
          page[:add_project_form].reset
307 306
          page.replace_html :list_projects, :partial => 'list_projects'
308 307
        }
309 308
      }
......
320 319
        @publication.projects.delete proj if request.post?
321 320
      end
322 321
    else
323
      logger.error { "Cannot remove project from publication list" }      
322
      logger.error { "Cannot remove project from publication list" }
324 323
    end
325 324

  
326 325
    logger.error { "CURRENT project name#{proj.name} and wanna delete #{@project.name}" }
327 326

  
328
    render(:update) {|page| 
327
    render(:update) {|page|
329 328
      page.replace_html "list_projects", :partial => 'list_projects', :id  => @publication
330
    }    
329
    }
331 330
  end
332 331

  
333 332
  def destroy

Also available in: Unified diff