diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1463de6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.bundle/ +log/*.log +pkg/ +test/dummy/db/*.sqlite3 +test/dummy/log/*.log +test/dummy/tmp/ \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..ee154b1 --- /dev/null +++ b/Gemfile @@ -0,0 +1,17 @@ +source "http://rubygems.org" + +# Declare your gem's dependencies in personal_journal.gemspec. +# Bundler will treat runtime dependencies like base dependencies, and +# development dependencies will be added by default to the :development group. +gemspec + +# jquery-rails is used by the dummy application +gem "jquery-rails" + +# Declare any dependencies that are still in development here instead of in +# your gemspec. These might include edge Rails or gems from your path or +# Git. Remember to move these dependencies to your gemspec before releasing +# your gem to rubygems.org. + +# To use debugger +# gem 'ruby-debug19', :require => 'ruby-debug' diff --git a/MIT-LICENSE b/MIT-LICENSE new file mode 100644 index 0000000..406f17b --- /dev/null +++ b/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright 2012 YOURNAME + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.rdoc b/README.rdoc new file mode 100644 index 0000000..16a320b --- /dev/null +++ b/README.rdoc @@ -0,0 +1,3 @@ += PersonalJournal + +This project rocks and uses MIT-LICENSE. \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..6ded2a1 --- /dev/null +++ b/Rakefile @@ -0,0 +1,39 @@ +#!/usr/bin/env rake +begin + require 'bundler/setup' +rescue LoadError + puts 'You must `gem install bundler` and `bundle install` to run rake tasks' +end +begin + require 'rdoc/task' +rescue LoadError + require 'rdoc/rdoc' + require 'rake/rdoctask' + RDoc::Task = Rake::RDocTask +end + +RDoc::Task.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'PersonalJournal' + rdoc.options << '--line-numbers' + rdoc.rdoc_files.include('README.rdoc') + rdoc.rdoc_files.include('lib/**/*.rb') +end + +APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__) +load 'rails/tasks/engine.rake' + + +Bundler::GemHelper.install_tasks + +require 'rake/testtask' + +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.libs << 'test' + t.pattern = 'test/**/*_test.rb' + t.verbose = false +end + + +task :default => :test diff --git a/app/assets/images/personal_journal/.gitkeep b/app/assets/images/personal_journal/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/javascripts/personal_journal.js b/app/assets/javascripts/personal_journal.js new file mode 100644 index 0000000..57fc98e --- /dev/null +++ b/app/assets/javascripts/personal_journal.js @@ -0,0 +1 @@ +//= require_tree ./personal_journal/desktop diff --git a/app/assets/javascripts/personal_journal/desktop/journal_pages.js b/app/assets/javascripts/personal_journal/desktop/journal_pages.js new file mode 100644 index 0000000..5da6a9d --- /dev/null +++ b/app/assets/javascripts/personal_journal/desktop/journal_pages.js @@ -0,0 +1,151 @@ +orbitDesktop.prototype.initializeJournalPapers = function(target,url,cache){ // this init journal papers + this.initializeJournalPapers.formCallback = function(data){ + if(data.success){ + o.notify(data.msg,"success"); + o.sub_menu_item($("div[content-type=menu] a").eq(0)); + }else{ + o.notify(data.msg,"alert"); + } + } + + this.initializeJournalPapers.list = function(){ // to open list part in journal papers page + var journalData; + var bindHandlers = function(){ // to bind handlers for list page + + } + bindHandlers(); + + var bindSecondaryHandlers = function(){ + $("#journal_p div#paper_list a.icon-check-empty").click(function(){ + if($(this).hasClass("icon-check-empty")){ + $(this).switchClass("icon-check-empty","icon-check",0); + } else if($(this) .hasClass("icon-check")) { + $(this).switchClass("icon-check","icon-check-empty",0); + } else if($(this).hasClass("icon-star")){ + $(this).removeClass("icon-star").addClass("icon-star-empty"); + } else if($(this).hasClass("icon-star-empty")){ + $(this).removeClass("icon-star-empty").addClass("icon-star"); + } + return false; + }) + } + o.enableSharing("div.share_mode"); + } + this.initializeJournalPapers.paperDelete = function(data,dom){ + var parent = dom.parent().parent().parent(); + if(data.success){ + parent.hide("slide",function(){parent.remove();}); + o.notify(data.msg,"success"); + } + } + + this.initializeJournalPapers.cancelpaper = function(){ + o.highlight_sub_menu_item(0); + } + + var uploadFiles = function(){ + $('#add_plugin_file a.add').click(function(){ + var new_id = $(this).prev().attr('value'); + var old_id = new RegExp("new_writing_journal_files", "g"); + $(this).prev().attr('value', parseInt(new_id) + 1); + var x = get_html(old_id,new_id); + var newfield = $(x); + $(this).parents('table').append(newfield); + newfield.find('.action a.delete').click(function(){ + newfield.remove(); + }); + return false; + }); + $('.action a.remove_existing_record').click(function(){ + $(this).toggleClass("color-red",function(){ + if($(this).hasClass('color-red')){ + $(this).next('.should_destroy').attr('value', 1); + }else{ + $(this).next('.should_destroy').removeAttr('value'); + } + }) + }); + } + + + + this.initializeJournalPapers.editpaper = function(){ + o.highlight_sub_menu_item(1); + uploadFiles(); + o.enablelanguageSelect(); + } + + this.initializeJournalPapers.addpaper = function(){ // to open add pages in journal papers page + uploadFiles(); + o.enablelanguageSelect(); + } + + this.initializeJournalPapers.brief = function(){ + o.enablelanguageSelect(); + $("textarea.editor").ckeditor({ + height: 300, + width: $(".overview").width() - 20 + }); + } + + this.initializeJournalPapers.journal = function(){ // to open add pages in journal papers page + var bindHandlers = function(){ // to bind handlers for add page + + } + bindHandlers(); + } + + this.initializeJournalPapers.coAuthorformCallback = function(data){ + if(data.success){ + o.notify(data.msg,"success"); + o.sub_menu_item($("div[content-type=menu] a").eq(3)); + }else{ + o.notify(data.msg,"alert"); + } + } + this.initializeJournalPapers.coauthor = function(){ // to open add pages in coauthor page + var bindHandlers = function(){ // to bind handlers for add page + + } + bindHandlers(); + } + this.initializeJournalPapers.coauthorRelationForm = function(data){ + if(data.success){ + o.notify(data.msg,"success"); + $("#co_author_relation_table").html(data.newvalue); + }else{ + o.notify(data.msg,"alert"); + } + } + this.initializeJournalPapers.coauthorRelationEditForm = function(data){ + if(data.success){ + o.notify(data.msg,"success"); + var x = o.layout_data.generate_layout_html(data.newvalue); + $("div[container=true] div.overview").html(x.markup); + }else{ + o.notify(data.msg,"alert"); + } + } + this.initializeJournalPapers.allnone = function(d,o){ + switch(o.attr("href")){ + case "all": + $("div.overview a.icon-check-empty").removeClass("icon-check-empty").addClass("icon-check"); + break; + case "none": + $("div.overview a.icon-check").removeClass("icon-check").addClass("icon-check-empty"); + break; + } + } + this.initializeJournalPapers.allnone = function(d,o){ + switch(o.attr("href")){ + case "all": + $("div.overview a.icon-check-empty").removeClass("icon-check-empty").addClass("icon-check"); + break; + case "none": + $("div.overview a.icon-check").removeClass("icon-check").addClass("icon-check-empty"); + break; + } + } +}; + + diff --git a/app/assets/stylesheets/personal_journal/.gitkeep b/app/assets/stylesheets/personal_journal/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/stylesheets/personal_journal/desktop/journal_pages.css b/app/assets/stylesheets/personal_journal/desktop/journal_pages.css new file mode 100644 index 0000000..96b2d39 --- /dev/null +++ b/app/assets/stylesheets/personal_journal/desktop/journal_pages.css @@ -0,0 +1,109 @@ +/* Journal Papers */ +[page-name="journal_p_list"] .list_t_item .inner { + padding-left: 30px; } +[page-name="journal_p_list"] .list_item_action { + font-size: 12px; + float: left; + margin-left: -30px; } + [page-name="journal_p_list"] .list_item_action a { + display: block; + width: 20px; + height: 20px; + line-height: 20px; + margin: 1px 1px 6px 1px; + font-size: 20px; } + [page-name="journal_p_list"] .list_item_action .icon-star-empty, [page-name="journal_p_list"] .list_item_action .icon-check-empty { + color: #dddddd; + -webkit-transition: color 0.3s ease; + -moz-transition: color 0.3s ease; + transition: color 0.3s ease; } + [page-name="journal_p_list"] .list_item_action .icon-star-empty:hover, [page-name="journal_p_list"] .list_item_action .icon-check-empty:hover { + color: #aaaaaa; } + [page-name="journal_p_list"] .list_item_action .icon-star { + color: #faa732; } + [page-name="journal_p_list"] .list_item_action .icon-check { + color: #333; } +[page-name="journal_p_list"] .file_view .list_t_des { + overflow: hidden; } +[page-name="journal_p_list"] .file_view .file { + float: left; + width: 120px; + height: 50px; + padding: 6px; + margin: 1px; + position: relative; + -webkit-box-sizing: border-box; + /* webkit */ + -khtml-box-sizing: border-box; + /* konqueror */ + -moz-box-sizing: border-box; + /* firefox */ + -ms-box-sizing: border-box; + /* ie */ + box-sizing: border-box; + /* css3 */ } + [page-name="journal_p_list"] .file_view .file:hover { + background-color: #c4c4c4; } + [page-name="journal_p_list"] .file_view .file img { + width: 38px; + height: 38px; + position: absolute; + left: 6px; + top: 6px; } + [page-name="journal_p_list"] .file_view .file .filetitle { + display: block; + width: 100%; + height: 38px; + padding-left: 40px; + overflow: hidden; + -webkit-box-sizing: border-box; + /* webkit */ + -khtml-box-sizing: border-box; + /* konqueror */ + -moz-box-sizing: border-box; + /* firefox */ + -ms-box-sizing: border-box; + /* ie */ + box-sizing: border-box; + /* css3 */ } + +/* Journal Journal list */ +[page-name="journal_p_journal"] .datalist_item .inner { + padding-left: 30px; } +[page-name="journal_p_journal"] .list_item_action { + font-size: 12px; + float: left; + margin-left: -30px; } +[page-name="journal_p_journal"] .list_item_action i { + color: #999; + font-size: 20px; + display: block; + width: 20px; + height: 20px; + line-height: 20px; + margin: 1px 1px 6px 1px; } +[page-name="journal_p_journal"] .list_t_desc { + font-family: Arial, sans-serif; + font-size: 12px; + color: #999; } + +/* Journal Co-Author */ +[page-name="journal_p_coauthor"] .list_t_item { + height: 110px; } +[page-name="journal_p_coauthor"] .info { + font-family: Arial, sans-serif; } +[page-name="journal_p_coauthor"] .info li { + margin-bottom: 8px; + color: #999; } +[page-name="journal_p_coauthor"] .info .name { + font-size: 18px; + line-height: 24px; + color: #333; } + +/* Journal Co-Author Relationship*/ +[page-name="journal_p_coauthor_relation"] .edit_co_author_relation { + /*margin-left: -10px;*/ } +[page-name="journal_p_coauthor_relation"] .form_space { + margin-bottom: 10px; + font-size: 18px; + font-family: Arial, sans-serif; } diff --git a/app/assets/stylesheets/personal_journal/desktop/journal_pages.scss b/app/assets/stylesheets/personal_journal/desktop/journal_pages.scss new file mode 100644 index 0000000..671a9ad --- /dev/null +++ b/app/assets/stylesheets/personal_journal/desktop/journal_pages.scss @@ -0,0 +1,124 @@ +@import "desktop-helper"; + +/* Journal Papers */ +[page-name="journal_p_list"] { + .list_t_item .inner { padding-left: 30px; } + .list_item_action { + font-size: 12px; + float: left; + margin-left: -30px; + + a { + display: block; + width: 20px; + height: 20px; + line-height: 20px; + margin: 1px 1px 6px 1px; + font-size: 20px; + } + .icon-star-empty, .icon-check-empty { + color: $gray; + @include transition-type(color,0.3); + + &:hover { + color: darken($gray, 20%); + } + } + .icon-star { color: #faa732; } + .icon-check { color: #333; } + } + + .file_view { + .list_t_des { + overflow: hidden; + } + .file { + float: left; + width: 120px; + height: 50px; + padding: 6px; + margin: 1px; + position: relative; + @include box-sizing; + + &:hover { + background-color: darken($gray, 10%); + } + img { + width: 38px; + height: 38px; + position: absolute; + left: 6px; + top: 6px; + } + .filetitle { + display: block; + width: 100%; + height: 38px; + padding-left: 40px; + overflow: hidden; + @include box-sizing; + } + } + } +} + +/* Journal Journal list */ +[page-name="journal_p_journal"] { + + .datalist_item .inner { + padding-left: 30px; + } + .list_item_action { + font-size: 12px; + float: left; + margin-left: -30px; + } + .list_item_action i { + color: #999; + font-size: 20px; + display: block; + width: 20px; + height: 20px; + line-height: 20px; + margin: 1px 1px 6px 1px; + } + .list_t_desc { + font-family: Arial, sans-serif; + font-size: 12px; + color: #999; + } +} + +/* Journal Co-Author */ +[page-name="journal_p_coauthor"] { + .list_t_item { + height: 110px; + } + .list_item_function {} + .list_item_function a {} + .info { + font-family: Arial, sans-serif; + } + .info li { + margin-bottom: 8px; + color: #999; + } + .info .name { + font-size: 18px; + line-height: 24px; + color: #333; + } +} + +/* Journal Co-Author Relationship*/ +[page-name="journal_p_coauthor_relation"]{ + .edit_co_author_relation { + /*margin-left: -10px;*/ + } + .form_space { + margin-bottom: 10px; + font-size: 18px; + font-family: Arial, sans-serif; + } +} \ No newline at end of file diff --git a/app/controllers/.gitkeep b/app/controllers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..307a4ac --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,23 @@ +class ApplicationController < ActionController::Base + protect_from_forgery + before_filter :set_locale + + # Set I18n.locale + def set_locale + # update session if passed + session[:locale] = params[:locale] if params[:locale] + + # set locale based on session or default + begin + # check if locale is valid for non site pages + if !VALID_LOCALES.include?(session[:locale]) + I18n.locale = I18n.default_locale + else + I18n.locale = session[:locale] + end + rescue + I18n.locale = I18n.default_locale + end + end + +end diff --git a/app/controllers/panel/personal_journal/back_end/journal_author_types_controller.rb b/app/controllers/panel/personal_journal/back_end/journal_author_types_controller.rb new file mode 100644 index 0000000..0d138ca --- /dev/null +++ b/app/controllers/panel/personal_journal/back_end/journal_author_types_controller.rb @@ -0,0 +1,8 @@ +class Panel::PersonalJournal::BackEnd::JournalAuthorTypesController < Panel::PersonalJournal::BackEnd::WritingJournalCategorysController + + def initialize + super + @app_type = 'journal_author_type' + end + +end diff --git a/app/controllers/panel/personal_journal/back_end/journal_level_types_controller.rb b/app/controllers/panel/personal_journal/back_end/journal_level_types_controller.rb new file mode 100644 index 0000000..f04f1cb --- /dev/null +++ b/app/controllers/panel/personal_journal/back_end/journal_level_types_controller.rb @@ -0,0 +1,8 @@ +class Panel::PersonalJournal::BackEnd::JournalLevelTypesController < Panel::PersonalJournal::BackEnd::WritingJournalCategorysController + + def initialize + super + @app_type = 'journal_level_type' + end + +end diff --git a/app/controllers/panel/personal_journal/back_end/journal_paper_types_controller.rb b/app/controllers/panel/personal_journal/back_end/journal_paper_types_controller.rb new file mode 100644 index 0000000..83e1593 --- /dev/null +++ b/app/controllers/panel/personal_journal/back_end/journal_paper_types_controller.rb @@ -0,0 +1,8 @@ +class Panel::PersonalJournal::BackEnd::JournalPaperTypesController < Panel::PersonalJournal::BackEnd::WritingJournalCategorysController + + def initialize + super + @app_type = 'journal_paper_type' + end + +end diff --git a/app/controllers/panel/personal_journal/back_end/personal_journal_intros_controller.rb b/app/controllers/panel/personal_journal/back_end/personal_journal_intros_controller.rb new file mode 100644 index 0000000..164cb9c --- /dev/null +++ b/app/controllers/panel/personal_journal/back_end/personal_journal_intros_controller.rb @@ -0,0 +1,10 @@ +class Panel::PersonalJournal::BackEnd::PersonalJournalIntrosController < Admin::PersonalPluginIntrosController + + def initialize + super + @app_type = 'personal_journal_intro' + @app_type_name = 'personal_journal' + @reback_name = 'WritingJournal' + end + +end diff --git a/app/controllers/panel/personal_journal/back_end/writing_journal_categorys_controller.rb b/app/controllers/panel/personal_journal/back_end/writing_journal_categorys_controller.rb new file mode 100644 index 0000000..cd232c9 --- /dev/null +++ b/app/controllers/panel/personal_journal/back_end/writing_journal_categorys_controller.rb @@ -0,0 +1,143 @@ +class Panel::PersonalJournal::BackEnd::WritingJournalCategorysController < OrbitBackendController + + include OrbitControllerLib::DivisionForDisable + + open_for_manager :except => [:indx] + + def index + + get_types + + @writing_journal_categorys = @types.all + @writing_journal_category = @types.new(:display => 'List') + + # @url = panel_personal_journal_back_end_writing_journal_categorys_path + @url = eval("panel_personal_journal_back_end_#{@app_type}s_path") + + respond_to do |format| + format.html # index.html.erb + format.js + end + end + + # GET /writing_journals/1 + # GET /writing_journals/1.xml + def show + + get_types + + @writing_journal_category = @types.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.js + end + end + + # GET /writing_journals/new + # GET /writing_journals/new.xml + def new + + get_types + + @writing_journal_category = @types.new(:display => 'List') + + @verb = :post + + respond_to do |format| + format.html # new.html.erb + format.js + end + end + + # GET /writing_journals/1/edit + def edit + + get_types + + @writing_journal_category = @types.find(params[:id]) + + # @url = panel_personal_journal_back_end_writing_journal_category_path(@writing_journal_category) + # @url = eval("panel_personal_journal_back_end_#{@app_type}_path(@writing_journal_category)") + @url = polymorphic_path([:panel, :personal_journal, :back_end, @writing_journal_category]) + + @verb = :put + + respond_to do |format| + format.html + format.js + end + end + + # POST /writing_journals + # POST /writing_journals.xml + def create + + get_types + + @writing_journal_category = @types.new(params[:writing_journal_category]) + + respond_to do |format| + if @writing_journal_category.save + format.html { redirect_to(panel_personal_journal_back_end_writing_journal_categorys_url, :notice => t('writing_journal_category.create_writing_journal_category_success')) } + format.js + else + format.html { render :action => "new" } + format.js { render action: "new" } + end + end + end + + # PUT /writing_journals/1 + # PUT /writing_journals/1.xml + def update + + get_types + + @writing_journal_category = @types.find(params[:id]) + # debugger + # @url = panel_personal_journal_back_end_writing_journal_category_path(@writing_journal_category) + # @url = eval("panel_personal_journal_back_end_#{@app_type}_path(#{@writing_journal_category})") + @url = polymorphic_path([:panel, :personal_journal, :back_end, @writing_journal_category]) + + respond_to do |format| + if @writing_journal_category.update_attributes(params[:writing_journal_category]) + format.html { redirect_to(panel_personal_journal_back_end_writing_journal_categorys_url, :notice => t('writing_journal_category.update_writing_journal_category_success')) } + # format.xml { head :ok } + format.js + else + format.html { render :action => "edit" } + format.js { render :action => "edit" } + end + end + end + + # DELETE /writing_journals/1 + # DELETE /writing_journals/1.xml + def destroy + + get_types + + @writing_journal_category = @types.find(params[:id]) + @writing_journal_category.disable = @writing_journal_category.disable ? false : true + + if @writing_journal_category.save! + respond_to do |format| + format.html { redirect_to(panel_personal_journal_back_end_writing_journal_categorys_url) } + # format.xml { head :ok } + format.js + end + else + flash[:error] = t("writing_journal_category.update_failed") + format.html { render :action => "index" } + end + + end + + protected + + def get_types + @types = @app_type.classify.constantize + end + +end diff --git a/app/controllers/panel/personal_journal/back_end/writing_journals_controller.rb b/app/controllers/panel/personal_journal/back_end/writing_journals_controller.rb new file mode 100644 index 0000000..1c3998f --- /dev/null +++ b/app/controllers/panel/personal_journal/back_end/writing_journals_controller.rb @@ -0,0 +1,366 @@ +class Panel::PersonalJournal::BackEnd::WritingJournalsController < OrbitBackendController + include AdminHelper + include OrbitControllerLib::DivisionForDisable + + before_filter :authenticate_user! + + before_filter :only => [ :new,:edit,:update] do |controller| + controller.get_categorys('WritingJournalCategory') + end + + def index + get_plugins + + # @tags = get_tags + # @categories = get_categories_for_index + # @statuses = get_statuses + # category_ids = @categories.collect{|t| t.id} + @paper_type_ids = JournalPaperType.all.collect{|t| t.id.to_s} + [nil] + + @writing_journals = get_sorted_and_filtered("writing_journal", :journal_paper_type_id.in => @paper_type_ids) + respond_to do |format| + format.html # index.html.erb + format.js { } + format.xml { render :xml => @writing_journals } + end + end + + def writing_journal_setting + + get_plugins + + @level_types = JournalLevelType.all + @author_types = JournalAuthorType.all + @paper_types = JournalPaperType.all + + @tags = get_tags + + # @writing_journal_categorys = JournalLevelType.all + @set_level_type = JournalLevelType.new(:display => 'List') + @level_type_url = panel_personal_journal_back_end_writing_journals_path + + @set_author_type = JournalAuthorType.new(:display => 'List') + @author_type_url = panel_personal_journal_back_end_writing_journals_path + + @set_paper_type = JournalPaperType.new(:display => 'List') + @paper_type_url = panel_personal_journal_back_end_writing_journals_path + + + end + + def level_type_quick_add + @set_level_type = JournalLevelType.new(:display => 'List') + @level_type_url = panel_personal_journal_back_end_writing_journals_path + @set_level_type.id = params[:id] + + respond_to do |format| + format.js + end + + end + + def level_type_quick_edit + + @set_level_type = JournalLevelType.find(params[:writing_journal_id]) + @level_type_url = panel_personal_journal_back_end_writing_journal_path(@set_level_type) + + respond_to do |format| + format.js + end + end + + def author_type_quick_add + @set_author_type = JournalAuthorType.new(:display => 'List') + @author_type_url = panel_personal_journal_back_end_writing_journals_path + @set_author_type.id = params[:id] + + respond_to do |format| + format.js + end + + end + + def author_type_quick_edit + + @set_author_type = JournalAuthorType.find(params[:writing_journal_id]) + @author_type_url = panel_personal_journal_back_end_writing_journal_path(@set_author_type) + + respond_to do |format| + format.js + end + end + + def paper_type_quick_add + @set_paper_type = JournalPaperType.new(:display => 'List') + @paper_type_url = panel_personal_journal_back_end_writing_journals_path + @set_paper_type.id = params[:id] + + respond_to do |format| + format.js + end + + end + + def paper_type_quick_edit + + @set_paper_type = JournalPaperType.find(params[:writing_journal_id]) + @paper_type_url = panel_personal_journal_back_end_writing_journal_path(@set_paper_type) + + respond_to do |format| + format.js + end + end + + # GET /writing_journals/1 + # GET /writing_journals/1.xml + def show + @writing_journal = WritingJournal.find(params[:id]) + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @writing_journal } + end + end + + # GET /writing_journals/new + # GET /writing_journals/new.xml + def new + + get_plugins + + @writing_journal = WritingJournal.new + # @writing_journal_files = WritingJournalFile.all + @level_types = JournalLevelType.all + @author_types = JournalAuthorType.all + @paper_types = JournalPaperType.all + + @tags = get_tags + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @writing_journal } + end + end + + # GET /writing_journals/1/edit + def edit + + get_plugins + + @writing_journal = WritingJournal.find(params[:id]) + + @level_types = JournalLevelType.all + @author_types = JournalAuthorType.all + @paper_types = JournalPaperType.all + + @tags = get_tags + end + + # POST /writing_journals + # POST /writing_journals.xml + def create + + if params[:journal_level_type] + + @journal_level_type = JournalLevelType.new(params[:journal_level_type]) + + respond_to do |format| + if @journal_level_type.save + format.js { render 'create_writing_journal_setting' } + end + end + + elsif params[:journal_author_type] + + @journal_author_type = JournalAuthorType.new(params[:journal_author_type]) + + respond_to do |format| + if @journal_author_type.save + format.js { render 'create_writing_journal_setting' } + end + end + + + elsif params[:journal_paper_type] + + @journal_paper_type = JournalPaperType.new(params[:journal_paper_type]) + + respond_to do |format| + if @journal_paper_type.save + format.js { render 'create_writing_journal_setting' } + end + end + + else + + @level_types = JournalLevelType.all + @author_types = JournalAuthorType.all + @paper_types = JournalPaperType.all + @tags = get_tags + + @writing_journal = WritingJournal.new(params[:writing_journal]) + + if params[:writing_journal][:user_id] + @writing_journal.create_user_id = params[:writing_journal][:user_id] + @writing_journal.update_user_id = params[:writing_journal][:user_id] + else + @writing_journal.create_user_id = current_user.id + @writing_journal.update_user_id = current_user.id + end + + respond_to do |format| + if @writing_journal.save + + if params[:writing_journal][:user_id] + format.html { redirect_to(admin_users_new_interface_url(:id=>params[:writing_journal][:user_id],:show_plugin_profile=>"WritingJournal")) } + else + format.html { redirect_to(panel_personal_journal_back_end_writing_journals_url) } + end + + format.xml { render :xml => @writing_journal, :status => :created, :location => @writing_journal } + + else + format.html { render :action => "new" } + format.xml { render :xml => @writing_journal.errors, :status => :unprocessable_entity } + end + end + end + + end + + # PUT /writing_journals/1 + # PUT /writing_journals/1.xml + def update + + if params[:journal_level_type] + + @journal_level_type = JournalLevelType.find(params[:id]) + + respond_to do |format| + + if @journal_level_type.update_attributes(params[:journal_level_type]) + # format.html { redirect_to(panel_announcement_back_end_bulletins_url) } + format.js { render 'update_writing_journal_setting' } + end + end + + elsif params[:journal_author_type] + + @journal_author_type = JournalAuthorType.find(params[:id]) + + respond_to do |format| + + if @journal_author_type.update_attributes(params[:journal_author_type]) + # format.html { redirect_to(panel_announcement_back_end_bulletins_url) } + format.js { render 'update_writing_journal_setting' } + end + end + + elsif params[:journal_paper_type] + + @journal_paper_type = JournalPaperType.find(params[:id]) + + respond_to do |format| + + if @journal_paper_type.update_attributes(params[:journal_paper_type]) + # format.html { redirect_to(panel_announcement_back_end_bulletins_url) } + format.js { render 'update_writing_journal_setting' } + end + end + + else + + @writing_journal = WritingJournal.find(params[:id]) + + @writing_journal.update_user_id = current_user.id + + params[:writing_journal][:tag_ids] ||=[] + + respond_to do |format| + if @writing_journal.update_attributes(params[:writing_journal]) + format.html { redirect_to(panel_personal_journal_back_end_writing_journals_url) } + # format.js { render 'toggle_enable' } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @writing_journal.errors, :status => :unprocessable_entity } + end + end + end + + end + + # DELETE /writing_journals/1 + # DELETE /writing_journals/1.xml + def destroy + @writing_journal = WritingJournal.find(params[:id]) + @writing_journal.destroy + + respond_to do |format| + format.html { redirect_to(panel_personal_journal_back_end_writing_journals_url) } + # format.xml { head :ok } + format.js + end + end + + def delete + if params[:ids] + writing_journals = WritingJournal.any_in(:_id => params[:ids]).destroy_all + end + redirect_to panel_personal_journal_back_end_writing_journals_url(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) + end + + def data_share + + if params[:ids] + + @writing_journals = WritingJournal.any_in(:_id => params[:ids]) + + @writing_journals.each do |writing_journal| + + writing_journal.is_hidden = params[:disable] + + writing_journal.save + end + + end + + respond_to do |format| + + format.html { redirect_to(admin_users_new_interface_url(:id=>params[:user_id],:show_plugin_profile=>"WritingJournal")) } + format.json { render json: {"success"=>true}.to_json} + end + + end + + protected + + + # def get_index_categories(id = nil) + # @bulletin_categorys = [] + # if(is_manager? || is_admin?) + # @bulletin_categorys = (id ? BulletinCategory.admin_manager_all.find(id).to_a : BulletinCategory.admin_manager_all) + # elsif is_sub_manager? + # @bulletin_categorys = BulletinCategory.all + # end + # @bulletin_categorys + # end + + + # def get_categorys(id = nil) + # @writing_journal_categorys = [] + # if(is_manager? || is_admin?) + # @writing_journal_categorys = (id ? WritingJournalCategory.admin_manager_all.find(id).to_a : WritingJournalCategory.admin_manager_all)) + # elsif is_sub_manager? + # @writing_journal_categorys = WritingJournalCategory.all.authed_for_user(current_user,'edit') + # end + # if @writing_journal_categorys.empty? && params[:action] != "index" + # flash[:alert] = t("announcement.error.no_avilb_cate_for_posting") + # redirect_to :action => :index + # end + # end + + def get_plugins + @plugins = OrbitApp::Plugin::Registration.all + end + +end diff --git a/app/controllers/panel/personal_journal/desktop/journal_co_author_relations_controller.rb b/app/controllers/panel/personal_journal/desktop/journal_co_author_relations_controller.rb new file mode 100644 index 0000000..5f0c9d4 --- /dev/null +++ b/app/controllers/panel/personal_journal/desktop/journal_co_author_relations_controller.rb @@ -0,0 +1,66 @@ +class Panel::PersonalJournal::Desktop::JournalCoAuthorRelationsController < ApplicationController + def index + page = params[:page] + page ||= 1 + @journal_co_author_relations = JournalCoAuthorRelation.all + new + + @journal_co_author_relations = @journal_co_author_relations.page(page).per(50) + respond_to do |format| + format.html {render layout: false } + end + end + + def edit + @journal_co_author_relation = JournalCoAuthorRelation.find(params[:id]) + respond_to do |format| + format.html { render :layout => false} + end + end + + def new + @journal_co_author_relation = JournalCoAuthorRelation.new + end + + def create + @journal_co_author_relation = JournalCoAuthorRelation.new(params[:journal_co_author_relation]) + @journal_co_author_relations = JournalCoAuthorRelation.all + + if @journal_co_author_relation.save + newv = render_to_string partial: "show_form", object: @journal_co_author_relations + render json: {success: true, msg: t("create_success"), newvalue: newv}.to_json + else + error_msg = @journal_co_author_relation.errors.full_messages.join("
") + render json: {success: false, msg: error_msg}.to_json + end + end + + def update + @journal_co_author_relation = JournalCoAuthorRelation.find(params[:id]) + if @journal_co_author_relation.update_attributes(params[:journal_co_author_relation]) + @journal_co_author_relations = JournalCoAuthorRelation.all + newv = render_to_string partial: "show_form", object: @journal_co_author_relations + render json: {success: true, msg: t("update_success"), newvalue: newv}.to_json + else + error_msg = @journal_co_author.errors.full_messages.join("
") + render json: {success: false, msg: error_msg}.to_json + end + end + + def destroy + @journal_co_author_relation = JournalCoAuthorRelation.find(params[:id]) + @journal_co_author_relation.destroy + reset_co_author_relation + + render :json => {success: true, msg: "delete_success"} + end + + private + + def reset_co_author_relation + co_author = JournalCoAuthor.where(journal_co_author_relations_id: @journal_co_author_relation.id) + co_author.map do |c| + c.update_attributes(journal_co_author_relations_id: nil) + end + end +end diff --git a/app/controllers/panel/personal_journal/desktop/journal_co_authors_controller.rb b/app/controllers/panel/personal_journal/desktop/journal_co_authors_controller.rb new file mode 100644 index 0000000..01a320a --- /dev/null +++ b/app/controllers/panel/personal_journal/desktop/journal_co_authors_controller.rb @@ -0,0 +1,61 @@ +class Panel::PersonalJournal::Desktop::JournalCoAuthorsController < ApplicationController + def index + page = params[:page] + page ||= 1 + @journal_co_authors = JournalCoAuthor.where(name_id: current_user.id).asc(:co_author) + @journal_co_author_relations = JournalCoAuthorRelation.all + + @journal_co_authors = @journal_co_authors.page(page).per(40) + + respond_to do |format| + format.html { render :layout => false} + end + end + + def new + @journal_co_author = JournalCoAuthor.new + @journal_co_author_relations = JournalCoAuthorRelation.all + + respond_to do |format| + format.html { render :layout => false} + end + end + + def edit + @journal_co_author = JournalCoAuthor.find(params[:id]) + @journal_co_author_relations = JournalCoAuthorRelation.all + respond_to do |format| + format.html { render :layout => false} + end + end + + def create + @journal_co_author = JournalCoAuthor.new(params[:journal_co_author]) + @journal_co_author.name_id= current_user.id + + if @journal_co_author.save + render json: {success:true, msg: t('create_success')}.to_json + else + error_msg = @journal_co_author.errors.full_messages.join("
") + render json: {success: false, msg: error_msg}.to_json + end + end + + def update + @journal_co_author = JournalCoAuthor.find(params[:id]) + + if @journal_co_author.update_attributes(params[:journal_co_author]) + render json: {success:true, msg: t('update_success')}.to_json + else + error_msg = @journal_co_author.errors.full_messages.join("
") + render json: {success: false, msg: error_msg}.to_json + end + end + + def destroy + @journal_co_author = JournalCoAuthor.find(params[:id]) + @journal_co_author.destroy + + render :json => {success: true, msg: "delete_success"} + end +end diff --git a/app/controllers/panel/personal_journal/desktop/journal_pages_controller.rb b/app/controllers/panel/personal_journal/desktop/journal_pages_controller.rb new file mode 100644 index 0000000..5948148 --- /dev/null +++ b/app/controllers/panel/personal_journal/desktop/journal_pages_controller.rb @@ -0,0 +1,124 @@ +class Panel::PersonalJournal::Desktop::JournalPagesController < ApplicationController + def index + @writing_journals = WritingJournal.where(create_user_id: current_user.id) + @level_types = JournalLevelType.all + @view_by = params[:view] + page = params[:page] + page ||= 1 + + @per_column = 5 + + case @view_by + when "abstract" + @per_column = 1 + when "file" + @per_column = 2 + end + + if @view_by.nil? + @view_by = " " + @writing_journals = @writing_journals.asc(:paper_title) + else + @writing_journals = @writing_journals.asc(@view_by).asc(:paper_title) + end + + @level_types = ConferencePaperType.all + + @writing_journals = @writing_journals.page(page).per(50) + + respond_to do |format| + format.html { render :layout => false} + end + end + + def new + @writing_journal = WritingJournal.new + @level_types = JournalLevelType.all + @author_types = JournalAuthorType.all + @paper_types= JournalPaperType.all + + @journal_candidate = + WritingJournal.where(create_user_id: current_user.id).map{|j|j.journal_title}.uniq + + if (not params[:q].nil?) and (current_user.name.include?params[:q]) + @user = [{ :id => 0, :text => current_user.name, :email => current_user.email}] # self account name + else + @user = [] + end + + @co_authors = JournalCoAuthor.where(name_id: current_user.id, :co_author => /#{params[:q]}/).asc(:co_author) + + # search string + self account name + match pattern + @co_authors = [{ :id => params[:q], :text => params[:q], :email => "#{t("add")}#{t("author")}" }] + + @user + + @co_authors.map{|m| { :id => m.id, :text => m.co_author, :email => m.email } } + + respond_to do |format| + format.html { render :layout => false} + format.json { render :json => {:results => @co_authors}.to_json } + end + + end + + def edit + @writing_journal = WritingJournal.find(params[:id]) + @level_types = JournalLevelType.all + @author_types = JournalAuthorType.all + @paper_types= JournalPaperType.all + respond_to do |format| + format.html { render :layout => false} + end + end + + def create + params[:writing_journal][:create_user_id] = current_user.id + @writing_journal = WritingJournal.new(params[:writing_journal]) + + if @writing_journal.save + render json: {success: true, msg: t('create_success')}.to_json + else + error_msg = @writing_journal.errors.full_messages.join("
") + render json: {success: false, msg: error_msg}.to_json + end + end + + def update + params[:writing_journal][:update_user_id] = current_user.id + @writing_journal= WritingJournal.find(params[:id]) + + if @writing_journal.update_attributes(params[:writing_journal]) + render json: {success: true, msg: t('update_success')}.to_json + else + error_msg = @writing_journal.errors.full_messages.join("
") + render json: {success: false, msg: error_msg}.to_json + end + end + + def destroy + @writing_journal = WritingJournal.find(params[:id]) + @writing_journal.destroy + render :json => {success: true, msg: t('delete_success')} + end + + def journal_type + page = params[:page] + page ||= 1 + + level_types = JournalLevelType.all + all_journal_lists = WritingJournal.where(create_user_id: current_user.id) + all_journal_lists = all_journal_lists.asc(:journal_title) + all_journal_lists = all_journal_lists.page(page).per(50) + all_journal_lists = all_journal_lists.map do |j| + [ j.journal_title, + j.journal_level_type_ids.map do |type| + level_types.find(type).title + end] + end + + @journal_lists = all_journal_lists + + respond_to do |format| + format.html { render :layout => false} + end + end +end diff --git a/app/controllers/panel/personal_journal/desktop/journal_windows_controller.rb b/app/controllers/panel/personal_journal/desktop/journal_windows_controller.rb new file mode 100644 index 0000000..52a8df0 --- /dev/null +++ b/app/controllers/panel/personal_journal/desktop/journal_windows_controller.rb @@ -0,0 +1,5 @@ +class Panel::PersonalJournal::Desktop::JournalWindowsController < ApplicationController + def journal_window + render panel_personal_journal_desktop_journal_window_path, :layout => false + end +end diff --git a/app/controllers/panel/personal_journal/desktop/plugin_intros_controller.rb b/app/controllers/panel/personal_journal/desktop/plugin_intros_controller.rb new file mode 100644 index 0000000..48d1dff --- /dev/null +++ b/app/controllers/panel/personal_journal/desktop/plugin_intros_controller.rb @@ -0,0 +1,32 @@ +class Panel::PersonalJournal::Desktop::PluginIntrosController < ApplicationController + + def index + @intro = PersonalJournalIntro.where(:user_id => current_user.id.to_s).first + if @intro.blank? + @intro = PersonalJournalIntro.new + render "new", :layout => false + else + render "edit", :layout => false + end + end + + def create + @intro = PersonalJournalIntro.new(params[:personal_journal_intro]) + @intro.user_id = current_user.id + if @intro.save + render :json => {"success" => true}.to_json + else + render :json => {"success" => false}.to_json + end + end + + def update + @intro = PersonalJournalIntro.find(params[:id]) + if @intro.update_attributes(params[:personal_journal_intro]) + render :json => {"success" => true}.to_json + else + render :json => {"success" => false}.to_json + end + end + +end \ No newline at end of file diff --git a/app/controllers/panel/personal_journal/front_end/writing_journals_controller.rb b/app/controllers/panel/personal_journal/front_end/writing_journals_controller.rb new file mode 100644 index 0000000..b63c8d8 --- /dev/null +++ b/app/controllers/panel/personal_journal/front_end/writing_journals_controller.rb @@ -0,0 +1,26 @@ +class Panel::PersonalJournal::FrontEnd::WritingJournalsController < OrbitWidgetController + + def initialize + super + @app_title = 'personal_journal' + end + + + def index + + @writing_journals = WritingJournal.where(:is_hidden => false).desc(:year, :publication_date).page(params[:page]).per(10) + + end + + # GET /writing_journals/1 + # GET /writing_journals/1.xml + def show + @writing_journal = WritingJournal.find(params[:id]) + + @journal_level_types = ( !@writing_journal.journal_level_types.blank? ? @writing_journal.journal_level_types.collect{|x| x.title}.join(', ') : nil) + @journal_author_types = ( !@writing_journal.journal_author_types.blank? ? @writing_journal.journal_author_types.collect{|x| x.title}.join(', ') : nil) + + end + + +end diff --git a/app/controllers/panel/personal_journal/plugin/writing_journals_controller.rb b/app/controllers/panel/personal_journal/plugin/writing_journals_controller.rb new file mode 100644 index 0000000..2b66073 --- /dev/null +++ b/app/controllers/panel/personal_journal/plugin/writing_journals_controller.rb @@ -0,0 +1,180 @@ +class Panel::PersonalJournal::Plugin::WritingJournalsController < OrbitBackendController + include AdminHelper + include OrbitControllerLib::DivisionForDisable + + before_filter :authenticate_user! + + before_filter :only => [ :new,:edit,:update] do |controller| + controller.get_categorys('WritingJournalCategory') + end + + def index + + get_categorys("JournalPaperType",params[:journal_paper_type_id]) + @filter = params[:filter] + new_filter = params[:new_filter] + + if @filter && params[:clear] + @filter.delete(params[:type]) + elsif @filter && new_filter + if @filter.has_key?(new_filter[:type]) && @filter[new_filter[:type]].include?(new_filter[:id].to_s) + @filter[new_filter[:type]].delete(new_filter[:id].to_s) + elsif @filter.has_key?(new_filter[:type]) + @filter[new_filter[:type]] << new_filter[:id].to_s + else + @filter.merge!({new_filter[:type] => [new_filter[:id].to_s]}) + end + elsif new_filter + @filter = {new_filter[:type] => [new_filter[:id].to_s]} + end + @paper_types = JournalPaperType.all + @paper_type_ids = @paper_types.collect{|t| t.id.to_s} + [nil] + + @level_types = JournalLevelType.all + + # @writing_journals = WritingJournal.search(params[:category_id]) + #@writing_journals = (params[:sort] || @filter) ? get_sorted_and_filtered_writing_journals : WritingJournal.all.page(params[:page]).per(10) + @writing_journals = (params[:sort] || @filter) ? get_sorted_and_filtered("writing_journal",:create_user_id => current_user.id) : get_viewable("writing_journal",:create_user_id => current_user.id) + + @tags = get_tags + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @writing_journals } + format.js + end + end + + # GET /writing_journals/1 + # GET /writing_journals/1.xml + def show + @writing_journal = WritingJournal.find(params[:id]) + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @writing_journal } + end + end + + # GET /writing_journals/new + # GET /writing_journals/new.xml + def new + + @writing_journal = WritingJournal.new + # @writing_journal_files = WritingJournalFile.all + @level_types = JournalLevelType.all + @author_types = JournalAuthorType.all + @paper_types = JournalPaperType.all + + @tags = get_tags + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @writing_journal } + end + end + + # GET /writing_journals/1/edit + def edit + @writing_journal = WritingJournal.find(params[:id]) + + @level_types = JournalLevelType.all + @author_types = JournalAuthorType.all + @paper_types = JournalPaperType.all + + @tags = get_tags + end + + # POST /writing_journals + # POST /writing_journals.xml + def create + + @level_types = JournalLevelType.all + @author_types = JournalAuthorType.all + @paper_types = JournalPaperType.all + @tags = get_tags + + @writing_journal = WritingJournal.new(params[:writing_journal]) + + @writing_journal.create_user_id = current_user.id + @writing_journal.update_user_id = current_user.id + + respond_to do |format| + if @writing_journal.save + format.html { redirect_to(panel_personal_journal_plugin_writing_journals_url) } + format.xml { render :xml => @writing_journal, :status => :created, :location => @writing_journal } + else + format.html { render :action => "new" } + format.xml { render :xml => @writing_journal.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /writing_journals/1 + # PUT /writing_journals/1.xml + def update + @writing_journal = WritingJournal.find(params[:id]) + + @writing_journal.update_user_id = current_user.id + + params[:writing_journal][:tag_ids] ||=[] + + respond_to do |format| + if @writing_journal.update_attributes(params[:writing_journal]) + format.html { redirect_to(panel_personal_journal_plugin_writing_journals_url) } + # format.js { render 'toggle_enable' } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @writing_journal.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /writing_journals/1 + # DELETE /writing_journals/1.xml + def destroy + @writing_journal = WritingJournal.find(params[:id]) + @writing_journal.destroy + + respond_to do |format| + format.html { redirect_to(panel_personal_journal_plugin_writing_journals_url) } + # format.xml { head :ok } + format.js + end + end + + def delete + if params[:ids] + writing_journals = WritingJournal.any_in(:_id => params[:ids]).destroy_all + end + redirect_to panel_personal_journal_plugin_writing_journals_url(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) + end + + protected + + + # def get_index_categories(id = nil) + # @bulletin_categorys = [] + # if(is_manager? || is_admin?) + # @bulletin_categorys = (id ? BulletinCategory.admin_manager_all.find(id).to_a : BulletinCategory.admin_manager_all) + # elsif is_sub_manager? + # @bulletin_categorys = BulletinCategory.all + # end + # @bulletin_categorys + # end + + + # def get_categorys(id = nil) + # @writing_journal_categorys = [] + # if(is_manager? || is_admin?) + # @writing_journal_categorys = (id ? WritingJournalCategory.admin_manager_all.find(id).to_a : WritingJournalCategory.admin_manager_all)) + # elsif is_sub_manager? + # @writing_journal_categorys = WritingJournalCategory.all.authed_for_user(current_user,'edit') + # end + # if @writing_journal_categorys.empty? && params[:action] != "index" + # flash[:alert] = t("announcement.error.no_avilb_cate_for_posting") + # redirect_to :action => :index + # end + # end + +end diff --git a/app/helpers/.gitkeep b/app/helpers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/helpers/panel/.gitkeep b/app/helpers/panel/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/helpers/panel/personal_journal/desktop/journal_pages_helper.rb b/app/helpers/panel/personal_journal/desktop/journal_pages_helper.rb new file mode 100644 index 0000000..785cb0c --- /dev/null +++ b/app/helpers/panel/personal_journal/desktop/journal_pages_helper.rb @@ -0,0 +1,126 @@ +module Panel::PersonalJournal::Desktop::JournalPagesHelper + def publication_record publication, view + + content_tag :li, + "item" => "true", + "data-id" => publication.id.to_s, + :class => "list_t_item #{view.blank? ? '' : "#{view}_view" } #{publication.is_hidden? ? "private" : "public" }" do + + content_tag :div, + :class => "inner" do + marker(publication.id) + \ + content(publication, view) + \ + edit_or_delete(publication) + end + end + end + + def get_height view + case view + when "journal_title" + height = "50px" + when "keywords" + height = "100px" + when "abstract" + height = "200px" + when "file" + height = "200px" + else + height = "50px" + end + height + end + + def marker id + content_tag :div, + :class => "list_item_action" do + content_tag(:a, "",:href=>"", + :class => "icon-check-empty", + "toggle-onclick"=>"icon-check-empty icon-check", + "data-id" => id.to_s, + "ajax-remote"=>"false") + \ + content_tag(:a, "",:href=>"", + :class => "icon-star-empty", + "toggle-onclick"=>"icon-star-empty icon-star", + "data-id" => id.to_s, + "ajax-remote"=>"false") + end + end + + def content publication, view + case view + when "journal_title" + des = content_tag(:div, publication.journal_title, + :class => "list_t_des") + when "keywords" + des = content_tag(:div, publication.keywords, + :class => "list_t_des") + when "abstract" + des = content_tag(:div, publication.abstract, + :class => "list_t_des") + when "file" + des = content_tag(:div, link_publication_file(publication), + :class => "list_t_des") + else + end + + content_tag(:div, publication.paper_title, + :class => "list_t_title") + des + + end + + def edit_or_delete publication + content_tag :div, + :class => "list_item_function" do + content_tag(:a, t("edit"), + :class => "journal_paper_edit admbg2 admtxt", + :href => edit_panel_personal_journal_desktop_journal_page_path(publication), + "callback-method" => "editpaper", + "ajax-remote" => "get") + \ + content_tag(:a, t(:delete_), + "ajax-remote" => "delete", + "confirm-message" => t("sure?"), + "callback-method" => "paperDelete", + "delete-item" => "true", + :class => "journal_paper_delete admbg2 admtxt", + :href => panel_personal_journal_desktop_journal_page_path(publication)) + end + end + + def link_publication_file publication + publication.writing_journal_files.map{|file| + + link_to(image_tag(check_file_type(file.file.url)) + \ + content_tag(:span, (file.title_translations[I18n.locale.to_s] rescue nil), :class => "filetitle"), + file.file.url, + :class => "file", + "target" => "_blank", + "title" => (file.title_translations[I18n.locale.to_s] rescue nil)) + }.inject(:+) + end + + def check_file_type file + if not file.nil? + x = file.split(/[\s\.]/) + file_type = x[x.length - 1] + file_type = file_type.downcase + file_type = "/assets/ft-icons/#{file_type}/#{file_type}-sm-32_32.png" + else + file_type = "" + end + end + + def generate_authors_name ids + author_name = ids.map{|m| + if m == "0" + #{:id => 0, :text => current_user.name, :email => current_user.email } + {:id => 0, :text => current_user.name} + else + #{:id => m, :text => JournalCoAuthor.find(m).co_author, :email => JournalCoAuthor.find(m).email} + {:id => m, :text => JournalCoAuthor.find(m).co_author} + end + } + + author_name.to_json + end +end diff --git a/app/mailers/.gitkeep b/app/mailers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/.gitkeep b/app/models/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/journal_author_type.rb b/app/models/journal_author_type.rb new file mode 100644 index 0000000..6715468 --- /dev/null +++ b/app/models/journal_author_type.rb @@ -0,0 +1,5 @@ +class JournalAuthorType < WritingJournalCategory + field :title, localize: true + + has_and_belongs_to_many :writing_journals +end diff --git a/app/models/journal_co_author.rb b/app/models/journal_co_author.rb new file mode 100644 index 0000000..4edf44b --- /dev/null +++ b/app/models/journal_co_author.rb @@ -0,0 +1,21 @@ +class JournalCoAuthor + include Mongoid::Document + + LANGUAGE_TYPES = [ "English", "Chinese" ] + + field :name_id, type: BSON::ObjectId + field :co_author, localize: true + field :email + + belongs_to :journal_co_author_relations + has_and_belongs_to_many :writing_journals + + VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/ + validates :email, format: { with: VALID_EMAIL_REGEX }, + allow_blank: true, + uniqueness: { case_sensitive: false } + + validates :co_author, presence: true + before_save { |coauthor| coauthor.email = email.downcase if not coauthor.email.nil?} +end + diff --git a/app/models/journal_co_author_relation.rb b/app/models/journal_co_author_relation.rb new file mode 100644 index 0000000..2218605 --- /dev/null +++ b/app/models/journal_co_author_relation.rb @@ -0,0 +1,11 @@ +class JournalCoAuthorRelation + include Mongoid::Document + include Mongoid::Timestamps + + field :relation, localize: true + + has_and_belongs_to_many :journal_co_authors + + validates :relation, presence: true, + uniqueness: { case_sensitive: false } +end diff --git a/app/models/journal_level_type.rb b/app/models/journal_level_type.rb new file mode 100644 index 0000000..d7639d1 --- /dev/null +++ b/app/models/journal_level_type.rb @@ -0,0 +1,5 @@ +class JournalLevelType < WritingJournalCategory + field :title, localize: true + + has_and_belongs_to_many :writing_journals +end diff --git a/app/models/journal_paper_type.rb b/app/models/journal_paper_type.rb new file mode 100644 index 0000000..7db2ca1 --- /dev/null +++ b/app/models/journal_paper_type.rb @@ -0,0 +1,3 @@ +class JournalPaperType < WritingJournalCategory + field :title +end diff --git a/app/models/personal_journal_intro.rb b/app/models/personal_journal_intro.rb new file mode 100644 index 0000000..ebf8996 --- /dev/null +++ b/app/models/personal_journal_intro.rb @@ -0,0 +1,4 @@ +class PersonalJournalIntro < PersonalPluginIntro + + +end diff --git a/app/models/writing_journal.rb b/app/models/writing_journal.rb new file mode 100644 index 0000000..415198b --- /dev/null +++ b/app/models/writing_journal.rb @@ -0,0 +1,126 @@ +class WritingJournal + include Mongoid::Document + include Mongoid::Timestamps + include Mongoid::MultiParameterAttributes + + include OrbitModel::LanguageRestrict + include OrbitModel::Status + include OrbitTag::Taggable + + LANGUAGE_TYPES = [ "English", "Chinese" ] + + field :paper_title, localize: true + field :journal_title, localize: true + field :authors, localize: true + + # has_and_belongs_to_many :tags, :class_name => "PersonalJournalTag" + has_and_belongs_to_many :journal_author_types + has_and_belongs_to_many :journal_level_types + has_and_belongs_to_many :journal_co_authors + has_many :writing_journal_files, :autosave => true, :dependent => :destroy + belongs_to :journal_paper_type + + field :year + field :language + field :isbn + field :vol_no + field :issue_no + field :form_to_start + field :form_to_end + field :total_pages + field :keywords + field :abstract + field :publication_date, :type => Date + field :url + field :note + field :create_user_id, :type => BSON::ObjectId + field :update_user_id, :type => BSON::ObjectId + + paginates_per 10 + + accepts_nested_attributes_for :writing_journal_files, :allow_destroy => true + after_save :save_writing_journal_files + before_validation :add_http + validates :paper_title, :at_least_one => true + validates :url, :format => /^(http|https):\/\/(([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5})|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(:[0-9]{1,5})?(\/.*)?/i, :unless => Proc.new{self.url.blank?} + + attr_reader :author_tokens + + def author_tokens=(ids) + if new_record? + current_user = create_user_id + else + current_user = update_user_id + end + authors_ids = ids.split(",").map{|id| + begin + JournalCoAuthor.find(id).id + rescue + if id != "0" + new_co_author = JournalCoAuthor.new(:co_author => id) + new_co_author.save + new_co_author.id + else + id + end + end + } + self.journal_co_author_ids = authors_ids + end + + def self.search( category_id = nil ) + if category_id.to_s.size > 0 + find(:all, :conditions => {writing_journal_category_id: category_id}).desc( :is_top, :title ) + else + find(:all).desc( :is_top, :title) + end + end + + + def self.widget_datas + where( :is_hidden => false ).desc(:is_top, :created_at) + end + + def save_writing_journal_files + self.writing_journal_files.each do |t| + if t.should_destroy + t.destroy + end + end + end + + def create_link + title = [] + + title << self.authors if self.authors.present? + + if !self.publication_date.nil? + pd = self.publication_date.strftime("%Y-%m-%d").split('-') + title << pd[0] + end + title << self.paper_title if self.paper_title.present? + title << self.journal_title if self.journal_title.present? + title << self.vol_no if (self.vol_no.present? && self.vol_no != "0") + title << self.issue_no if (self.issue_no.present? && self.issue_no != "0") + title << "pp"+self.form_to_start+"-"+self.form_to_end if (self.form_to_start.present? && self.form_to_start != "0") + title << ( !self.journal_level_types.blank? ? "(#{self.journal_level_types.collect{|x| x.title}.join(', ')})" : nil) + title.join(', ') + end + + def new_writing_journal_files=(var) + self.writing_journal_files.new(:file=>var[0]) + end + protected + + def add_http + unless self.url.blank? || self.url[/^http:\/\//] || self.url[/^https:\/\//] + self.url = 'http://' + self.url + end + end + + def clean_checkboxs + self.tagged_ids.delete('') + self.journal_author_type_ids.delete('') + self.journal_level_type_ids.delete('') + end +end diff --git a/app/models/writing_journal_category.rb b/app/models/writing_journal_category.rb new file mode 100644 index 0000000..e0ba2a4 --- /dev/null +++ b/app/models/writing_journal_category.rb @@ -0,0 +1,26 @@ +class WritingJournalCategory + include Mongoid::Document + include Mongoid::Timestamps + include OrbitCoreLib::ObjectAuthable + include OrbitCoreLib::ObjectDisable + + AfterObjectAuthUrl = '/panel/personal_journal/back_end/writing_journal_categorys' + APP_NAME = 'writing_journal' + # ObjectAuthTitlesOptions = %W{edit} + ObjectAuthTitlesOptions = %W{submit_new fact_check} + + field :key + has_many :writing_journals + + def pp_object + title + end + + def self.from_id(id) + WritingJournalCategory.find(id) rescue nil + end + + def self.is_localized?(field_name) + self.fields[field_name.to_s].localized? + end +end diff --git a/app/models/writing_journal_file.rb b/app/models/writing_journal_file.rb new file mode 100644 index 0000000..2758dca --- /dev/null +++ b/app/models/writing_journal_file.rb @@ -0,0 +1,14 @@ +class WritingJournalFile + + include Mongoid::Document + include Mongoid::Timestamps + + mount_uploader :file, AssetUploader + + field :description, localize: true + field :should_destroy, :type => Boolean + field :title, localize: true + + belongs_to :writing_journal + +end diff --git a/app/views/.gitkeep b/app/views/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/views/panel/personal_journal/back_end/writing_journal_categorys/_form.html.erb b/app/views/panel/personal_journal/back_end/writing_journal_categorys/_form.html.erb new file mode 100644 index 0000000..a9a3a77 --- /dev/null +++ b/app/views/panel/personal_journal/back_end/writing_journal_categorys/_form.html.erb @@ -0,0 +1,44 @@ +<% # encoding: utf-8 %> + +<%= form_for(:writing_journal_category, :remote => true, :url => @url, :method => @verb, :html => { :id => 'form_writing_journal_category' } ) do |f| %> + +

