var anthologize = {
"src_id": null,
"new_item_org_seq_num": null,
"org_seq_num": null,
"src_seq" : {},
"fromNew": false,
"newItem": null,
"appending": false,
"callBack" : function(event, ui){
jQuery.blockUI({css:{width: '12%',top:'40%',left:'45%'},
message: jQuery('#blockUISpinner').show() });
var dest_part_id;
var dest_seq = {};
var offset = 1;
var new_item = "false";
var src_id = anthologize.src_id;
var item_id = anthologize.cleanPostIds(ui.item.attr("id"));
var project_id = anthologize.getProjectId();
var org_seq_num = anthologize.org_seq_num;
if (anthologize.fromNew){
new_item = "true";
org_seq_num = anthologize.new_item_org_seq_num;
ui.item.attr("id", "new_new_new");
}
offset = 1;
ui.item.siblings().addBack().each(function(){
dest_seq[anthologize.cleanPostIds(jQuery(this).attr("id"))] = offset;
offset++;
});
if (ui.item.hasClass("item")){
dest_id = ui.item.closest("li.part").attr("id");
// src_id is null if we didn't receive it from another list,
// so keep the parent id
if (src_id == null){
src_id = dest_id;
anthologize.src_seq = {};
}
}else{
//dest and src for parts is the project id
dest_id = project_id;
anthologize.src_id = project_id;
anthologize.src_seq = {};
}
var ajax_options = {
"project_id": project_id,
"src_id": this.cleanPostIds(src_id),
"dest_id": this.cleanPostIds(dest_id),
"new_item": new_item,
"item_id": item_id,
"org_seq_num": org_seq_num,
"dest_seq": dest_seq,
"src_seq": anthologize.src_seq
};
if (anthologize.didSortChange(ajax_options)){
anth_admin_ajax.place_item(ajax_options);
}else{
jQuery.unblockUI();
}
},
"addMultiItems": function(event, ui){
/*jQuery.blockUI({
css: {width: '12%',top:'40%',left:'45%'},
message: jQuery('#blockUISpinner').show()
});*/
var dest_seq = {};
var item_ids = [];
var project_id = anthologize.getProjectId();
var i = 0;
ui.item.after(jQuery("#sidebar-posts-clone li").clone().each(function(){
var sidePostId = jQuery(this).find("span.fromNewId").first().text();
var orig_id = anthologize.cleanPostIds(sidePostId);
var added_id = "item-" + orig_id;
jQuery(this).attr("id", added_id);
item_ids[i] = added_id;
i++;
}));
var startOffset = ui.item.next();
var dest_id = ui.item.closest("li.part").attr("id");
ui.item.detach();
offset = 1;
startOffset.siblings().andSelf().each(function(){
dest_seq[jQuery(this).attr("id")] = offset;
offset++;
});
var ajax_options = {
"project_id": project_id,
"dest_id": this.cleanPostIds(dest_id),
"item_ids": item_ids,
"dest_seq": dest_seq,
};
anth_admin_ajax.place_items(ajax_options);
},
"didSortChange" : function(ajax_options){
if (! (((ajax_options.src_id == ajax_options.dest_id) ||
(ajax_options.src_id == null && ajax_options.dest_id == ajax_options.project_id))
&& ajax_options.src_seq[ajax_options.item_id] == ajax_options.dest_seq[ajax_options.item_id])){
return true;
}else{
return false;
}
},
"initSidebar" : function(){
jQuery("#sidebar-posts li").draggable({
connectToSortable: ".part-items ul",
helper: "clone",
revert: "invalid",
zIndex: 2700,
distance: 3,
start: function(event, ui){
anthologize.new_item_org_seq_num = jQuery(this).index() + 1;
},
drag: function(event, ui){
if (anthologize.fromNew == false){
anthologize.fromNew = true;
}
}
});
jQuery("#customlinkdiv .part-header").draggable({
connectToSortable: ".part-items ul",
helper: function(){
var cloned_items = jQuery( '#sidebar-posts' ).clone().attr( 'id', 'sidebar-posts-clone' );
return cloned_items;
},
revert: "invalid",
zIndex: 2700,
distance: 3,
start: function(event, ui){
anthologize.new_item_org_seq_num = jQuery(this).index() + 1;
},
drag: function(event, ui){
if (anthologize.fromNew == false){
anthologize.fromNew = true;
}
}
});
},
"getProjectId" : function(){
return this.cleanPostIds(jQuery(".wrap").attr("id"));
},
"cleanPostIds" : function(dom_id){
var clean_id = dom_id;
if (clean_id != null){
clean_id = clean_id.replace("project-", "");
clean_id = clean_id.replace("part-", "");
clean_id = clean_id.replace("item-", "");
clean_id = clean_id.replace("new-", "");
clean_id = clean_id.replace("append-", "");
clean_id = clean_id.replace("comment-", "");
}
return clean_id;
},
"getAppendableItems" : function(item_id){
var itemInfo = {};
var part = jQuery("#" + item_id).closest("li.part");
var items = jQuery("#" + item_id).siblings();
var i = 0;
items.each(function(){
itemInfo[jQuery(this).attr("id")] = jQuery(this).find("span.part-title").text();
i++;
});
return itemInfo;
},
"getComments" : function(item_id,item){
jQuery.ajax({
url: ajaxurl,
type: 'POST',
dataType: 'json',
data: {
action:'get_item_comments',
post_id:item_id
},
async:false,
timeout:20000,
success: function(response){
if (! response){
jQuery(item).find('.comments-panel').html('
' + anth_strings.no_comments + '
');
} else {
var w = jQuery(item).find('.comment-table tbody');
for (var itemId in response){
var commentid = response[itemId].comment_ID;
if ( response[itemId].is_included ) {
var checked = ' checked="checked"';
} else {
var checked = '';
}
var comment = '
';
w.append(comment);
}
}
jQuery(".project-parts").sortable("disable");
jQuery(".part-items ul").sortable("disable");
jQuery("a.toggle").addClass("disabled");
jQuery("span.toggle-sep").addClass("disabled");
jQuery(item).removeClass("disabled");
jQuery(item).siblings().removeClass("disabled");
jQuery(item).find("a.comments").removeClass("disabled");
jQuery(item).find("span.comments-sep").removeClass("disabled");
item.find("div.comments-panel").first().slideToggle();
anthologize.appending = true;
},
error: function(){
ajax_error_refresh();
}
});
},
"updateAddedItem" : function (new_item_id,comment_count,original_id){
newItem = anthologize.newItem;
/* Multi-add items get their ids from the original post id, so we swap the selector here */
var id_selector = original_id !== false ? original_id : new_item_id;
newItem.attr("id", "item-" + id_selector);
newItem.children("h3").wrapInner('');
/* Comments are being held until 0.7 */
/*
var buttons = '
' + anth_strings.comments_explain + '
' + '' + anth_strings.select_all + ' | ' + anth_strings.select_none + '