mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-05 20:54:27 +08:00
refactor
This commit is contained in:
parent
ed24448817
commit
5b58824ec0
7 changed files with 31 additions and 23 deletions
2
Gemfile
2
Gemfile
|
@ -65,7 +65,7 @@ gem 'aws-sdk-v1'
|
|||
gem 'delayed_job_active_record'
|
||||
gem 'devise-async'
|
||||
gem 'ruby-graphviz', '~> 1.2' # Graphviz for rails
|
||||
gem 'tinymce-rails' # Rich text editor
|
||||
gem 'tinymce-rails', '~> 4.5.7' # Rich text editor
|
||||
|
||||
gem 'base62' # Used for smart annotations
|
||||
gem 'newrelic_rpm'
|
||||
|
|
|
@ -20,11 +20,13 @@ var TinyMCE = (function() {
|
|||
tinyMCE.init({
|
||||
selector: 'textarea.tinymce',
|
||||
toolbar: ["undo redo | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link | forecolor backcolor | customimageuploader | codesample"],
|
||||
plugins: "customimageuploader,link,advlist,codesample,autolink,lists,charmap,hr,anchor,searchreplace,wordcount,visualblocks,visualchars,insertdatetime,nonbreaking,save,contextmenu,directionality,paste,textcolor,colorpicker,textpattern,imagetools",
|
||||
plugins: "customimageuploader,link,advlist,codesample,autolink,lists,charmap,hr,anchor,searchreplace,wordcount,visualblocks,visualchars,insertdatetime,nonbreaking,save,contextmenu,directionality,paste,textcolor,colorpicker,textpattern",
|
||||
codesample_languages: [{"text":"R","value":"r"},{"text":"MATLAB","value":"matlab"},{"text":"Python","value":"python"},{"text":"JSON","value":"javascript"},{"text":"HTML/XML","value":"markup"},{"text":"JavaScript","value":"javascript"},{"text":"CSS","value":"css"},{"text":"PHP","value":"php"},{"text":"Ruby","value":"ruby"},{"text":"Java","value":"java"},{"text":"C","value":"c"},{"text":"C#","value":"csharp"},{"text":"C++","value":"cpp"}],
|
||||
removed_menuitems: 'newdocument',
|
||||
object_resizing: false,
|
||||
elementpath: false,
|
||||
default_link_target: "_blank",
|
||||
forced_root_block: false,
|
||||
default_link_target: '_blank',
|
||||
target_list: [
|
||||
{title: 'New page', value: '_blank'},
|
||||
{title: 'Same page', value: '_self'}
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
onclick: insertImage,
|
||||
subtype: 'primary'},
|
||||
{text: "<%= I18n.t 'general.cancel' %>",
|
||||
onclick: ed.windowManager.close}
|
||||
onclick: editor.windowManager.close}
|
||||
],
|
||||
}, {
|
||||
plugin_url: url
|
||||
|
@ -42,11 +42,11 @@
|
|||
|
||||
iframe = win.find('iframe')[0];
|
||||
form = createElement('form', {
|
||||
action: ed.getParam('customimageuploader_form_url',
|
||||
'<%= Rails.application
|
||||
.routes
|
||||
.url_helpers
|
||||
.tiny_mce_assets_path %>'),
|
||||
action: editor.getParam('customimageuploader_form_url',
|
||||
'<%= Rails.application
|
||||
.routes
|
||||
.url_helpers
|
||||
.tiny_mce_assets_path %>'),
|
||||
target: iframe._id,
|
||||
method: 'POST',
|
||||
enctype: 'multipart/form-data',
|
||||
|
@ -67,17 +67,17 @@
|
|||
form.appendChild(createElement('input',
|
||||
{type: 'hidden',
|
||||
name: 'object_type',
|
||||
value: $(ed.getElement())
|
||||
.data('object-type')}));
|
||||
value: $(editor.getElement())
|
||||
.data('object-type')}));
|
||||
form.appendChild(createElement('input',
|
||||
{type: 'hidden',
|
||||
name: 'object_id',
|
||||
value: $(ed.getElement())
|
||||
.data('object-id')}));
|
||||
value: $(editor.getElement())
|
||||
.data('object-id')}));
|
||||
form.appendChild(createElement('input',
|
||||
{type: 'hidden',
|
||||
name: 'hint',
|
||||
value: ed.getParam('uploadimage_hint', '')}));
|
||||
value: editor.getParam('uploadimage_hint', '')}));
|
||||
|
||||
var el = win.getEl();
|
||||
var body = document.getElementById(el.id + '-body');
|
||||
|
@ -157,11 +157,11 @@
|
|||
if(json['error']) {
|
||||
handleError(json['error']['message']);
|
||||
} else {
|
||||
ed.execCommand('mceInsertContent', false, buildHTML(json));
|
||||
ed.windowManager.close();
|
||||
editor.execCommand('mceInsertContent', false, buildHTML(json));
|
||||
editor.windowManager.close();
|
||||
}
|
||||
} catch(e) {
|
||||
// hack that get's the server error message
|
||||
// hack that gets the server error message
|
||||
var error_json = JSON.parse($(ret).text());
|
||||
handleError(error_json['error'][0]);
|
||||
}
|
||||
|
@ -177,8 +177,12 @@
|
|||
function handleError(error) {
|
||||
var message = win.find('.error')[0].getEl();
|
||||
|
||||
if(message)
|
||||
message.getElementsByTagName('p')[0].innerHTML = ed.translate(error);
|
||||
if(message) {
|
||||
message
|
||||
.getElementsByTagName('p')[0]
|
||||
.innerHTML = editor.translate(error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function createElement(element, attributes) {
|
||||
|
|
|
@ -32,6 +32,7 @@ class ResultTextsController < ApplicationController
|
|||
|
||||
def create
|
||||
@result_text = ResultText.new(result_params[:result_text_attributes])
|
||||
# gerate a tag that replaces img tag in database
|
||||
@result_text.text = parse_tiny_mce_asset_to_token(@result_text.text)
|
||||
@result = Result.new(
|
||||
user: current_user,
|
||||
|
@ -42,8 +43,8 @@ class ResultTextsController < ApplicationController
|
|||
@result.last_modified_by = current_user
|
||||
|
||||
respond_to do |format|
|
||||
if (@result.save and @result_text.save) then
|
||||
# link tiny_mce_assets to the result text
|
||||
if (@result.save and @result_text.save)
|
||||
# link tiny_mce_assets to the text result
|
||||
link_tiny_mce_assets(@result_text.text, @result_text)
|
||||
|
||||
result_annotation_notification
|
||||
|
|
|
@ -164,7 +164,7 @@ class StepsController < ApplicationController
|
|||
table.last_modified_by = current_user unless table.new_record?
|
||||
table.team = current_team
|
||||
end
|
||||
|
||||
|
||||
# gerate a tag that replaces img tag in databases
|
||||
@step.description = parse_tiny_mce_asset_to_token(
|
||||
params[:step][:description],
|
||||
|
|
|
@ -103,6 +103,8 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def smart_annotation_parser(text, team = nil)
|
||||
# sometimes happens that the "team" param gets wrong data: "{nil, []}"
|
||||
# so we have to check if the "team" param is kind of Team object
|
||||
team = nil unless team.is_a? Team
|
||||
new_text = smart_annotation_filter_resources(text)
|
||||
new_text = smart_annotation_filter_users(new_text, team)
|
||||
|
|
|
@ -6,5 +6,4 @@ namespace :tiny_mce_asset do
|
|||
'result_text_id IS ? AND created_at < ?',
|
||||
nil, nil, 7.days.ago)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue