将at js data整合到文件中

This commit is contained in:
guange 2015-12-09 09:59:13 +08:00
parent 57d05d147e
commit 3476731b83
7 changed files with 50 additions and 32 deletions

View File

@ -0,0 +1,25 @@
#coding=utf-8
class AtController < ApplicationController
respond_to :js
def show
type = params[:type]
case type
when "Issue"
@users = find_issue(params)
else
end
end
private
def find_issue(params)
#1. issues list persons
#2. project persons
issue = Issue.find(params[:id])
journals = issue.journals
at_persons = journals.map(&:user) + issue.project.users
at_persons.uniq{|u| u.id}.delete_if{|u| u.id == User.current.id}
end
end

View File

@ -142,24 +142,17 @@ class IssuesController < ApplicationController
@project_base_tag = (params[:project_id] || @issue.project) ? 'base_projects':'base'#by young
@available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
#id name email
#1. issues list persons
#2. project persons
@at_persons = @journals.map(&:user) + @issue.project.users
@at_persons = @at_persons.uniq{|u| u.id}.delete_if{|u| u.id == User.current.id}
@at_persons = nil
respond_to do |format|``
format.html {
retrieve_previous_and_next_issue_ids
render :template => 'issues/show', :layout => @project_base_tag#by young
}
format.api
format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
format.pdf {
pdf = issue_to_pdf(@issue, :journals => @journals)
send_data(pdf, :type => 'application/pdf', :filename => filename_for_content_disposition("#{@project.identifier}-#{@issue.id}.pdf") )
}
respond_to do |format|
format.html {
retrieve_previous_and_next_issue_ids
render :template => 'issues/show', :layout => @project_base_tag#by young
}
format.api
format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
format.pdf {
pdf = issue_to_pdf(@issue, :journals => @journals)
send_data(pdf, :type => 'application/pdf', :filename => filename_for_content_disposition("#{@project.identifier}-#{@issue.id}.pdf") )
}
end
end

View File

@ -2624,15 +2624,7 @@ int main(int argc, char** argv){
opt = {enable_at: true, prettify: false, init_activity: false}.merge default_opt
ss = ''
if opt[:enable_at]
ss = '<script type="text/javascript">'
ss += 'window.atPersonLists = [];'
@at_persons && @at_persons.each_with_index do |person,index|
ss += "var o = {id: #{index}, name: '#{person.show_name}', login: '#{person.login}', searchKey: '#{person.get_at_show_name}'};"
ss += "atPersonLists.push(o);"
end
ss += "</script>"
ss += %Q|<script src="/at/#{opt[:enable_at][:id]}.js?type=#{opt[:enable_at][:type]}" type="text/javascript"></script>|
end
ss += javascript_include_tag("/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg')

8
app/views/at/show.js.erb Normal file
View File

@ -0,0 +1,8 @@
(function(){
window.atPersonLists = [];
<% @users && @users.each_with_index do |person,index| %>
var o = {id: <%=index%>, name: '<%=person.show_name%>', login: '<%=person.login%>', searchKey: '<%=person.get_at_show_name%>'};
atPersonLists.push(o);
<% end %>
})();

View File

@ -1,5 +1,5 @@
<%= content_for(:header_tags) do %>
<%= import_ke(enable_at: true) %>
<%= import_ke(enable_at: {id: @issue.id, type: 'Issue'}) %>
<% end %>
<div class="project_r_h">

View File

@ -1035,13 +1035,14 @@ RedmineApp::Application.routes.draw do
match 'system_log/clear'
##ended by lizanle
resources :git_callback do
collection do
post 'post_update'
end
end
resources :at
Dir.glob File.expand_path("plugins/*", Rails.root) do |plugin_dir|
file = File.join(plugin_dir, "config/routes.rb")
if File.exists?(file)

View File

@ -1,4 +1,4 @@
function enableAt(_editor) {
var enableAt = function(_editor) {
var editor = _editor;
if(editor.edit == undefined || editor.edit.iframe == undefined){
return;
@ -11,7 +11,7 @@ function enableAt(_editor) {
console.log("enable at");
$.fn.atwho.debug = true;
if(!atPersonLists){
if("undefined" === (typeof atPersonLists) || !atPersonLists){
return;
}
var names = atPersonLists;
@ -32,7 +32,6 @@ function enableAt(_editor) {
}
$inputor = $(ifrBody).atwho(at_config);
window.aaa= $inputor;
$inputor.caret('pos', 47);
$inputor.focus().atwho('run');
};