function organize(base_url, public_profile, default_collection, site_notification_object) {
// set basic params
this.params = {
base_url: base_url,
public_profile: public_profile,
default_collection: default_collection,
site_notification: site_notification_object,
search: {
container: '#search-organize',
term: '#search_term',
search_in: '#search_in',
advanced_container: $("#show_advanced_search"),
button: $('#search_button')
}
};
this.layout = {
params: {
parent: this,
left: $("#left_nav"),
left_toggle: $("#left_nav_toggle"),
right: $("#right_body"),
// because the grid is created dynamically, we can't get the actual
// object until run-time, so we just store the selector
grid_selector: '.jqgrid',
states: {
wide: {
name: "wide",
interface_width: 1000,
grid_width: 1000
},
normal: {
name: "normal",
interface_width: 788,
grid_width: 788
}
},
current_state: null
},
initialize: function (show_left_nav) {
this.params.current_state = this.params.states.normal;
if (!show_left_nav && this.left_is_visible()) {
this.hide_left();
}
this.add_listeners();
},
add_listeners: function () {
this.params.left_toggle.bind('click', {'this_layout': this}, function (event) {
var this_layout = event.data.this_layout;
this_layout.toggle_left();
var visible = this_layout.left_is_visible() ? 1 : 0;
// save the visibility as a preference
$.post(this_layout.params.parent.params.base_url + "organize_services/set_left_nav_visibility", {'visible': visible}, function (data) {
}, "json");
return false;
}).bind('mouseenter', {'this_layout': this}, function (event) {
if (event.data.this_layout.left_is_visible()) {
$(this).addClass("left-arrow-hover");
} else {
$(this).addClass("right-arrow-hover");
}
}).bind('mouseleave', {'this_layout': this}, function (event) {
if (event.data.this_layout.left_is_visible()) {
$(this).removeClass("left-arrow-hover");
} else {
$(this).removeClass("right-arrow-hover");
}
});
},
get_interface_width: function () {
return this.params.current_state.interface_width;
},
get_grid_width: function () {
return this.params.current_state.grid_width;
},
left_is_visible: function () {
return (this.params.current_state === this.params.states.normal);
},
show_left: function () {
this.params.current_state = this.params.states.normal;
this.params.left.show("slide", {
direction: "left"
}, 300);
this.params.left_toggle.removeClass("right-arrow").addClass("left-arrow").attr('title', 'Collapse');
this.params.right.width(this.get_interface_width());
$(this.params.grid_selector).setGridWidth(this.get_grid_width());
},
left_is_hidden: function () {
return (this.params.current_state === this.params.states.wide);
},
hide_left: function () {
this.params.current_state = this.params.states.wide;
this.params.left.hide("slide", {
direction: "left"
}, 300);
this.params.left_toggle.removeClass("left-arrow").addClass("right-arrow").attr('title', 'Expand');
this.params.right.width(this.get_interface_width());
$(this.params.grid_selector).setGridWidth(this.get_grid_width());
},
toggle_left: function () {
this.params.left_toggle.removeClass("left-arrow-hover");
this.params.left_toggle.removeClass("right-arrow-hover");
if (this.left_is_visible()) {
this.hide_left();
} else if (this.left_is_hidden()) {
this.show_left();
}
}
};
this.lists = {};
this.display = {};
this.folders = {};
this.collections = {};
this.autocompleter_search_options = [];
this.initialize = function (left_nav_visible) {
// initialize the layout
this.layout.initialize(left_nav_visible);
// add event listeners
this.add_listeners();
};
this.add_listeners = function () {
// hashchange event
// Set up the window listeners
var last_c = null;
$(window).bind('hashchange', {'this_object': this}, function (event) {
// check if a search term exists
var search_term = event.getState('s');
if (search_term == undefined || search_term == '') {
$(event.data.this_object.params.search.term).val('');
search_term = null;
} else {
$(event.data.this_object.params.search.term).val(search_term);
}
var collection_to_load = event.getState('c');
if (collection_to_load !== last_c) {
if (typeof collection_to_load != 'undefined') {
collection_to_load = $.trim(collection_to_load);
}
switch (true) {
// load collection management
case (collection_to_load == 'mg_c'):
event.data.this_object.display.load_collection_management();
last_c = collection_to_load;
break;
// load registry management
case (collection_to_load == 'mg_r'):
last_c = collection_to_load;
break;
// if no collection was specified, load the current (last viewed) collection
case (collection_to_load == undefined):
$.bbq.pushState({"c": event.data.this_object.params.default_collection});
break;
// if the collection to load is in the current collections view, load that collection
case (event.data.this_object.collections[collection_to_load] && event.data.this_object.collections[collection_to_load].params.type == 'regular'):
// update the menu to note the current collection
event.data.this_object.lists['regular'].set_current_item(collection_to_load);
// show the collection list
event.data.this_object.lists['regular'].expand();
// hide the registry list
if (event.data.this_object.lists['registry']) {
event.data.this_object.lists['registry'].collapse();
}
// change the collection, and include the search term if it was set
event.data.this_object.display.change_collection(collection_to_load, search_term);
last_c = collection_to_load;
break;
// if the collection to load is in the current registries view, load that collection
case (event.data.this_object.collections[collection_to_load] && event.data.this_object.collections[collection_to_load].params.type == 'registry'):
// update the menu to note the current collection
event.data.this_object.lists['registry'].set_current_item(collection_to_load);
// show the registry list, if not already shown
event.data.this_object.lists['registry'].expand();
// hide the collection list
if (event.data.this_object.lists['regular']) {
event.data.this_object.lists['regular'].collapse();
}
// change the collection, and include the search term if it was set
event.data.this_object.display.change_collection(collection_to_load, search_term);
last_c = collection_to_load;
break;
// if we get here, then an invalid collection was specified - show an error message accordingly
default:
event.data.this_object.display.load_invalid_collection();
break;
}
} else if (search_term != null) {
event.data.this_object.display.get_entries_container().setPostDataItem('filters', '{"groupOp":"AND","rules":[{"field":"title","op":"cn","data":"' + search_term + '"}]}');
event.data.this_object.display.get_entries_container().setGridParam({search: true}).trigger("reloadGrid");
}
});
// Print collection
$("#print-link").bind('click', {'this_object': this}, function (event) {
window.open(event.data.this_object.params.base_url + 'organize_test/print/collection/' + event.data.this_object.display.params.collection_id);
});
// Global search
$("#search_form").live('submit', {'this_object': this}, function (event) {
event.stopPropagation();
var search_term = $(event.data.this_object.params.search.term).val();
if (search_term.length === 0) {
alert('Please enter a search term');
} else {
$("#select_none").click();
var search_in = $(event.data.this_object.params.search.search_in).val();
// if searching all items and we're in All Items, or if we're searching the current collection, then just refresh with the search results
if ((search_in == "all" && event.data.this_object.display.params.collection_id == 0) || search_in == "collection") {
$.bbq.pushState({'s': search_term});
// otherwise, we need to switch to all items, and pass in the search results
} else if (search_in == "all") {
$.bbq.pushState({'c': 0, 's': search_term});
}
}
return false;
});
$("#launch_advanced_search").live('click', {'this_object': this}, function (event) {
event.stopPropagation();
event.data.this_object.display.get_entries_container().searchGrid({multipleSearch: true});
});
$("#clear_search").live('click', {'this_object': this}, function (event) {
event.stopPropagation();
$.bbq.removeState('s');
$("#select_none").click();
event.data.this_object.display.get_entries_container().removePostDataItem('filters');
event.data.this_object.display.get_entries_container().setGridParam({search: false}).trigger("reloadGrid");
});
// Add collection
$(".add_collection_button").live('click', {'this_object': this}, function (event) {
event.data.this_object.add_collection_prompt();
});
// Define the color picker
$("#create_collection_color_picker").colorPicker();
// Submit the Add Collection form
$("#create_collection_form").live('submit', {'this_object': this}, function (event) {
var name = $("#create_collection_name").val();
var color = $("#create_collection_color_picker").val().substr(1); //trim the # from the color string
var publicity = $("#create_collection_publicity").val();
var folder = $("#create_collection_folder").val();
event.data.this_object.add_collection(name, publicity, color, folder, {}, function (data) {
if (data.success) {
if (data.success == "true") {
$("#add_collection_popup").dialog('close');
} else {
if (data.message) {
$("#create_collection_error_message").show().text(data.message);
} else {
$("#create_collection_error_message").show().text("An unknown error has occurred. Please try again.");
}
}
}
});
return false;
});
// Add folder
$(".add_folder_button").live('click', {'this_object': this}, function (event) {
event.data.this_object.add_folder_prompt();
});
// Submit the Add Folder form
$("#create_folder_form").live('submit', {'this_object': this}, function (event) {
var folder_name = $("#folder_name").val();
event.data.this_object.add_folder(folder_name, {}, function (data) {
if (data.success) {
if (data.success == "true") {
$("#add_folder_popup").dialog('close');
} else {
if (data.message) {
$("#create_folder_error_message").show().text(data.message);
} else {
$("#create_folder_error_message").show().text("An unknown error has occurred. Please try again.");
}
}
}
});
return false;
});
// entry fields
var inputFields = $('input[name="have"], input[name="want"], input[name="keep"], input[name="sell"], input[name="trade_away"], input[name="trade_for"], input[name="want_to_buy"], textarea[name="comments"], input[name="sell_price"], input[name="want_price"], input[name="grading_serial_num"], input[name="price_paid"]');
var previous_value;
inputFields.live('focus', function () {
$this = $(this);
$this.select();
// Work around Chrome's little problem
$this.mouseup(function () {
// Prevent further mouseup intervention
$this.unbind("mouseup");
return false;
});
previous_value = $(this).val();
}).live('blur', {'this_object': this}, function (event) {
var new_value = $(this).val();
if (new_value != previous_value) {
$(this).css({'border': '2px solid #FFD324'});
var row_id = $(this).closest('tr').attr('id');
var entry_ids = [row_id];
var this_obj = $(this);
event.data.this_object.update_item_field(entry_ids, $(this).attr('name'), new_value, function (data) {
if (data.success) {
if (data.success == "true") {
this_obj.css({'border': '2px solid #C6D880'});
} else {
this_obj.css({'border': '2px solid #FBC2C4'});
}
} else {
alert('An error occurred updating this entry. Please refresh the page and try again.');
}
});
}
});
$('select[name="condition"]').live('change', {'this_object': this}, function (event) {
var grid = event.data.this_object.display.get_entries_container();
var row_id = $(this).closest('tr').attr('id');
var entry_ids = [row_id];
var selected_grade_id = $(this).val();
var rowData = grid.jqGrid('getRowData', row_id);
var this_obj = $(this);
event.data.this_object.update_item_field(entry_ids, 'condition', selected_grade_id, function (data) {
if (data.success) {
if (data.success == "true") {
this_obj.css({'border': '2px solid #C6D880'});
if (rowData.conditional_value) {
$.each(entry_ids, function (index, entry_id) {
if (data['conditional_value_' + entry_id]) {
var conditional_value = data['conditional_value_' + entry_id].replace(',', '');
conditional_value = parseFloat(conditional_value);
//change by akhilesh singh
//var formatted_conditional_value = (conditional_value > 0) ? '$' + conditional_value.toFixed(2) : 'n/a';
var formatted_conditional_value = (conditional_value > 0) ? conditional_value.toFixed(2) : 'n/a';
if ((conditional_value > 0)) {
var change_rate = parseFloat(formatted_conditional_value) * parseFloat(exchange_rate);
var final_amount = currency_name + " " + currency_symbol + change_rate.toFixed(2);
formatted_conditional_value = "" + add_tool_tip(conditional_value.toFixed(2)) + final_amount.replace(/(\d)(?=(\d{3})+\.)/g, "$1,") + "";
}
//end chnage grid
grid.jqGrid('setRowData', row_id, {conditional_value: formatted_conditional_value});
}
});
}
} else {
this_obj.css({'border': '2px solid #FBC2C4'});
}
} else {
alert('An error occurred updating this entry. Please refresh the page and try again.');
}
});
});
$('.view_comment').live('click', {'this_object': this}, function (event) {
var grid = event.data.this_object.display.get_entries_container();
var row_id = $(this).closest('tr').attr('id');
var entry_ids = [row_id];
var rowData = grid.jqGrid('getRowData', row_id);
var this_obj = $(this);
event.data.this_object.view_comment(entry_ids, 'comments', function (data) {
if (data.success) {
if (data.success == "true") {
$.each(entry_ids, function (index, entry_id) {
//if(data['conditional_value_'+entry_id]) {
//var conditional_value = parseFloat(data['conditional_value_'+entry_id]);
var formatted_conditional_value = data.message;
if (formatted_conditional_value == null) {
formatted_conditional_value = '';
}
grid.jqGrid('setRowData', row_id, {comments: ''});
//}
});
} else {
this_obj.css({'border': '2px solid #FBC2C4'});
}
} else {
alert('An error occurred updating this entry. Please refresh the page and try again.');
}
});
});
$('select[name="grading_company"]').live('change', {'this_object': this}, function (event) {
var row_id = $(this).closest('tr').attr('id');
var entry_ids = [row_id];
var grading_company = $(this).val();
var this_obj = $(this);
event.data.this_object.update_item_field(entry_ids, 'grading_company', grading_company, function (data) {
if (data.success) {
if (data.success == "true") {
this_obj.css({'border': '2px solid #C6D880'});
} else {
this_obj.css({'border': '2px solid #FBC2C4'});
}
} else {
alert('An error occurred updating this entry. Please refresh the page and try again.');
}
});
});
};
this.show_response_message = function (data) {
if (data.message && data.success) {
if (data.success == "true") {
this.params.site_notification.show_only_this_message(data.message, "success");
} else if (data.success == "false") {
this.params.site_notification.show_only_this_message(data.message, "error");
}
}
};
// collection functions
this.handle_collection_response = function (data) {
var response_data = jQuery.parseJSON(data.responseText);
if (response_data.success && response_data.success == "true") {
var collection_id = response_data.collection_id;
var this_obj = organize;
switch (response_data.oper) {
case 'edit':
if (response_data.updated_attributes) {
$.each(response_data.updated_attributes, function (key, value) {
switch (key) {
case 'name':
this_obj.update_collection_name_display(collection_id, value, {'bypass_mg_c_update': true});
break;
case 'public':
this_obj.update_collection_publicity_display(collection_id, value, {'bypass_mg_c_update': true});
break;
case 'folder_id':
this_obj.update_collection_folder_display(collection_id, value, {'bypass_mg_c_update': true});
break;
}
});
}
break;
case 'del':
this_obj.remove_collection_display(collection_id, {'bypass_mg_c_update': true});
break;
}
organize.show_response_message(response_data);
return true;
} else {
organize.show_response_message(response_data);
return false;
}
};
this.add_available_collection = function (id, name, count, publicity, folder, type) {
// create a new collection object
this.collections[id] = new collection(id, name, count, publicity, folder, type);
// if it is a valid entry for the autocompleter (move to and add to), add it to those options
if (this.collections[id].is_valid_autocompleter_option()) {
var autocompleter_name = name;
if (folder != 0) {
autocompleter_name = this.folders[folder].params.name + '\\' + autocompleter_name;
}
this.autocompleter_search_options.push({label: autocompleter_name, value: id});
}
// attach event listeners to it
// clicking on the collection name will refresh the display with the new collection
var collection_container = $("#" + this.lists[type].params.container_prefix + id);
collection_container.click(function (event) {
event.stopPropagation();
$.bbq.pushState({'c': id}, 2);
});
// clicking on the public/private element will toggle its publicity
$("#" + this.lists[type].params.publicity_prefix + id).bind('click', {'this_obj': this}, function (event) {
// stop the click propagation to prevent li and body clicks
event.stopPropagation();
// determine the new publicity (0 becomes 1, 1 becomes 0)
var new_publicity = (event.data.this_obj.collections[id].params.publicity + 1) % 2;
// update the publicity
event.data.this_obj.update_collection_publicity(id, new_publicity);
});
// @TODO enable this for future release
/*if(collection_container.hasClass('can_accept_entries')) {
// make each collection container droppable to move entries to it
collection_container.droppable({
scope: 'collections',
tolerance: 'pointer',
over: function(event, ui) {
$("a", this).addClass('jstree-hover');
},
out: function(event, ui) {
$("a", this).removeClass('jstree-hover');
},
drop: function(event, ui) {
var send_data = {
'entries': organize.display.get_checked(),
'destination_collection_id': id,
'source_collection_id': organize.display.params.collection_id
};
$.post(organize.params.base_url + "organize_services/move_entries", send_data, function(data) {
if(data.success && data.success == "true") {
organize.display.update_entries();
if(data.collections_to_increment) {
$.each(data.collections_to_increment, function(key, value) {
organize.increment_collection_count(key, value);
});
}
if(data.collections_to_decrement) {
$.each(data.collections_to_decrement, function(key, value) {
organize.decrement_collection_count(key, value);
});
}
}
organize.show_response_message(data);
}, "json");
}
});
}*/
};
this.add_collection_prompt = function () {
// get the most recent list of select options
var output = [];
var unsorted_options = [];
$("#create_collection_name").val("");
$("#create_collection_color_picker").val(""); //trim the # from the color string
$("#create_collection_publicity").val("");
$("#create_collection_folder").val("");
$(".color_picker").css("background-color", "#FFFFFF");
output.push('');
$.each(this.folders, function (key, obj) {
if (obj.params.type == 'regular') {
unsorted_options.push(obj);
}
});
unsorted_options.sort(function (a, b) {
return ((a.params.name > b.params.name) ? 1 : -1)
});
$.each(unsorted_options, function (key, obj) {
output.push('');
});
$("#create_collection_folder").html(output.join(''));
// launch the modal window
$("#add_collection_popup").dialog({
width: 400,
resizable: false,
modal: true
});
return false;
};
this.add_collection = function (name, publicity, color, folder_id, display_params, callback) {
// try and create the folder on the server
var this_object = this;
$.post(this.params.base_url + "organize_services/add_collection", {'name': name, 'color': color, 'public': publicity, 'folder_id': folder_id}, function (data) {
if (callback) {
callback(data);
}
// if successful, update the folder display
if (data.success && data.success == "true") {
this_object.add_collection_display(data.collection_id, name, publicity, color, folder_id, display_params);
// error messages are shown inside the callback, so only need to show response messages on success
this_object.show_response_message(data);
}
}, "json");
};
this.add_collection_display = function (id, name, publicity, color, folder_id, passed_params) {
var params = {
'bypass_list_update': ((passed_params && passed_params.bypass_list_update) ? true : false),
'bypass_mg_c_update': ((passed_params && passed_params.bypass_mg_c_update) ? true : false),
'bypass_autocompleters_update': ((passed_params && passed_params.bypass_autocompleters_update) ? true : false)
};
// create the new folder object
var collection_obj = new collection(id, name, 0, publicity, folder_id, 'regular');
this.collections[id] = collection_obj;
// update the collections list
if (params.bypass_list_update == false) {
// create the new element on the list
this.lists[collection_obj.params.type].params.list_container.jstree("create", (folder_id ? "#" + this.lists[collection_obj.params.type].params.folder_prefix + folder_id : -1), "last", {
"attr": {
"rel": "collection",
"id": this.lists[collection_obj.params.type].params.container_prefix + id,
"class": "collection can_accept_entries",
"style": "border-bottom:1px solid #ccc;"
},
"data": name
});
// get the new element, and add a link to it, and add the count and publicity icon
var created_object = $("#" + this.lists[collection_obj.params.type].params.container_prefix + id);
if ($("> ins", created_object).css('background-image') == 'none') {
$("> ins", created_object).hide();
}
created_object.children('a').attr('class', 'coll_name').attr('href', '#c=' + id).click(function () {
$.bbq.pushState({"c": id});
});
created_object.append('
');
created_object.append('
(0)');
created_object.append('');
}
// update the autocompleters
if (params.bypass_autocompleters_update == false) {
var autocompleter_name = name;
if (folder_id != 0) {
autocompleter_name = this.folders[folder_id].params.name + '\\' + autocompleter_name;
}
this.autocompleter_search_options.push({label: autocompleter_name, value: id});
this.display.set_autocompleters();
}
// update the manage collections if it's open
if (this.display.collection_management_loaded && params.bypass_mg_c_update == false) {
this.display.load_collection_management();
}
};
this.remove_collection_prompt = function (id, display_params) {
var obj = $("#" + this.lists[this.collections[id].params.type].params.container_prefix + id);
var type = $(obj).attr('rel');
if (type == "system_collection") {
alert("System folders can not be deleted");
return false;
} else if (type == "collection" && confirm("Are you sure you want to delete this collection?")) {
this.remove_collection(id, display_params);
}
// unknown type, return false
return false;
};
this.remove_collection = function (id, display_params) {
// save an instance of the organize object
this_obj = this;
// delete the folder from the database
$.post(this.params.base_url + 'organize_services/delete_collection', {'id': id}, function (data) {
// if the delete was successful, remove it from the various points in the interface
if (data.success && data.success == "true") {
this_obj.remove_collection_display(id, display_params);
// show any success or error messages
this_obj.show_response_message(data);
} else {
// show any success or error messages
this_obj.show_response_message(data);
return false;
}
}, 'json');
};
this.remove_collection_display = function (id, passed_params) {
var params = {
'bypass_list_update': ((passed_params && passed_params.bypass_list_update) ? true : false),
'bypass_mg_c_update': ((passed_params && passed_params.bypass_mg_c_update) ? true : false),
'bypass_autocompleters_update': ((passed_params && passed_params.bypass_autocompleters_update) ? true : false)
};
// update the autocompleters
if (params.bypass_autocompleters_update == false) {
var this_object = this;
$.each(this.autocompleter_search_options, function (index, obj) {
if (obj.value == id) {
this_object.autocompleter_search_options.splice(index, 1);
this_object.display.set_autocompleters();
return false;
}
});
}
// rename the node in the list
if (params.bypass_list_update == false) {
this.lists[this.collections[id].params.type].params.list_container.jstree('delete_node', '#collection_container_' + id);
}
// if the collection is the current default collection, set the default to 0
if (this.params.default_collection == id) {
this.params.default_collection = 0;
}
// update the manage collections, or load the default collection if we're currently viewing it
if (!this.display.collection_management_loaded || (this.display.collection_management_loaded && params.bypass_mg_c_update == false)) {
this.display.reload_grid();
} else if (this.display.params.collection_id == id) {
$.bbq.pushState({"c": this.params.default_collection});
}
// remove the global collection object
delete this.collections[id];
};
this.update_collection_name = function (id, name, display_params) {
var this_obj = this;
// update the publicity in the database
$.post(this.params.base_url + "organize_services/update_collection_name", {'collection_id': id, 'name': name}, function (data) {
if (data.success && data.success == "true") {
// if successful, also update the display
this_obj.update_collection_name_display(id, name, display_params);
} else {
// if not succesful, revert the change
this_obj.update_collection_name_display(id, this_obj.collections[id].params.name, {});
}
this_obj.show_response_message(data);
}, "json");
};
this.update_collection_name_display = function (id, name, passed_params) {
var params = {
'bypass_list_update': ((passed_params && passed_params.bypass_list_update) ? true : false),
'bypass_mg_c_update': ((passed_params && passed_params.bypass_mg_c_update) ? true : false),
'bypass_autocompleters_update': ((passed_params && passed_params.bypass_autocompleters_update) ? true : false)
};
// update the global collection object
this.collections[id].params.name = name;
// update the autocompleters
if (params.bypass_autocompleters_update == false) {
var this_object = this;
$.each(this.autocompleter_search_options, function (index, obj) {
if (obj.value == id) {
var autocompleter_name = name;
if (this_object.collections[id].params.folder != 0) {
autocompleter_name = this.folders[this_object.collections[id].params.folder].params.name + '\\' + autocompleter_name;
}
this_object.autocompleter_search_options[index] = {
'value': id,
'label': autocompleter_name
};
this_object.display.set_autocompleters();
return false;
}
});
}
// rename the node in the list
if (params.bypass_list_update == false) {
this.lists[this.collections[id].params.type].params.list_container.jstree('rename_node', '#collection_container_' + id, name);
}
$("#" + this.lists[this.collections[id].params.type].params.container_prefix + id).effect("highlight", {}, 3000);
// update the manage collections or current collection listing
if (this.display.collection_management_loaded && params.bypass_mg_c_update == false) {
this.display.reload_grid();
} else if (this.display.params.collection_id == id) {
$("#currently_viewing").text(name).effect("highlight", {}, 3000);
if (this.display.params.show_tags) {
this.display.reload_grid();
}
}
};
this.increment_collection_count = function (id, amount_to_increment_by, display_params) {
var count = this.collections[id].params.count += parseInt(amount_to_increment_by);
this.update_collection_count_display(id, count, display_params);
}
this.decrement_collection_count = function (id, amount_to_decrement_by, display_params) {
var count = this.collections[id].params.count -= parseInt(amount_to_decrement_by);
count = (count < 0) ? 0 : count;
this.update_collection_count_display(id, count, display_params);
}
this.update_collection_count_display = function (id, count, passed_params) {
var params = {
'bypass_list_update': ((passed_params && passed_params.bypass_list_update) ? true : false)
};
// update the global collection object
this.collections[id].params.count = count;
// rename the node in the list
if (params.bypass_list_update == false) {
$("#" + this.lists[this.collections[id].params.type].params.count_prefix + id).text(count);
}
$("#" + this.lists[this.collections[id].params.type].params.container_prefix + id).effect("highlight", {}, 3000);
};
this.update_collection_folder = function (id, folder_id, display_params) {
var this_obj = this;
// update the publicity in the database
$.post(this.params.base_url + "organize_services/update_collection_inline", {'id': id, 'folder_id': folder_id}, function (data) {
if (data.success && data.success == "true") {
// if successful, also update the display
this_obj.update_collection_folder_display(id, folder_id, display_params);
}
this_obj.show_response_message(data);
}, "json");
};
this.update_collection_folder_display = function (id, folder_id, passed_params) {
var params = {
'bypass_list_update': ((passed_params && passed_params.bypass_list_update) ? true : false),
'bypass_mg_c_update': ((passed_params && passed_params.bypass_mg_c_update) ? true : false),
'bypass_autocompleters_update': ((passed_params && passed_params.bypass_autocompleters_update) ? true : false)
};
// update the global collection object
this.collections[id].params.folder = folder_id;
// set the icon to public or private based on the selected mode
if (params.bypass_list_update == false) {
var destination_folder = (folder_id == 0) ? -1 : "#folder_" + folder_id;
this.lists[this.collections[id].params.type].params.list_container.jstree('move_node', '#collection_container_' + id, destination_folder, "last", false, false, true);
}
$("#" + this.lists[this.collections[id].params.type].params.container_prefix + id).effect("highlight", {}, 3000);
// update the autocompleters
if (params.bypass_autocompleters_update == false) {
var this_object = this;
$.each(this.autocompleter_search_options, function (index, obj) {
if (obj.value == id) {
var autocompleter_name = this_object.collections[id].params.name;
if (folder_id != 0) {
autocompleter_name = this_object.folders[folder_id].params.name + '\\' + autocompleter_name;
}
this_object.autocompleter_search_options[index] = {
'value': id,
'label': autocompleter_name
};
this_object.display.set_autocompleters();
return false;
}
});
}
// update the manage collections listing
if (this.display.collection_management_loaded && params.bypass_mg_c_update == false) {
this.display.reload_grid();
}
};
this.update_collection_publicity = function (id, publicity, display_params) {
var this_obj = this;
// update the publicity in the database
$.post(this.params.base_url + "organize_services/update_collection_publicity", {'collection_id': id, 'publicity': publicity}, function (data) {
if (data.success && data.success == "true") {
// if successful, also update the display
this_obj.update_collection_publicity_display(id, publicity, display_params);
}
this_obj.show_response_message(data);
}, "json");
};
this.update_collection_publicity_display = function (id, publicity, passed_params) {
var params = {
'bypass_list_update': ((passed_params && passed_params.bypass_list_update) ? true : false),
'bypass_mg_c_update': ((passed_params && passed_params.bypass_mg_c_update) ? true : false)
};
// update the global collection object
this.collections[id].params.publicity = publicity;
// set the icon to public or private based on the selected mode
if (params.bypass_list_update == false) {
if (publicity == 1) {
$("#" + this.lists[this.collections[id].params.type].params.publicity_prefix + id).html("");
} else {
$("#" + this.lists[this.collections[id].params.type].params.publicity_prefix + id).html("");
}
}
// update the manage collections listing
if (this.display.collection_management_loaded && params.bypass_mg_c_update == false) {
this.display.reload_grid();
}
};
// folder functions
this.add_available_folder = function (id, name) {
this.folders[id] = new folder(id, name);
};
this.add_folder_prompt = function () {
$("#folder_name").val("");
$("#add_folder_popup").dialog({
width: 400,
resizable: false,
modal: true
});
return false;
};
this.add_folder = function (name, display_params, callback) {
// try and create the folder on the server
var this_object = this;
$.post(this.params.base_url + "organize_services/add_folder", {'name': name}, function (data) {
if (callback) {
callback(data);
}
// if successful, update the folder display
if (data.success && data.success == "true") {
this_object.add_folder_display(data.new_folder_id, data.new_folder_name, display_params);
// error messages are shown inside the callback, so only need to show response messages on success
this_object.show_response_message(data);
}
}, "json");
};
this.add_folder_display = function (id, name, passed_params) {
var params = {
'bypass_list_update': ((passed_params && passed_params.bypass_list_update) ? true : false),
'bypass_mg_c_update': ((passed_params && passed_params.bypass_mg_c_update) ? true : false)
};
// create the new folder object
var folder_obj = new folder(id, name);
this.folders[id] = folder_obj;
// update the collections list
if (params.bypass_list_update == false) {
this.lists[folder_obj.params.type].params.list_container.jstree("create", -1, "last", {
"attr": {
"rel": "folder",
"id": this.lists[folder_obj.params.type].params.folder_prefix + id,
"class": "folder"
},
"data": name
});
}
// update the manage collections if it's open
if (this.display.collection_management_loaded && params.bypass_mg_c_update == false) {
this.display.load_collection_management();
}
}
this.remove_folder_prompt = function (id, display_params) {
// get the folder object
var folder = this.folders[id];
if (folder) {
// check if there are children collections in this folder
var children = jQuery.jstree._reference(this.lists[folder.params.type].params.list_container)._get_children(document.getElementById('folder_' + id));
// if there are collections inside the folder, confirm they want to delete them as well
if (children.length && confirm("Warning: deleting this folder will also delete all collections inside of it. Are you sure you wish to remove this folder?")) {
this.remove_folder(id, children, display_params);
} else if (!children.length && confirm("Are you sure you want to delete this folder?")) {
this.remove_folder(id, false, display_params);
}
}
};
this.remove_folder = function (id, children, display_params) {
// save an instance of the organize object
var this_obj = this;
// delete the folder from the database
$.post(this.params.base_url + 'organize_services/delete_folder', {'id': id}, function (data) {
// if the delete was successful, remove it from the various points in the interface
if (data.success && data.success == "true") {
this_obj.remove_folder_display(id, children, display_params);
// show any success or error messages
this_obj.show_response_message(data);
} else {
// show any error messages
this_obj.show_response_message(data);
return false;
}
}, 'json');
};
this.remove_folder_display = function (id, children, passed_params) {
var params = {
'bypass_list_update': ((passed_params && passed_params.bypass_list_update) ? true : false),
'bypass_mg_c_update': ((passed_params && passed_params.bypass_mg_c_update) ? true : false)
};
// remove the children from the display
if (children.length) {
var this_object = this;
$.each(children, function (index, value) {
var child_id = $(value).attr('id').substr(this_object.lists['regular'].params.container_prefix.length);
this_object.remove_collection_display(child_id, {'bypass_list_update': true, 'bypass_mg_c_update': true});
});
}
// if the default collection is a child of the deleted folder, set the default collection to 0
if (this.collections[this.params.default_collection].params.folder == id) {
this.params.default_collection = 0;
}
// if Collections Management or a collection that was inside the deleted folder is loaded, then refresh the display
if (this.display.collection_management_loaded && params.bypass_mg_c_update == false) {
this.display.load_collection_management();
} else if (children && this.collections[this.display.params.collection_id].params.folder == id) {
$.bbq.pushState({"c": this.params.default_collection});
}
// remove the folder from the listing tree
if (params.bypass_list_update == false) {
this.lists[this.folders[id].params.type].params.list_container.jstree('delete_node', '#folder_' + id);
}
// remove the object from the master folder list
delete this.folders[id];
};
this.update_folder_name = function (id, name, display_params) {
var this_obj = this;
// update the publicity in the database
$.post(this.params.base_url + "organize_services/update_folder_name", {'folder_id': id, 'name': name}, function (data) {
if (data.success && data.success == "true") {
// if successful, also update the display
this_obj.update_folder_name_display(id, name, display_params);
} else {
// if not succesful, revert the change
this_obj.update_folder_name_display(id, this_obj.folders[id].params.name, {});
}
this_obj.show_response_message(data);
}, "json");
};
this.update_folder_name_display = function (id, name, passed_params) {
var params = {
'bypass_list_update': ((passed_params && passed_params.bypass_list_update) ? true : false),
'bypass_mg_c_update': ((passed_params && passed_params.bypass_mg_c_update) ? true : false),
'bypass_autocompleters_update': ((passed_params && passed_params.bypass_autocompleters_update) ? true : false)
};
// update the global folders object
this.folders[id].params.name = name;
// rename the node in the list
if (params.bypass_list_update == false) {
this.lists[this.folders[id].params.type].params.list_container.jstree('rename_node', '#folder_' + id, name);
}
$("#folder_" + id).effect("highlight", {}, 3000);
// update the autocompleters
if (params.bypass_autocompleters_update == false) {
var this_object = this;
$.each(this.autocompleter_search_options, function (index, obj) {
if (this_object.collections[obj.value].params.folder == id) {
var autocompleter_name = name + '\\' + this.collections[obj.value].params.name;
this_object.autocompleter_search_options[index] = {
'value': obj.value,
'label': autocompleter_name
};
this_object.display.set_autocompleters();
return false;
}
});
}
// update the manage collections if it's open
if (this.display.collection_management_loaded && params.bypass_mg_c_update == false) {
this.display.load_collection_management();
}
};
// item functions
this.duplicate_item = function (id, collection_id, display_params) {
var this_obj = this;
// update the publicity in the database
$.post(this.params.base_url + "organize_services/duplicate_entries", {'entries': id, 'collection_id': collection_id}, function (data) {
if (data.success && data.success == "true") {
// if successful, also update the display
this_obj.duplicate_item_display(id, collection_id, display_params);
}
this_obj.show_response_message(data);
}, "json");
};
this.duplicate_item_display = function (id, collection_id, passed_params) {
var params = {
'bypass_list_update': ((passed_params && passed_params.bypass_list_update) ? true : false),
'bypass_display_update': ((passed_params && passed_params.bypass_mg_c_update) ? true : false)
};
// update the count on the display
if (params.bypass_list_update == false) {
this.update_collection_count_display(collection_id, (this.collections[collection_id].params.count + 1));
}
// update the manage collections if it's open
if (this.display.params.collection_id == collection_id && params.bypass_display_update == false) {
this.display.update_entries();
}
};
this.update_item_field = function (entry_ids, field, new_value, callback) {
var post_data = {
'entry_ids': entry_ids,
'field': field,
'new_value': new_value
};
if (entry_ids == "all") {
post_data['collection_id'] = this.display.params.collection_id;
}
$.post(this.params.base_url + 'organize_services/update_entries', post_data, function (data) {
if (callback)
callback(data);
}, 'json');
};
this.view_comment = function (entry_ids, field, callback) {
var post_data = {
'entry_ids': entry_ids,
'field': field,
};
$.post(this.params.base_url + 'organize_services/view_comments', post_data, function (data) {
if (callback)
callback(data);
}, 'json');
};
this.remove_entry_from_collection = function (entry_id, collection_id) {
if (confirm("Are you sure you want to remove this item from this collection?")) {
var this_obj = this;
// remove the entry from the collection in the DB
$.post(this.params.base_url + "organize_services/remove_entries_from_collection", {'entries': entry_id, 'collection_id': collection_id}, function (data) {
if (data.success && data.success == "true") {
this_obj.display.update_entries();
if (data.collections_to_decrement) {
$.each(data.collections_to_decrement, function (key, value) {
this_obj.decrement_collection_count(key, value);
});
}
$("#select_none").click();
}
this_obj.show_response_message(data);
}, "json");
}
};
// image gallery methods
this.launch_image_gallery = function (entry_id) {
$("#image_gallery_popup").load(this.params.base_url + 'image_gallery/entry/' + entry_id + '/true/', function () {
$("#image_gallery_popup").dialog({
width: 700,
modal: true,
open: function (event, ui) {
$('.ui-dialog-titlebar-close').removeAttr('style');
},
close: function (event, ui) {
$(document).unbind('keydown');
}
});
});
};
}
function display(organize_object, user_id, view, collection_layout, registry_layout, show_tags) {
if (!$)
alert('Global jQuery object is required to use the display class');
this.organize = organize_object;
this.site_notification = this.organize.params.site_notification;
this.params = {
"user_id": user_id,
"collection_id": null,
"view": view,
"collection_layout": collection_layout,
"registry_layout": registry_layout,
"public": this.organize.params.public_profile,
"show_tags": show_tags
};
this.collection_management_loaded = false;
this.container = $("#collection_display");
this.entries_container_selector = "#collection_entries";
this.get_entries_container = function () {
return $(this.entries_container_selector);
}
this.loading_div = $("#loadingDiv");
this.initialize = function () {
this.add_listeners();
}
this.add_listeners = function () {
// BEGIN Manage Collections listeners
// Action that happens when you change the value of a color picker
$(".colorPicker").live('change', {'this_object': this}, function (event) {
var collection_id = $(this).attr('id').substring("collection_color_".length);
var color = $(this).val().substring(1);
$.post(event.data.this_object.organize.params.base_url + "organize_services/update_collection_color", {'collection_id': collection_id, 'color': color}, function (data) {
event.data.this_object.organize.show_response_message(data);
}, "json");
});
// END Manage Collections listeners
// BEGIN Collections listeners
// Select Collection
$("#select_collection").live('click', {'this_object': this}, function (event) {
event.stopPropagation();
event.data.this_object.select_all_items();
$("#select_collection_warning_count").text(event.data.this_object.organize.collections[event.data.this_object.params.collection_id].params.count);
$("#select_collection_warning").show();
$("#entries_select_checkbox").attr('checked', true);
$("#all_entries_selected").attr('checked', true);
});
// Select Page
$("#select_page").live('click', {'this_object': this}, function (event) {
event.stopPropagation();
event.data.this_object.select_all_items();
$("#select_collection_warning").hide();
$("#entries_select_checkbox").attr('checked', true);
$("#all_entries_selected").attr('checked', false);
});
// Select None
$("#select_none").live('click', {'this_object': this}, function (event) {
event.stopPropagation();
event.data.this_object.deselect_all_items();
$("#select_collection_warning").hide();
$("#entries_select_checkbox").attr('checked', false);
$("#all_entries_selected").attr('checked', false);
});
// Clicking on the "Select" checkbox toggles between Select Page and Select None
$("#entries_select_checkbox").live('click', {'this_object': this}, function (event) {
event.stopPropagation();
if ($(this).is(":checked")) {
$("#select_page").click();
} else {
$("#select_none").click();
}
});
// Action that happens when you click the "Send to Trash" button
$("#send_to_trash").live('click', {'this_object': this}, function (event) {
if (event.data.this_object.count_checked() && confirm("Are you sure you want to send these items to the Trash?")) {
var entries = $("#all_entries_selected").is(":checked") ? 'all' : event.data.this_object.get_checked();
var this_object = event.data.this_object;
var send_trash_value = $("
Deleting data..
");
send_trash_value.dialog({
width: 150,
height: 100,
title: 'Please Wait..',
resizable: false,
modal: true,
closeOnEscape: false,
dialogbeforeclose: false,
draggable: false,
resizable: false
});
send_trash_value.dialog('open');
$.post(this_object.organize.params.base_url + "organize_services/move_entries_to_trash", {'entries': entries, 'source_collection_id': this_object.params.collection_id}, function (data) {
if (data.success && data.success == "true") {
this_object.update_entries();
if (data.collections_to_increment) {
$.each(data.collections_to_increment, function (key, value) {
this_object.organize.increment_collection_count(key, value);
});
}
if (data.collections_to_decrement) {
$.each(data.collections_to_decrement, function (key, value) {
this_object.organize.decrement_collection_count(key, value);
});
}
$("#select_none").click();
}
this_object.organize.show_response_message(data);
send_trash_value.dialog('close');
}, "json");
}
});
// Action that happens when you click the "Permanently Delete Selected Items" button
$("#delete_selected").live('click', {'this_object': this}, function (event) {
var this_object = event.data.this_object;
if (this_object.count_checked() && confirm("Are you sure you want to permanently delete these items?")) {
var entries = $("#all_entries_selected").is(":checked") ? 'all' : this_object.get_checked();
$.post(this_object.organize.params.base_url + "organize_services/delete_entries", {'entries': entries}, function (data) {
if (data.success && data.success == "true") {
this_object.update_entries();
if (data.collections_to_decrement) {
$.each(data.collections_to_decrement, function (key, value) {
this_object.organize.decrement_collection_count(key, value);
});
}
}
this_object.organize.show_response_message(data);
}, "json");
}
});
// Action that happens when you click the "Empty Trash" button
$("#empty_trash").live('click', {'this_object': this}, function (event) {
var this_object = event.data.this_object;
if (confirm("This will permanently delete all items in Trash from your Organize. Are you sure you want to continue?")) {
var empty_trash_loader = $("
Deleting data..
");
empty_trash_loader.dialog({
width: 150,
height: 100,
title: 'Please Wait..',
resizable: false,
modal: true,
closeOnEscape: false,
dialogbeforeclose: false,
draggable: false,
resizable: false
});
empty_trash_loader.dialog('open');
$.post(this_object.organize.params.base_url + "organize_services/empty_trash", function (data) {
if (data.success && data.success == "true") {
this_object.update_entries();
if (data.collections_to_decrement) {
$.each(data.collections_to_decrement, function (key, value) {
this_object.organize.decrement_collection_count(key, value);
});
}
}
this_object.organize.show_response_message(data);
var empty_trash_div = $("");
empty_trash_div.dialog({
width: 500,
height: 50,
title: 'Thanks',
resizable: false,
modal: true,
closeOnEscape: false,
dialogbeforeclose: false,
draggable: false,
resizable: false
});
empty_trash_div.dialog('open').html(data.message);
empty_trash_loader.dialog('close');
}, "json");
}
});
// Action that happens when you click the "Send to Trash" button
$("#launch").live('click', {'this_object': this}, function (event) {
var confirm_msg = 'Are you sure you want to launch these items on eBay? By using the Beckett SuperSeller launcher you understand that Beckett SuperSeller only creates the listings and you are responsible for any shipping, communication, final value fees, etc. for those items.';
if ($(this).html() === 'Revise/Add') {
confirm_msg = 'Are you sure you want to revise these items on eBay?';
}
if (event.data.this_object.count_checked() && confirm(confirm_msg)) {
$('#ebay_launch_warning').html('').hide();
var entries = $("#all_entries_selected").is(":checked") ? 'all' : event.data.this_object.get_checked();
var this_object = event.data.this_object;
if (entries.length > 0) {
var entry_ids = [];
var error_entry_ids = [];
var item_id, ebay_card_desc, available_qty, launched_qty, bss_trade_away_qty, ebay_fixed_price, use_stock_photo, ebay_card_condition, listing_duration, ebay_category, ebay_store_category;
var isValidated = true;
var isRowValidated = true;
var flashMsg = '';
$.each(entries, function (i) {
isRowValidated = true;
flashMsg = '';
if ($('#jqg_collection_entries_' + entries[i]).is(':checked')) {
$('tr#' + entries[i]).find('td').each(function () {
$(this).removeClass('red');
});
item_id = $('#' + entries[i]).find('td input[type="hidden"][name="item_id"]').val();
ebay_card_desc = $('#' + entries[i]).find('td textarea[name="ebay_card_description"]').val();
available_qty = parseInt($('#' + entries[i]).find('td input[type="text"][name="available_quantity"]').val());
launched_qty = parseInt($('#' + entries[i]).find('td input[type="text"][name="launched_quantity"]').val());
use_stock_photo = 0;
if ($('#' + entries[i]).find('td input[type="checkbox"][name="use_stock_photo"]').is(':checked')) {
use_stock_photo = 1;
}
bss_trade_away_qty = parseInt($('#' + entries[i]).find('td input[type="text"][name="bss_trade_away"]').val());
ebay_fixed_price = $.trim($('#' + entries[i]).find('td input[type="text"][name="ebay_fixed_price"]').val());
ebay_card_condition = $('#' + entries[i]).find('td select[name="ebay_card_condition"]').val();
listing_duration = $('#' + entries[i]).find('td select[name="ebay_listing_duration"]').val();
ebay_category = $('#' + entries[i]).find('td select[name="ebay_category"]').val();
ebay_store_category = $('#' + entries[i]).find('td select[name="ebay_store_category"]').val();
if (ebay_card_desc == '') {
isRowValidated = false;
flashMsg = 'The Card Description must be exist';
} else if (ebay_card_desc.length > 80) {
isRowValidated = false;
flashMsg = 'The Card Description must be less than 80 characters';
} else if (available_qty <= 0 || isNaN(available_qty)) {
isRowValidated = false;
flashMsg = 'The Available Quantity must be greater than 0';
} else if (launched_qty <= 0 || isNaN(launched_qty)) {
isRowValidated = false;
flashMsg = 'The Ebay Quantity must be greater than 0';
} else if (launched_qty > available_qty) {
isRowValidated = false;
flashMsg = 'The Ebay Quantity must be less than or equal to Available Quantity';
} else if (ebay_fixed_price == '') {
isRowValidated = false;
flashMsg = 'The Price field can\'t be left blank';
} else if (isNaN(ebay_fixed_price) || ebay_fixed_price < 1) {
isRowValidated = false;
flashMsg = 'The Price should be minimum $1';
} else if (ebay_category == '') {
isRowValidated = false;
flashMsg = 'The Ebay Category must be selected';
}
if (isRowValidated) {
entry_ids.push({'entry_id': entries[i], 'item_id': item_id, 'ebay_card_desc': ebay_card_desc, 'available_qty': available_qty, 'launched_qty': launched_qty, 'trade_away_qty': bss_trade_away_qty, 'ebay_fixed_price': ebay_fixed_price, 'use_stock_photo': use_stock_photo, 'ebay_card_condition': ebay_card_condition, 'listing_duration': listing_duration, 'ebay_category': ebay_category, 'ebay_store_category': ebay_store_category, 'ebay_queue_status': 1});
} else {
isValidated = false;
error_entry_ids.push({'entry_id': entries[i], 'roc_msg': flashMsg});
}
}
});
if (isValidated) {
$.each(entries, function (i) {
$('tr#' + entries[i]).find('td').each(function () {
$(this).removeClass('red');
});
});
var launch_loader = $("
Launching the data..
");
launch_loader.dialog({
width: 150,
height: 100,
title: 'Please Wait..',
resizable: false,
modal: true,
open: function (event, ui) {
$('.ui-dialog-titlebar-close').css('display', 'none');
},
closeOnEscape: false,
dialogbeforeclose: false,
draggable: false,
resizable: false
});
launch_loader.dialog('open');
$.post(this_object.organize.params.base_url + "organize_services/launch_items_to_ebay", {'entry_ids': entry_ids, 'source_collection_id': this_object.params.collection_id}, function (data) {
if (data.success && data.success == "true") {
this_object.update_entries();
if (data.collections_to_increment) {
$.each(data.collections_to_increment, function (key, value) {
this_object.organize.increment_collection_count(key, value);
});
}
if (data.collections_to_decrement) {
$.each(data.collections_to_decrement, function (key, value) {
this_object.organize.decrement_collection_count(key, value);
});
}
$("#select_none").click();
} else {
if (data.error_entry_ids) {
if (data.error_entry_ids.length > 0) {
var roc_msg = '
Record ' + (i + 1) + ' - ' + error_entry_ids[i].roc_msg + '
';
});
roc_msg += '
';
$('#ebay_launch_warning').html(roc_msg).show();
this_object.site_notification.show_only_this_message('Please fill the valid details', "error");
}
}
}
});
// Action that happens when you click the "Send to Trash" button
$("#end_ebay_items").live('click', {'this_object': this}, function (event) {
if (event.data.this_object.count_checked() && confirm("Are you sure you want to end these items on ebay?One item will be end it will be be moved to eBay Items-Expired collection.")) {
var entries = $("#all_entries_selected").is(":checked") ? 'all' : event.data.this_object.get_checked();
var this_object = event.data.this_object;
var end_ebay_value = $("
Ending the data..
");
end_ebay_value.dialog({
width: 150,
height: 100,
title: 'Please Wait..',
resizable: false,
modal: true,
closeOnEscape: false,
dialogbeforeclose: false,
draggable: false,
resizable: false
});
end_ebay_value.dialog('open');
$.post(this_object.organize.params.base_url + "organize_services/end_ebay_items", {'entries': entries, 'source_collection_id': this_object.params.collection_id}, function (data) {
if (data.success && data.success == "true") {
this_object.update_entries();
if (data.collections_to_increment) {
$.each(data.collections_to_increment, function (key, value) {
this_object.organize.increment_collection_count(key, value);
});
}
if (data.collections_to_decrement) {
$.each(data.collections_to_decrement, function (key, value) {
this_object.organize.decrement_collection_count(key, value);
});
}
$("#select_none").click();
}
this_object.organize.show_response_message(data);
end_ebay_value.dialog('close');
}, "json");
}
});
$('#toggle_tags').live('click', {'this_object': this}, function (event) {
var this_object = event.data.this_object;
$(this).text('Loading...');
if (this_object.params.show_tags == 1) {
this_object.params.show_tags = 0;
this_object.get_entries_container().setPostDataItem('show_tags', 'false');
this_object.reload_grid();
$(this).text('Show Tags');
} else {
this_object.params.show_tags = 1;
this_object.get_entries_container().setPostDataItem('show_tags', 'true');
this_object.reload_grid();
$(this).text('Hide Tags');
}
// save the tag visibility as a preference
$.post(this_object.organize.params.base_url + "organize_services/set_tag_visibility_preference", {'show_tags': this_object.params.show_tags}, function (data) {
}, "json");
return false;
});
// Actions to handle toggling the submenus off
$('body').click(function () {
$(".entries_expanded_content").css({visibility: 'hidden'});
});
$(".entries_button").live('click', {'this_object': this}, function (event) {
event.stopPropagation();
if ($(this).hasClass('expands')) {
var my_id = $(this).attr('id');
var my_expanded_field = $(".entries_expanded_content[rel='" + my_id + "']");
if (!$(this).hasClass('requires_checked') || ($(this).hasClass('requires_checked') && event.data.this_object.count_checked())) {
if (my_expanded_field.css('visibility') == 'hidden') {
$('body').click();
var os = $(this).offset();
var height = $(this).height();
my_expanded_field.offset({top: (os.top + height + 3), left: (os.left + 3)}).css({visibility: 'visible'});
my_expanded_field.children('.collection_search').focus();
} else {
my_expanded_field.css({visibility: 'hidden'});
}
}
}
});
$(".collection_search").live('focus', function () {
$(this).keydown();
});
$(".collection_search").live('click', function (event) {
event.stopPropagation();
});
// Action that happens when you click the "Send to Trash" button
$("#send_to_trash_collection").live('click', {'this_object': this}, function (event) {
if (confirm("Are you sure you want to send these items to the Trash?")) {
var entries = 'all';
var this_object = event.data.this_object;
var send_trash_value = $("
processing..
");
send_trash_value.dialog({
width: 150,
height: 100,
title: 'Please Wait..',
resizable: false,
modal: true,
closeOnEscape: false,
dialogbeforeclose: false,
draggable: false,
resizable: false
});
send_trash_value.dialog('open');
$.post(this_object.organize.params.base_url + "organize_services/move_collection_entries_to_trash", {'entries': entries, 'source_collection_id': this_object.params.collection_id}, function (data) {
if (data.success && data.success == "true") {
this_object.update_entries();
if (data.collections_to_increment) {
$.each(data.collections_to_increment, function (key, value) {
this_object.organize.increment_collection_count(key, value);
});
}
if (data.collections_to_decrement) {
$.each(data.collections_to_decrement, function (key, value) {
this_object.organize.decrement_collection_count(key, value);
});
}
$("#select_none").click();
}
this_object.organize.show_response_message(data);
send_trash_value.dialog('close');
}, "json");
}
});
// END Collection listeners
}
this.change_collection = function (collection_id, search_term) {
this.params.collection_id = collection_id;
this.update_entries(search_term);
};
this.change_view = function (view, search_term) {
this.params.view = view;
this.update_entries(search_term);
};
this.change_layout = function (layout, type, search_term) {
if (type === 'REGULAR') {
this.params.collection_layout = layout;
this.update_entries(search_term);
} else if (type === 'REGISTRY') {
this.params.registry_layout = layout;
this.update_entries(search_term);
}
};
this.update_entries = function (search_term) {
this.container.hide();
this.loading_div.show();
var this_object = this;
// since this.params is an object, it needs to be cloned before being set
// http://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-clone-a-javascript-object
var send_data = $.extend({}, this.params);
if (search_term)
send_data.search_term = search_term;
send_data.grid_width = this.organize.layout.get_grid_width();
this.container.load(this.organize.params.base_url + "organize_services/load_entry_display", send_data, function () {
this_object.collection_management_loaded = false;
this_object.set_autocompleters();
this_object.loading_div.hide();
this_object.container.show();
});
};
this.load_collection_management = function () {
this.container.hide();
this.loading_div.show();
var this_object = this;
this.container.load(this.organize.params.base_url + "organize_services/load_collection_management", {}, function () {
this_object.collection_management_loaded = true;
this_object.loading_div.hide();
this_object.container.show();
});
};
this.load_invalid_collection = function () {
this.container.html("
Error
The collection you tried to view is not valid in this context. Please select a collection or registry from the left menu.
");
this.site_notification.show_only_this_message("Invalid collection specified", "error");
};
this.set_draggables = function () {
// @TODO enable this for future release
// var this_object = this;
/*$('.jqgrow').draggable({
start: function(event, ui) {
this.get_entries_container().setSelection($(this).attr('id'));
},
helper: function(event){
return $('
Move selected to...
')
.find('table').append($(event.target).closest('tr').clone()).end();
},
handle: '.entry_draggable_handle',
cursor: 'move',
scope: 'collections',
revert: 'invalid'
});
//$('.jqgrow').addClass('jstree-draggable');*/
};
this.set_autocompleters = function () {
var this_object = this;
$("#move_to_collection_search").autocomplete({
source: this_object.organize.autocompleter_search_options,
minLength: 0,
focus: function (event, ui) {
$(event.target).val(ui.item.label);
return false;
},
select: function (event, ui) {
$(event.target).val(ui.item.label);
var entries = $("#all_entries_selected").is(":checked") ? 'all' : this_object.get_checked();
var send_data = {
'entries': entries,
'destination_collection_id': ui.item.value,
'source_collection_id': this_object.params.collection_id
};
//Add loader
var move_entries_value = $("