From 1880ed11ca1bf29c4bc73ed5fb0b369f835ce89f Mon Sep 17 00:00:00 2001 From: Rueshyna Date: Mon, 11 Mar 2013 10:41:07 +0800 Subject: [PATCH] add author filter for journal and fix some bug --- .../personal_journal/desktop/journal_pages.js | 272 ++++++++++++------ .../desktop/journal_pages/edit.html.erb | 2 +- .../journal_pages/journal_type.html.erb | 2 +- 3 files changed, 189 insertions(+), 87 deletions(-) diff --git a/vendor/built_in_modules/personal_journal/app/assets/javascripts/personal_journal/desktop/journal_pages.js b/vendor/built_in_modules/personal_journal/app/assets/javascripts/personal_journal/desktop/journal_pages.js index 0157b4e7c..a1a769bdf 100644 --- a/vendor/built_in_modules/personal_journal/app/assets/javascripts/personal_journal/desktop/journal_pages.js +++ b/vendor/built_in_modules/personal_journal/app/assets/javascripts/personal_journal/desktop/journal_pages.js @@ -1,117 +1,219 @@ 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.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 + o.simple_drop_down(); } - this.initializeJournalPapers.list = function(){ // to open list part in journal papers page - var journalData; - var bindHandlers = function(){ // to bind handlers for list page - o.simple_drop_down(); - } + 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; + }) + } + } + this.initializeJournalPapers.paperDelete = function(data,dom){ + var parent = dom.parent().parent(); + if(data.success){ + parent.hide("slide",function(){parent.remove();}); + o.notify(data.msg,"success"); + } + } - 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"); + this.initializeJournalPapers.editpaper = function(){ + o.highlight_sub_menu_item(1); + 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).next('.should_destroy').attr('value', 1); + $("tr#add_plugin_file_" + $(this).prev().attr('value')).hide(); + }); + } + + var tokesplits = function(){ + $("#writing_journal_author_tokens").select2({ + multiple: true, + minimumInputLength: 1, + width: "300px;", + formatResult: function movieFormatResult(coAuthor) { + var markup = ""; + if (coAuthor.text !== undefined && coAuthor.email !== undefined) { + markup += coAuthor.text + " -- " + coAuthor.email; + }else if (coAuthor.email !== undefined) { + markup += coAuthor.text; } - return false; - }) - } - } - this.initializeJournalPapers.paperDelete = function(data,dom){ - var parent = dom.parent().parent(); - if(data.success){ - parent.hide("slide",function(){parent.remove();}); - o.notify(data.msg,"success"); - } + return markup; + }, + ajax: { + url: "/panel/personal_journal/desktop/journal_pages/new.json", + dataType: 'json', + quietMillis: 100, + tokenSeparators: [","], + data: function (search, page) { + return {q: search}; + }, + results: function (data, page) { + return {results: data.results}; + } + }, + }); + + $("#writing_journal_author_tokens").select2("container").find("ul.select2-choices").sortable({ + containment: 'parent', + start: function() { $("#writing_journal_author_tokens").select2("onSortStart"); }, + update: function() { $("#writing_journal_author_tokens").select2("onSortEnd"); } + }); } - this.initializeJournalPapers.editpaper = function(){ - o.highlight_sub_menu_item(1) + var preData = function(){ + $("#writing_journal_author_tokens").select2('data', JSON.parse($("#writing_journal_author_tokens").attr('data-pre'))); } - this.initializeJournalPapers.addpaper = function(){ // to open add pages in journal papers page - var bindHandlers = function(){ // to bind handlers for add page - o.simple_drop_down(); - $('#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; + uploadFiles(); + tokesplits(); + preData(); + } + + this.initializeJournalPapers.addpaper = function(){ // to open add pages in journal papers page + 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(); }); - - - $('.action a.remove_existing_record').click(function(){ - $(this).next('.should_destroy').attr('value', 1); - $("tr#add_plugin_file_" + $(this).prev().attr('value')).hide(); - }); - - } - bindHandlers(); + return false; + }); + $('.action a.remove_existing_record').click(function(){ + $(this).next('.should_destroy').attr('value', 1); + $("tr#add_plugin_file_" + $(this).prev().attr('value')).hide(); + }); } - this.initializeJournalPapers.journal = function(){ // to open add pages in journal papers page - var bindHandlers = function(){ // to bind handlers for add page - o.simple_drop_down(); - } - bindHandlers(); + console.log("hi"); + var bindHandlers = function(){ + o.simple_drop_down(); } - 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"); - } + var tokesplits = function(){ + $("#writing_journal_author_tokens").select2({ + multiple: true, + minimumInputLength: 1, + width: "300px;", + formatResult: function movieFormatResult(coAuthor) { + var markup = ""; + if (coAuthor.text !== undefined && coAuthor.email !== undefined) { + markup += coAuthor.text + " -- " + coAuthor.email; + }else if (coAuthor.email !== undefined) { + markup += coAuthor.text; + } + return markup; + }, + ajax: { + url: "/panel/personal_journal/desktop/journal_pages/new.json", + dataType: 'json', + quietMillis: 100, + tokenSeparators: [","], + data: function (search, page) { + return {q: search}; + }, + results: function (data, page) { + return {results: data.results}; + } + }, + }); + + $("#writing_journal_author_tokens").select2("container").find("ul.select2-choices").sortable({ + containment: 'parent', + start: function() { $("#writing_journal_author_tokens").select2("onSortStart"); }, + update: function() { $("#writing_journal_author_tokens").select2("onSortEnd"); } + }); + } + + bindHandlers(); + uploadFiles(); + tokesplits(); + } + + this.initializeJournalPapers.journal = function(){ // to open add pages in journal papers page + var bindHandlers = function(){ // to bind handlers for add page + o.simple_drop_down(); + } + 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 + o.simple_drop_down(); } - this.initializeJournalPapers.coauthor = function(){ // to open add pages in coauthor page - var bindHandlers = function(){ // to bind handlers for add page - o.simple_drop_down(); - } 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"); + 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"); - $("#co_author_relation_table").html(data.newvalue); - }else{ - o.notify(data.msg,"alert"); + o.notify(data.msg,"success"); + $("#co_author_relation_table").html(data.newvalue); + }else{ + o.notify(data.msg,"alert"); } } - this.initializeJournalPapers.allnone = function(d,o){ + 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; + break; case "none": $("div.overview a.icon-check").removeClass("icon-check").addClass("icon-check-empty"); - break; + break; } - } + } }; + + diff --git a/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/desktop/journal_pages/edit.html.erb b/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/desktop/journal_pages/edit.html.erb index 26b504c13..9c5fa571c 100644 --- a/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/desktop/journal_pages/edit.html.erb +++ b/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/desktop/journal_pages/edit.html.erb @@ -1,3 +1,3 @@ -<%= form_for @writing_journal, html: { multipart: true, "form-type"=>"ajax_form", "callback-method"=>"addpaper"}, url: panel_personal_journal_desktop_journal_page_path(@writing_journal) do |f| %> +<%= form_for @writing_journal, html: { multipart: true, "form-type"=>"ajax_form", "callback-method"=>"formCallback"}, url: panel_personal_journal_desktop_journal_page_path(@writing_journal) do |f| %> <%= render partial: 'form', locals: {:f => f} %> <%end%> diff --git a/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/desktop/journal_pages/journal_type.html.erb b/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/desktop/journal_pages/journal_type.html.erb index 7b440121c..055274686 100644 --- a/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/desktop/journal_pages/journal_type.html.erb +++ b/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/desktop/journal_pages/journal_type.html.erb @@ -14,7 +14,7 @@ -
+
<% @journal_lists.each_with_index do |journal_list,i| %>