2009-12-12 17:39:18 +00:00
|
|
|
(function($) {
|
2009-12-16 19:51:45 +00:00
|
|
|
var _paths = [];
|
2009-12-12 17:39:18 +00:00
|
|
|
|
|
|
|
$.fn.gallery3_client = function() {
|
|
|
|
return this.each(function(i) {
|
|
|
|
ajaxifyLoginForm(this);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function ajaxifyLoginForm(obj) {
|
|
|
|
var login = $(obj).find("#g-login-form form");
|
|
|
|
if (login.length > 0) {
|
|
|
|
$(login).ajaxForm({
|
|
|
|
dataType: "json",
|
|
|
|
beforeSubmit: function(formData, form, options) {
|
|
|
|
form.find(":submit")
|
|
|
|
.addClass("ui-state-disabled")
|
|
|
|
.attr("disabled", "disabled");
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
$(obj).html(data.content);
|
|
|
|
if (data.status == "ok") {
|
|
|
|
initializeDetail(obj);
|
2009-12-17 19:25:46 +00:00
|
|
|
} else {
|
2009-12-12 17:39:18 +00:00
|
|
|
ajaxifyLoginForm(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
initializeDetail(obj);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function initializeDetail(obj) {
|
|
|
|
$(".ui-icon-plus", obj).live("click", function (event) {
|
|
|
|
var siblings = $("~ ul", this);
|
|
|
|
if (siblings.length > 0) {
|
|
|
|
siblings.show();
|
|
|
|
$(this).removeClass("ui-icon-plus");
|
|
|
|
$(this).addClass("ui-icon-minus");
|
|
|
|
} else {
|
2009-12-16 19:51:45 +00:00
|
|
|
var parent = $(this).parents("li:first");
|
2009-12-12 17:39:18 +00:00
|
|
|
$.get("/g3_client/index.php/g3_client/albums",
|
|
|
|
{path: $(parent).attr("ref")},
|
|
|
|
function(data, textStatus) {
|
|
|
|
$(parent).replaceWith(data);
|
|
|
|
});
|
|
|
|
}
|
2009-12-15 20:23:32 +00:00
|
|
|
return false;
|
2009-12-12 17:39:18 +00:00
|
|
|
});
|
2009-12-15 20:23:32 +00:00
|
|
|
|
2009-12-12 17:39:18 +00:00
|
|
|
$(".ui-icon-minus", obj).live("click", function (event) {
|
|
|
|
$("~ ul", this).hide();
|
|
|
|
$(this).removeClass("ui-icon-minus");
|
|
|
|
$(this).addClass("ui-icon-plus");
|
2009-12-15 20:23:32 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2009-12-17 19:25:46 +00:00
|
|
|
$("#center a.wc-child-link").live("dblclick", function(event) {
|
2009-12-15 20:23:32 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2009-12-16 19:51:45 +00:00
|
|
|
var path = $(this).parents("li:first").attr("ref");
|
2009-12-15 20:23:32 +00:00
|
|
|
var url = $(this).attr("href");
|
2009-12-17 19:25:46 +00:00
|
|
|
get_detail(path, _set_active_album);
|
2009-12-15 20:23:32 +00:00
|
|
|
return false;
|
2009-12-12 17:39:18 +00:00
|
|
|
});
|
2009-12-15 20:23:32 +00:00
|
|
|
|
2009-12-18 20:24:10 +00:00
|
|
|
$("#wc-choose-resource").live("click", function(event){
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
if ($("#wc-resource-list:visible").length) {
|
|
|
|
$("#wc-resource-list").hide();
|
|
|
|
} else {
|
|
|
|
var parent = $(this).parent("div");
|
|
|
|
var width = parent.width();
|
|
|
|
var height = parent.height();
|
|
|
|
var top = parent.position().top;
|
|
|
|
var current_path = $("#wc-add-resource").attr("ref");
|
|
|
|
$("#wc-resource-list li[ref='" + current_path + "']").addClass("ui-selected");
|
|
|
|
$("#wc-resource-list")
|
|
|
|
.css({"top": (top + height - 5) + "px", "width": width + "px"})
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#wc-resource-list").live("click", function(event) {
|
|
|
|
var ref = $(event.originalTarget).attr("ref");
|
|
|
|
var text = $(event.originalTarget).text();
|
|
|
|
$("#wc-add-resource span").text(text);
|
|
|
|
$("#wc-add-resource").attr("ref", ref);
|
|
|
|
$("#wc-resource-list").hide();
|
|
|
|
$("#wc-resource-list li.ui-selected").removeClass("ui-selected");
|
|
|
|
});
|
|
|
|
|
2009-12-17 19:25:46 +00:00
|
|
|
$("#center a.wc-child-link").live("click", function(event) {
|
|
|
|
$(".wc-thumb-grid-cell.ui-selected").removeClass("ui-selected");
|
2009-12-16 19:51:45 +00:00
|
|
|
$(this).parents("li:first").addClass("ui-selected");
|
2009-12-17 19:25:46 +00:00
|
|
|
_set_navigation_buttons($(".wc-thumb-grid-cell.ui-selected").attr("ref"));
|
2009-12-15 20:23:32 +00:00
|
|
|
return false;
|
2009-12-12 17:39:18 +00:00
|
|
|
});
|
2009-12-16 19:51:45 +00:00
|
|
|
|
|
|
|
$(".wc-button").live("click", function() {
|
2009-12-17 19:25:46 +00:00
|
|
|
if ($(this).hasClass("ui-state-disabled")) {
|
2009-12-16 19:51:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-12-18 20:24:10 +00:00
|
|
|
|
|
|
|
var action = $(this).attr("ref");
|
|
|
|
switch (action) {
|
2009-12-17 04:11:15 +00:00
|
|
|
case "parent":
|
2009-12-17 19:25:46 +00:00
|
|
|
get_detail($("span", this).attr("ref"), _set_active_album);
|
2009-12-17 04:11:15 +00:00
|
|
|
break;
|
|
|
|
case "first":
|
|
|
|
case "previous":
|
|
|
|
case "next":
|
|
|
|
case "last":
|
2009-12-17 19:25:46 +00:00
|
|
|
if (resource_type != "album") {
|
2009-12-17 04:11:15 +00:00
|
|
|
get_detail($("span", this).attr("ref"));
|
|
|
|
} else {
|
2009-12-17 19:25:46 +00:00
|
|
|
var selected = $(".wc-thumb-grid-cell.ui-selected");
|
2009-12-17 04:11:15 +00:00
|
|
|
selected.removeClass("ui-selected");
|
|
|
|
switch ($(this).attr("ref")) {
|
|
|
|
case "first":
|
2009-12-17 19:25:46 +00:00
|
|
|
$(".wc-thumb-grid-cell:first").addClass("ui-selected");
|
2009-12-17 04:11:15 +00:00
|
|
|
break;
|
|
|
|
case "previous":
|
|
|
|
selected.prev().addClass("ui-selected");
|
|
|
|
break;
|
|
|
|
case "next":
|
|
|
|
selected.next().addClass("ui-selected");
|
|
|
|
break;
|
|
|
|
case "last":
|
2009-12-17 19:25:46 +00:00
|
|
|
$(".wc-thumb-grid-cell:last").addClass("ui-selected");
|
2009-12-17 04:11:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
_set_navigation_buttons();
|
|
|
|
}
|
|
|
|
break;
|
2009-12-18 20:24:10 +00:00
|
|
|
case "edit":
|
|
|
|
case "delete":
|
2009-12-21 19:30:38 +00:00
|
|
|
_open_dialog(action + "_" + resource_type, $("span", this).attr("ref"));
|
2009-12-18 20:24:10 +00:00
|
|
|
break;
|
2009-12-17 04:11:15 +00:00
|
|
|
default:
|
2009-12-21 19:30:38 +00:00
|
|
|
if (/^add_.*/.test(action)) {
|
|
|
|
_open_dialog(action, $("span", this).attr("ref"));
|
|
|
|
} else {
|
|
|
|
console.group("process toolbar button click: " + $(this).attr("ref"));
|
|
|
|
console.log(($("span", this).attr("ref")));
|
|
|
|
console.groupEnd();
|
|
|
|
}
|
2009-12-16 19:51:45 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".tree-title", obj).live("click", function (event) {
|
|
|
|
get_detail($(this).parents("li:first").attr("ref"));
|
|
|
|
$(".ui-selected").removeClass("ui-selected");
|
2009-12-17 04:11:15 +00:00
|
|
|
$(this).addClass("ui-selected");
|
|
|
|
return false;
|
|
|
|
});
|
2009-12-16 19:51:45 +00:00
|
|
|
|
2009-12-12 17:39:18 +00:00
|
|
|
$("#album_tree [ref=''] .tree-title:first").addClass("ui-selected");
|
2009-12-16 19:51:45 +00:00
|
|
|
set_selected_thumb();
|
2009-12-17 19:25:46 +00:00
|
|
|
save_paths();
|
|
|
|
}
|
|
|
|
|
|
|
|
function _set_active_album(path) {
|
|
|
|
var album = $("#album_tree [ref='" + path + "']");
|
|
|
|
if (album.length > 0) {
|
|
|
|
$(".tree-title.ui-selected").removeClass("ui-selected");
|
|
|
|
$(".tree-title:first", album).addClass("ui-selected");
|
|
|
|
}
|
|
|
|
}
|
2009-12-16 19:51:45 +00:00
|
|
|
|
|
|
|
function set_selected_thumb() {
|
2009-12-17 19:25:46 +00:00
|
|
|
if ($(".wc-thumb-grid-cell.ui-selected").length == 0) {
|
|
|
|
$(".wc-thumb-grid-cell:first").addClass("ui-selected");
|
2009-12-16 19:51:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-18 20:24:10 +00:00
|
|
|
function _open_dialog(dialog, resource_path) {
|
|
|
|
$("body").append('<div id="g-dialog"></div>');
|
|
|
|
$("#g-dialog").dialog({
|
|
|
|
model: true,
|
|
|
|
resizable: false,
|
|
|
|
position: "center",
|
|
|
|
close: function() {
|
|
|
|
$("#g-dialog").dialog("destroy").remove();
|
|
|
|
}
|
|
|
|
});
|
2009-12-21 19:30:38 +00:00
|
|
|
$.getJSON("/g3_client/index.php/" + dialog, {path: resource_path}, function(data) {
|
|
|
|
$("#g-dialog").html(data.form);
|
2009-12-18 20:24:10 +00:00
|
|
|
|
|
|
|
$("#g-dialog").dialog("open");
|
|
|
|
if ($("#g-dialog fieldset legend").length) {
|
|
|
|
$("#g-dialog").dialog('option', 'title', $("#g-dialog fieldset legend:eq(0)").html());
|
|
|
|
}
|
2009-12-21 19:30:38 +00:00
|
|
|
_ajaxifyDialog();
|
2009-12-18 20:24:10 +00:00
|
|
|
|
2009-12-21 19:30:38 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function _ajaxifyDialog() {
|
|
|
|
if ($("#g-dialog form").length) {
|
|
|
|
$("#g-dialog form").ajaxForm({
|
|
|
|
dataType: "json",
|
|
|
|
beforeSubmit: function(formData, form, options) {
|
|
|
|
form.find(":submit")
|
|
|
|
.addClass("ui-state-disabled")
|
|
|
|
.attr("disabled", "disabled");
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
if (data.form) {
|
|
|
|
$("#g-dialog form").replaceWith(data.form);
|
|
|
|
$("#g-dialog form :submit").removeClass("ui-state-disabled")
|
|
|
|
.attr("disabled", null);
|
|
|
|
_ajaxifyDialog();
|
|
|
|
}
|
|
|
|
if (data.result == "success") {
|
|
|
|
$("#g-dialog").dialog('close');
|
|
|
|
get_detail(data.path, _set_active_album);
|
|
|
|
if (data.type == "album") {
|
|
|
|
var path = data.path;
|
|
|
|
$.get("/g3_client/index.php/g3_client/albums",
|
|
|
|
{path: path},
|
|
|
|
function(data, textStatus) {
|
|
|
|
var selector = "#album_tree li[ref=" + path + "]";
|
|
|
|
$(selector).replaceWith(data);
|
|
|
|
$(selector + " .tree-title:first").addClass("ui-selected");
|
|
|
|
});
|
2009-12-18 20:24:10 +00:00
|
|
|
}
|
2009-12-21 19:30:38 +00:00
|
|
|
} else if (data.result == "fail") {
|
|
|
|
$("#g-dialog").dialog('close');
|
|
|
|
alert(data.message);
|
2009-12-18 20:24:10 +00:00
|
|
|
}
|
2009-12-21 19:30:38 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2009-12-18 20:24:10 +00:00
|
|
|
}
|
|
|
|
|
2009-12-16 19:51:45 +00:00
|
|
|
function get_detail(path, callback) {
|
|
|
|
$.get("/g3_client/index.php/g3_client/detail", {path: path}, function(data, textStatus) {
|
|
|
|
$("#wc-detail").html(data);
|
|
|
|
set_selected_thumb();
|
2009-12-17 19:25:46 +00:00
|
|
|
save_paths();
|
2009-12-17 04:11:15 +00:00
|
|
|
if (callback) {
|
2009-12-16 19:51:45 +00:00
|
|
|
callback(path);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2009-12-17 19:25:46 +00:00
|
|
|
function save_paths() {
|
|
|
|
_paths[current_path] = [];
|
|
|
|
$(".wc-thumb-grid-cell").each(function(i) {
|
|
|
|
_paths[current_path][i] = $(this).attr("ref");
|
2009-12-16 19:51:45 +00:00
|
|
|
});
|
|
|
|
|
2009-12-17 19:25:46 +00:00
|
|
|
_set_navigation_buttons();
|
2009-12-16 19:51:45 +00:00
|
|
|
}
|
|
|
|
|
2009-12-17 19:25:46 +00:00
|
|
|
function _set_navigation_buttons() {
|
|
|
|
if (current_path != "") {
|
2009-12-16 19:51:45 +00:00
|
|
|
$(".wc-toolbar .ui-icon-eject").parent("a").removeClass("ui-state-disabled");
|
2009-12-18 23:03:22 +00:00
|
|
|
//$(".wc-toolbar .ui-icon-trash").parent("a").removeClass("ui-state-disabled");
|
2009-12-16 19:51:45 +00:00
|
|
|
} else {
|
|
|
|
$(".wc-toolbar .ui-icon-eject").parent("a").addClass("ui-state-disabled");
|
2009-12-18 23:03:22 +00:00
|
|
|
//$(".wc-toolbar .ui-icon-trash").parent("a").addClass("ui-state-disabled");
|
2009-12-17 04:11:15 +00:00
|
|
|
}
|
2009-12-17 19:25:46 +00:00
|
|
|
$(".wc-toolbar .ui-icon-eject").attr("ref", parent_path);
|
|
|
|
$(".wc-toolbar .ui-icon-pencil").attr("ref", current_path);
|
2009-12-18 20:24:10 +00:00
|
|
|
$(".wc-toolbar #wc-add-resource span")
|
2009-12-17 19:25:46 +00:00
|
|
|
.attr("ref", resource_type == "album" ? current_path : parent_path);
|
2009-12-17 04:11:15 +00:00
|
|
|
|
2009-12-18 23:03:22 +00:00
|
|
|
var paths = _paths[resource_type == "album" ? current_path : parent_path];
|
2009-12-17 04:11:15 +00:00
|
|
|
|
2009-12-17 19:25:46 +00:00
|
|
|
$(".wc-toolbar .ui-icon-pencil").attr("ref", current_path);
|
2009-12-17 04:11:15 +00:00
|
|
|
if (paths.length > 0) {
|
|
|
|
$(".wc-toolbar .ui-icon-seek-first").parent("a").removeClass("ui-state-disabled");
|
|
|
|
$(".wc-toolbar .ui-icon-seek-end").parent("a").removeClass("ui-state-disabled");
|
|
|
|
$(".wc-toolbar .ui-icon-seek-first").attr("ref", paths[0]);
|
|
|
|
$(".wc-toolbar .ui-icon-seek-end").attr("ref", paths[paths.length - 1]);
|
|
|
|
} else {
|
|
|
|
$(".wc-toolbar .ui-icon-seek-first").parent("a").addClass("ui-state-disabled");
|
|
|
|
$(".wc-toolbar .ui-icon-seek-end").parent("a").addClass("ui-state-disabled");
|
|
|
|
}
|
|
|
|
|
2009-12-17 19:25:46 +00:00
|
|
|
var selected_path =
|
|
|
|
resource_type == "album" ? $(".wc-thumb-grid-cell.ui-selected").attr("ref") : current_path;
|
2009-12-17 04:11:15 +00:00
|
|
|
var i = 0;
|
|
|
|
for (; i < paths.length; i++) {
|
|
|
|
if (paths[i] == selected_path) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-18 23:03:22 +00:00
|
|
|
$(".wc-toolbar .ui-icon-trash").attr("ref", selected_path);
|
|
|
|
|
2009-12-17 04:11:15 +00:00
|
|
|
if (i > 0) {
|
|
|
|
$(".wc-toolbar .ui-icon-seek-prev").parent("a").removeClass("ui-state-disabled");
|
|
|
|
$(".wc-toolbar .ui-icon-seek-prev").attr("ref", paths[i - 1]);
|
|
|
|
} else {
|
|
|
|
$(".wc-toolbar .ui-icon-seek-first").parent("a").addClass("ui-state-disabled");
|
|
|
|
$(".wc-toolbar .ui-icon-seek-prev").parent("a").addClass("ui-state-disabled");
|
|
|
|
}
|
|
|
|
if (i < paths.length - 1) {
|
|
|
|
$(".wc-toolbar .ui-icon-seek-next").parent("a").removeClass("ui-state-disabled");
|
|
|
|
$(".wc-toolbar .ui-icon-seek-next").attr("ref", paths[i + 1]);
|
|
|
|
} else {
|
|
|
|
$(".wc-toolbar .ui-icon-seek-next").parent("a").addClass("ui-state-disabled");
|
|
|
|
$(".wc-toolbar .ui-icon-seek-end").parent("a").addClass("ui-state-disabled");
|
2009-12-16 19:51:45 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-17 19:25:46 +00:00
|
|
|
})(jQuery);
|