<%= (@writing_journal_category.new_record? ? 'Add' : 'Edit') %>

+ +
+ <%= f.label :key %> + <%= f.text_field :key %> +
+ +
+ <% if @types.is_localized?(:title) %> + <%= f.fields_for :title_translations do |f| %> + <% @site_in_use_locales.each do |locale| %> +
+ <%= label_tag "name-#{locale}", "Name-#{I18nVariable.from_locale(locale)}", :class => 'control-label' %> +
+ <%= f.text_field locale, :class => 'input-xxlarge', :value => (@writing_journal_category.title_translations[locale] rescue nil) %> +
+
+ <% end %> + <% end %> + <% else %> +
+ <%= f.label :title %> + <%= f.text_field :title %> +
+ <% end %> +
+ +
+ <%#= f.label :display %> + <%#= f.radio_button :display, "List" List%> + <%#= f.radio_button :display, "Picture" Picture%> + <%#
顯示方式是設定在前台頁面時,資訊所呈現的樣式 %> +
+ +
+ <%= f.submit t('submit'), :class=>'btn btn-primary' %> +
+ +<% end %> + \ No newline at end of file diff --git a/app/views/panel/personal_journal/back_end/writing_journal_categorys/_quick_edit_qe.html.erb b/app/views/panel/personal_journal/back_end/writing_journal_categorys/_quick_edit_qe.html.erb new file mode 100644 index 0000000..cc537cb --- /dev/null +++ b/app/views/panel/personal_journal/back_end/writing_journal_categorys/_quick_edit_qe.html.erb @@ -0,0 +1,28 @@ +<% # encoding: utf-8 %> + +
+ +
+ <%= f.label :key %> + <%= f.text_field :key %> +
+
+ <%= f.fields_for :title_translations do |f| %> + <% @site_in_use_locales.each do |locale| %> +
+ <%= label_tag "title-#{locale}", "Title-#{I18nVariable.from_locale(locale)}", :class => 'control-label' %> +
+ <%= f.text_field locale, :class => 'input-xxlarge', :value => (news_bulletin_category.title_translations[locale] rescue nil) %> +
+
+ <% end %> + <% end %> +
+ +
+ <%= f.label :display %> + <%= f.radio_button :display, "List" %>List + <%= f.radio_button :display, "Picture" %>Picture +
顯示方式是設定在前台頁面時,資訊所呈現的樣式 +
+
diff --git a/app/views/panel/personal_journal/back_end/writing_journal_categorys/_writing_journal_category.html.erb b/app/views/panel/personal_journal/back_end/writing_journal_categorys/_writing_journal_category.html.erb new file mode 100644 index 0000000..cb0fb42 --- /dev/null +++ b/app/views/panel/personal_journal/back_end/writing_journal_categorys/_writing_journal_category.html.erb @@ -0,0 +1,23 @@ + + + + <%= writing_journal_category.key %> +
+ +
+ + <% if @types.is_localized?(:title) %> + <% @site_in_use_locales.each do |locale| %> + <%= writing_journal_category.title_translations[locale] rescue nil %> + <% end %> + <% else %> + <%= writing_journal_category.title %> + <% end %> + diff --git a/app/views/panel/personal_journal/back_end/writing_journal_categorys/create.js.erb b/app/views/panel/personal_journal/back_end/writing_journal_categorys/create.js.erb new file mode 100644 index 0000000..b2d0567 --- /dev/null +++ b/app/views/panel/personal_journal/back_end/writing_journal_categorys/create.js.erb @@ -0,0 +1,2 @@ +$('<%= j render :partial => 'writing_journal_category', :collection => [@writing_journal_category] %>').appendTo('#writing_journal_categorys').hide().fadeIn(); +$("#form_writing_journal_category")[0].reset(); \ No newline at end of file diff --git a/app/views/panel/personal_journal/back_end/writing_journal_categorys/destroy.js.erb b/app/views/panel/personal_journal/back_end/writing_journal_categorys/destroy.js.erb new file mode 100644 index 0000000..19b329f --- /dev/null +++ b/app/views/panel/personal_journal/back_end/writing_journal_categorys/destroy.js.erb @@ -0,0 +1 @@ +$("#<%= dom_id @writing_journal_category %>").find(".archive_toggle").text("<%= show_toggle_archive_btn(@writing_journal_category) %> "); \ No newline at end of file diff --git a/app/views/panel/personal_journal/back_end/writing_journal_categorys/edit.html.erb b/app/views/panel/personal_journal/back_end/writing_journal_categorys/edit.html.erb new file mode 100644 index 0000000..8510eac --- /dev/null +++ b/app/views/panel/personal_journal/back_end/writing_journal_categorys/edit.html.erb @@ -0,0 +1,7 @@ +

