add author filter for journal and fix some bug

This commit is contained in:
Rueshyna 2013-03-11 10:41:07 +08:00 committed by Matt K. Fu
parent 625f2e9ad6
commit bdaef3af0f
3 changed files with 189 additions and 87 deletions

View File

@ -1,117 +1,219 @@
orbitDesktop.prototype.initializeJournalPapers = function(target,url,cache){ // this init journal papers orbitDesktop.prototype.initializeJournalPapers = function(target,url,cache){ // this init journal papers
this.initializeJournalPapers.formCallback = function(data){ this.initializeJournalPapers.formCallback = function(data){
if(data.success){ if(data.success){
o.notify(data.msg,"success"); o.notify(data.msg,"success");
o.sub_menu_item($("div[content-type=menu] a").eq(0)); o.sub_menu_item($("div[content-type=menu] a").eq(0));
}else{ }else{
o.notify(data.msg,"alert"); 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 bindSecondaryHandlers = function(){
var journalData; $("#journal_p div#paper_list a.icon-check-empty").click(function(){
var bindHandlers = function(){ // to bind handlers for list page if($(this).hasClass("icon-check-empty")){
o.simple_drop_down(); $(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(){ this.initializeJournalPapers.editpaper = function(){
$("#journal_p div#paper_list a.icon-check-empty").click(function(){ o.highlight_sub_menu_item(1);
if($(this).hasClass("icon-check-empty")){ var uploadFiles = function(){
$(this).switchClass("icon-check-empty","icon-check",0); $('#add_plugin_file a.add').click(function(){
} else if($(this) .hasClass("icon-check")) { var new_id = $(this).prev().attr('value');
$(this).switchClass("icon-check","icon-check-empty",0); var old_id = new RegExp("new_writing_journal_files", "g");
} else if($(this).hasClass("icon-star")){ $(this).prev().attr('value', parseInt(new_id) + 1);
$(this).removeClass("icon-star").addClass("icon-star-empty"); var x = get_html(old_id,new_id);
} else if($(this).hasClass("icon-star-empty")){ var newfield = $(x);
$(this).removeClass("icon-star-empty").addClass("icon-star"); $(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; return markup;
}) },
} ajax: {
} url: "/panel/personal_journal/desktop/journal_pages/new.json",
this.initializeJournalPapers.paperDelete = function(data,dom){ dataType: 'json',
var parent = dom.parent().parent(); quietMillis: 100,
if(data.success){ tokenSeparators: [","],
parent.hide("slide",function(){parent.remove();}); data: function (search, page) {
o.notify(data.msg,"success"); 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(){ var preData = function(){
o.highlight_sub_menu_item(1) $("#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 uploadFiles();
var bindHandlers = function(){ // to bind handlers for add page tokesplits();
o.simple_drop_down(); preData();
$('#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.initializeJournalPapers.addpaper = function(){ // to open add pages in journal papers page
$(this).prev().attr('value', parseInt(new_id) + 1); var uploadFiles = function(){
var x = get_html(old_id,new_id); $('#add_plugin_file a.add').click(function(){
var newfield = $(x); var new_id = $(this).prev().attr('value');
$(this).parents('table').append(newfield); var old_id = new RegExp("new_writing_journal_files", "g");
newfield.find('.action a.delete').click(function(){ $(this).prev().attr('value', parseInt(new_id) + 1);
newfield.remove(); var x = get_html(old_id,new_id);
}); var newfield = $(x);
return false; $(this).parents('table').append(newfield);
newfield.find('.action a.delete').click(function(){
newfield.remove();
}); });
return false;
});
$('.action a.remove_existing_record').click(function(){ $('.action a.remove_existing_record').click(function(){
$(this).next('.should_destroy').attr('value', 1); $(this).next('.should_destroy').attr('value', 1);
$("tr#add_plugin_file_" + $(this).prev().attr('value')).hide(); $("tr#add_plugin_file_" + $(this).prev().attr('value')).hide();
}); });
}
bindHandlers();
} }
this.initializeJournalPapers.journal = function(){ // to open add pages in journal papers page console.log("hi");
var bindHandlers = function(){ // to bind handlers for add page var bindHandlers = function(){
o.simple_drop_down(); o.simple_drop_down();
}
bindHandlers();
} }
this.initializeJournalPapers.coAuthorformCallback = function(data){ var tokesplits = function(){
if(data.success){ $("#writing_journal_author_tokens").select2({
o.notify(data.msg,"success"); multiple: true,
o.sub_menu_item($("div[content-type=menu] a").eq(3)); minimumInputLength: 1,
}else{ width: "300px;",
o.notify(data.msg,"alert"); 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(); bindHandlers();
} }
this.initializeJournalPapers.coauthorRelationForm = function(data){ this.initializeJournalPapers.coauthorRelationForm = function(data){
if(data.success){ if(data.success){
o.notify(data.msg,"success"); o.notify(data.msg,"success");
$("#co_author_relation_table").html(data.newvalue); $("#co_author_relation_table").html(data.newvalue);
}else{ }else{
o.notify(data.msg,"alert"); o.notify(data.msg,"alert");
} }
} }
this.initializeJournalPapers.coauthorRelationEditForm = function(data){ this.initializeJournalPapers.coauthorRelationEditForm = function(data){
if(data.success){ if(data.success){
o.notify(data.msg,"success"); o.notify(data.msg,"success");
$("#co_author_relation_table").html(data.newvalue); $("#co_author_relation_table").html(data.newvalue);
}else{ }else{
o.notify(data.msg,"alert"); o.notify(data.msg,"alert");
} }
} }
this.initializeJournalPapers.allnone = function(d,o){ this.initializeJournalPapers.allnone = function(d,o){
switch(o.attr("href")){ switch(o.attr("href")){
case "all": case "all":
$("div.overview a.icon-check-empty").removeClass("icon-check-empty").addClass("icon-check"); $("div.overview a.icon-check-empty").removeClass("icon-check-empty").addClass("icon-check");
break; break;
case "none": case "none":
$("div.overview a.icon-check").removeClass("icon-check").addClass("icon-check-empty"); $("div.overview a.icon-check").removeClass("icon-check").addClass("icon-check-empty");
break; break;
} }
} }
}; };

View File

@ -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} %> <%= render partial: 'form', locals: {:f => f} %>
<%end%> <%end%>

View File

@ -14,7 +14,7 @@
</div> </div>
</div> </div>
<div class="overview" content-layout="datalist" base-width="300" per-column="5"> <div class="overview" content-layout="datalist" per-column="5" base-width="300">
<% @journal_lists.each_with_index do |journal_list,i| %> <% @journal_lists.each_with_index do |journal_list,i| %>
<div class="g_col"> <div class="g_col">
<ul> <ul>