<%= t('personal_journal.editing_personal_journal_class') %>

+ +<%= form_for @writing_journal_category, :url => panel_personal_journal_back_end_writing_journal_category_path(@writing_journal_category) do |f| %> + <%= render :partial => 'form', :locals => {:f => f} %> +<% end %> + +<%= link_back %> diff --git a/app/views/panel/personal_journal/back_end/writing_journal_categorys/edit.js.erb b/app/views/panel/personal_journal/back_end/writing_journal_categorys/edit.js.erb new file mode 100644 index 0000000..eaff01f --- /dev/null +++ b/app/views/panel/personal_journal/back_end/writing_journal_categorys/edit.js.erb @@ -0,0 +1 @@ +$("#form > form").replaceWith("<%= j render "form" %>"); \ No newline at end of file diff --git a/app/views/panel/personal_journal/back_end/writing_journal_categorys/index.html.erb b/app/views/panel/personal_journal/back_end/writing_journal_categorys/index.html.erb new file mode 100644 index 0000000..a3651d8 --- /dev/null +++ b/app/views/panel/personal_journal/back_end/writing_journal_categorys/index.html.erb @@ -0,0 +1,29 @@ + +<%= flash_messages %> + +<%= @types %> + + + + + + <% if @types.is_localized?(:title) %> + <% @site_in_use_locales.each do |locale| %> + + <% end %> + <% else %> + + <% end %> + + + + + <%= render :partial => 'writing_journal_category', :collection => @writing_journal_categorys %> + + +
<%= t('writing_journal_category.key') %><%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %><%= t('writing_journal_category.title') %>
+ +
<%= render :partial => "form" if is_manager? %>
+ + + diff --git a/app/views/panel/personal_journal/back_end/writing_journal_categorys/new.html.erb b/app/views/panel/personal_journal/back_end/writing_journal_categorys/new.html.erb new file mode 100644 index 0000000..9214f9f --- /dev/null +++ b/app/views/panel/personal_journal/back_end/writing_journal_categorys/new.html.erb @@ -0,0 +1,19 @@ +<% content_for :secondary do %> +<%= render :partial => '/panel/personal_journal/back_end/personal_journal_secondary' %> +<% end -%> + +<%= flash_messages %> + +
+
+
+
+
+ +

<%= t('writing_journal_category.new_personal_journal_class') %>

+<%= form_for @writing_journal_category, :url => panel_personal_journal_back_end_writing_journal_categorys_path do |f| %> + <%= render :partial => 'form', :locals => {:f => f} %> +<% end %> + +<%= link_back %> + diff --git a/app/views/panel/personal_journal/back_end/writing_journal_categorys/new.js.erb b/app/views/panel/personal_journal/back_end/writing_journal_categorys/new.js.erb new file mode 100644 index 0000000..40061b9 --- /dev/null +++ b/app/views/panel/personal_journal/back_end/writing_journal_categorys/new.js.erb @@ -0,0 +1 @@ +$("#form > form").replaceWith("<%= j render "form" %>"); diff --git a/app/views/panel/personal_journal/back_end/writing_journal_categorys/update.js.erb b/app/views/panel/personal_journal/back_end/writing_journal_categorys/update.js.erb new file mode 100644 index 0000000..6dd87c5 --- /dev/null +++ b/app/views/panel/personal_journal/back_end/writing_journal_categorys/update.js.erb @@ -0,0 +1,4 @@ +$("#<%= dom_id @writing_journal_category %>").replaceWith("<%= j render :partial => 'writing_journal_category', :collection => [@writing_journal_category] %>"); +<% @writing_journal_category = @types.new(:display => 'List') # reset for new form %> +$("#form_writing_journal_category").replaceWith("<%= j render "form" %>") +$("#form_writing_journal_category")[0].reset(); \ No newline at end of file diff --git a/app/views/panel/personal_journal/back_end/writing_journals/_author_type_qe.html.erb b/app/views/panel/personal_journal/back_end/writing_journals/_author_type_qe.html.erb new file mode 100644 index 0000000..33f0de0 --- /dev/null +++ b/app/views/panel/personal_journal/back_end/writing_journals/_author_type_qe.html.erb @@ -0,0 +1,34 @@ +<% # encoding: utf-8 %> + +<%= form_for(@set_author_type, :remote => true, :url => @author_type_url ) do |f| %> + + +