1
0

Ajax is now working for all operations but only by sacrificing the full size link.

This commit is contained in:
hukoeth 2010-09-22 00:04:45 +08:00 committed by Bharat Mediratta
parent f1084d6390
commit f35ba09203
7 changed files with 110 additions and 42 deletions

View File

@ -115,12 +115,16 @@ class photoannotation_Controller extends Controller {
} }
//Save annotation //Save annotation
if ($annotate_id == "new") { //This is a new annotation if ($annotate_id == "new") { //This is a new annotation
$annotate_id = -1;
if ($user_id != "") { //Save user if ($user_id != "") { //Save user
photoannotation::saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description); $new_id = photoannotation::saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
$dest_type = "user";
} elseif ($tag_data != "") { //Save face } elseif ($tag_data != "") { //Save face
photoannotation::saveface($tag_data, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description); $new_id = photoannotation::saveface($tag_data, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
$dest_type = "face";
} elseif ($item_title != "") { //Save note } elseif ($item_title != "") { //Save note
photoannotation::savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description); $new_id = photoannotation::savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
$dest_type = "note";
} else { //Something's wrong } else { //Something's wrong
json::reply(array("result" => "error", "message" => (string)$error_noselection)); json::reply(array("result" => "error", "message" => (string)$error_noselection));
return; return;
@ -132,12 +136,15 @@ class photoannotation_Controller extends Controller {
->where("id", "=", $annotate_id) ->where("id", "=", $annotate_id)
->find(); ->find();
if ($user_id != "") { //Conversion user -> user if ($user_id != "") { //Conversion user -> user
photoannotation::saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description); $new_id = photoannotation::saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
$dest_type = "user";
} elseif ($tag_data != "") { //Conversion user -> face } elseif ($tag_data != "") { //Conversion user -> face
photoannotation::saveface($tag_data, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description); $new_id = photoannotation::saveface($tag_data, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
$dest_type = "face";
$updateduser->delete(); //delete old user $updateduser->delete(); //delete old user
} elseif ($item_title != "") { //Conversion user -> note } elseif ($item_title != "") { //Conversion user -> note
photoannotation::savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description); $new_id = photoannotation::savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
$dest_type = "note";
$updateduser->delete(); //delete old user $updateduser->delete(); //delete old user
} else { //Somethings wrong } else { //Somethings wrong
json::reply(array("result" => "error", "message" => (string)$error_noselection)); json::reply(array("result" => "error", "message" => (string)$error_noselection));
@ -149,12 +156,15 @@ class photoannotation_Controller extends Controller {
->where("id", "=", $annotate_id) ->where("id", "=", $annotate_id)
->find(); ->find();
if ($user_id != "") { //Conversion face -> user if ($user_id != "") { //Conversion face -> user
photoannotation::saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description); $new_id = photoannotation::saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
$dest_type = "user";
$updatedface->delete(); //delete old face $updatedface->delete(); //delete old face
} elseif ($tag_data != "") { //Conversion face -> face } elseif ($tag_data != "") { //Conversion face -> face
photoannotation::saveface($tag_data, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description, $annotate_id); $new_id = photoannotation::saveface($tag_data, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description, $annotate_id);
$dest_type = "face";
} elseif ($item_title != "") { //Conversion face -> note } elseif ($item_title != "") { //Conversion face -> note
photoannotation::savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description); $new_id = photoannotation::savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
$dest_type = "note";
$updatedface->delete(); //delete old face $updatedface->delete(); //delete old face
} else { //Somethings wrong } else { //Somethings wrong
json::reply(array("result" => "error", "message" => (string)$error_noselection)); json::reply(array("result" => "error", "message" => (string)$error_noselection));
@ -166,13 +176,16 @@ class photoannotation_Controller extends Controller {
->where("id", "=", $annotate_id) ->where("id", "=", $annotate_id)
->find(); ->find();
if ($user_id != "") { //Conversion note -> user if ($user_id != "") { //Conversion note -> user
photoannotation::saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description); $new_id = photoannotation::saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
$dest_type = "user";
$updatednote->delete(); //delete old note $updatednote->delete(); //delete old note
} elseif ($tag_data != "") { //Conversion note -> face } elseif ($tag_data != "") { //Conversion note -> face
photoannotation::saveface($tag_data, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description); $new_id = photoannotation::saveface($tag_data, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
$dest_type = "face";
$updatednote->delete(); //delete old note $updatednote->delete(); //delete old note
} elseif ($item_title != "") { //Conversion note -> note } elseif ($item_title != "") { //Conversion note -> note
photoannotation::savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description, $annotate_id); $new_id = photoannotation::savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description, $annotate_id);
$dest_type = "note";
} else { //Somethings wrong } else { //Somethings wrong
json::reply(array("result" => "error", "message" => (string)$error_noselection)); json::reply(array("result" => "error", "message" => (string)$error_noselection));
return; return;
@ -184,8 +197,47 @@ class photoannotation_Controller extends Controller {
} }
} }
//@todo: add needed data to the json reply //@todo: add needed data to the json reply
json::reply(array("result" => "success")); $int_text = "";
return; $editable = true;
switch ($dest_type) {
case "user":
$fullname = module::get_var("photoannotation", "fullname", false);
$int_text = $getuser->user->display_name() ." (". $getuser->user->name .")";
if ($fullname) {
$note_text = $getuser->user->display_name();
} else {
$note_text = $getuser->user->name;
}
$note_url = user_profile::url($getuser->user->id);
break;
case "face":
$note_text = $tag->name;
$note_url = $tag->url();
break;
case "note":
$note_text = $item_title;
$note_url = "";
$editable = false;
}
if ($annotate_id == -1) {
$annotation_id = "";
} else {
$annotation_id = "photoannotation-area-". $notetype ."-". $annotate_id;
}
$reply = array("result" => "success",
"notetype" => (string)$dest_type,
"description" => (string)$description,
"height" => (integer)$_POST["height"],
"internaltext" => (string)$int_text,
"left" => (integer)$str_x1,
"noteid" => (integer)$new_id,
"text" => (string)$note_text,
"top" => (integer)$str_y1,
"url" => (string)$note_url,
"width" => (integer)$_POST["width"],
"editable" => (boolean)$editable,
"annotationid" => (string)$annotation_id);
json::reply($reply);
} }
public function delete($item_data) { public function delete($item_data) {

View File

@ -69,7 +69,6 @@
color: #f30; color: #f30;
text-decoration: underline; text-decoration: underline;
} }
.image-annotate-canvas { .image-annotate-canvas {
background-position: left top; background-position: left top;
background-repeat: no-repeat; background-repeat: no-repeat;

View File

@ -99,6 +99,7 @@ class photoannotation_Core {
$item_user->y2 = $str_y2; $item_user->y2 = $str_y2;
$item_user->description = $description; $item_user->description = $description;
$item_user->save(); $item_user->save();
return $item_user->id;
} }
public static function saveface($tag_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description, $annotate_id = "") { public static function saveface($tag_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description, $annotate_id = "") {
@ -117,6 +118,7 @@ class photoannotation_Core {
$item_face->y2 = $str_y2; $item_face->y2 = $str_y2;
$item_face->description = $description; $item_face->description = $description;
$item_face->save(); $item_face->save();
return $item_face->id;
} }
public static function savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description, $annotate_id = "") { public static function savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description, $annotate_id = "") {
@ -135,6 +137,7 @@ class photoannotation_Core {
$item_note->title = $item_title; $item_note->title = $item_title;
$item_note->description = $description; $item_note->description = $description;
$item_note->save(); $item_note->save();
return $item_note->id;
} }
public static function send_notifications($recipient_id, $item_id, $mailtype) { public static function send_notifications($recipient_id, $item_id, $mailtype) {

View File

@ -21,7 +21,7 @@ class photoannotation_theme_Core {
static function head($theme) { static function head($theme) {
$theme->css("photoannotation.css"); $theme->css("photoannotation.css");
if ($theme->page_subtype == "photo") { if ($theme->page_subtype == "photo") {
//$theme->script("jquery.annotate.min.js"); $theme->script("jquery.annotate.min.js");
$noborder = module::get_var("photoannotation", "noborder", false); $noborder = module::get_var("photoannotation", "noborder", false);
$noclickablehover = module::get_var("photoannotation", "noclickablehover", false); $noclickablehover = module::get_var("photoannotation", "noclickablehover", false);
$nohover = module::get_var("photoannotation", "nohover", false); $nohover = module::get_var("photoannotation", "nohover", false);
@ -60,7 +60,7 @@ class photoannotation_theme_Core {
}\n"; }\n";
} }
} }
$v .= "</style>\n<script type=\"text/javascript\" src=\"/gallery3/modules/photoannotation/js/jquery.annotate.js\"></script>"; $v .= "</style>\n";
return $v; return $v;
} }
} }

View File

@ -26,13 +26,13 @@
this.cssaclass = opts.cssaclass; this.cssaclass = opts.cssaclass;
this.rtlsupport = opts.rtlsupport; this.rtlsupport = opts.rtlsupport;
this.users = opts.users; this.users = opts.users;
anchor = $('.g-fullsize-link');
// Add the canvas // Add the canvas
this.canvas = $('<div class="image-annotate-canvas g-thumbnail"><div class="image-annotate-view"></div><div class="image-annotate-edit"><div class="image-annotate-edit-area"></div></div></div>'); this.canvas = $('<div class="image-annotate-canvas g-thumbnail"><div class="image-annotate-view"><div id="photoannotation-fullsize" class="image-annotate-note"></div></div><div class="image-annotate-edit"><div class="image-annotate-edit-area"></div></div></div>');
this.canvas.children('.image-annotate-edit').hide(); this.canvas.children('.image-annotate-edit').hide();
this.canvas.children('.image-annotate-view').hide(); this.canvas.children('.image-annotate-view').hide();
$('#g-photo').after(this.canvas); $('#g-photo').after(this.canvas);
//this.image.after(this.canvas);
// Give the canvas and the container their size and background // Give the canvas and the container their size and background
this.canvas.height(this.height()); this.canvas.height(this.height());
@ -45,10 +45,12 @@
this.canvas.hover(function() { this.canvas.hover(function() {
if ($(this).children('.image-annotate-edit').css('display') == 'none') { if ($(this).children('.image-annotate-edit').css('display') == 'none') {
$(this).children('.image-annotate-view').show(); $(this).children('.image-annotate-view').show();
$("#photoannotation-fullsize").show();
} }
}, function() { }, function() {
$(this).children('.image-annotate-view').hide(); $(this).children('.image-annotate-view').hide();
$(this).children('.image-annotate-note').hide(); $(this).children('.image-annotate-note').hide();
$("#photoannotation-fullsize").hide();
}); });
this.canvas.children('.image-annotate-view').hover(function() { this.canvas.children('.image-annotate-view').hover(function() {
@ -76,7 +78,11 @@
// Hide the original // Hide the original
this.hide(); this.hide();
$('#g-photo').hide();
$('.image-annotate-canvas').show();
$(".g-resize").remove();
$("#photoannotation-fullsize").append($('.g-fullsize-link:first'));
$('.g-fullsize-link').append($('.g-fullsize-link:first').attr('title'));
return this; return this;
}; };
@ -156,7 +162,7 @@
ok.click(function() { ok.click(function() {
var form = $('#image-annotate-edit-form form'); var form = $('#image-annotate-edit-form form');
$.fn.annotateImage.appendPosition(form, editable) $.fn.annotateImage.appendPosition(form, editable);
$.ajax({ $.ajax({
url: saveUrl, url: saveUrl,
type: 'POST', type: 'POST',
@ -206,20 +212,25 @@
buttons: btns buttons: btns
}); });
} else { } else {
var test = saveUrl; if (data.annotationid != "") {
var newnote = new array(); $("#" + data.annotationid).remove();
newnote.description = data.description; $("#" + data.annotationid + "-edit").remove();
newnote.editable = true; $("#" + data.annotationid + "-delete").remove();
newnote.height = data.height; $("#" + data.annotationid + "-note").remove();
newnote.internaltext = data.internaltext; }
newnote.left = data.left; editable.description = data.description;
newnote.noteid = data.noteid; editable.editable = data.editable;
newnote.notetype = data.notetype; editable.height = data.height;
newnote.text = data.text; editable.internaltext = data.internaltext;
newnote.top = data.top; editable.left = data.left;
newnote.url = data.url; editable.noteid = data.noteid;
newnote.width = data.width; editable.notetype = data.notetype;
$.fn.annotateView(!image, newnote, !image.tags, !image.labels, !image.editable, !image.csrf, !image.deleteUrl, !image.saveUrl, !image.cssaclass, !image.rtlsupport, !image.users); editable.text = data.text;
editable.top = data.top;
editable.url = data.url;
editable.width = data.width;
note = new $.fn.annotateView(image, editable, image.tags, image.labels, image.editable, image.csrf, image.deleteUrl, image.saveUrl, image.cssaclass, image.rtlsupport, image.users);
//@todo: save new annotation / update existing annotation //@todo: save new annotation / update existing annotation
//success //success
} }
@ -421,8 +432,8 @@
image.canvas.children('.image-annotate-view').prepend(this.area); image.canvas.children('.image-annotate-view').prepend(this.area);
if (editable) { if (editable) {
this.delarea = $('<div class="image-annotate-area photoannotation-del-button" rel="photoannotation-area-' + this.note.notetype + "-" + this.note.noteid + '"><div><form id="photoannotation-area-' + this.note.notetype + "-" + this.note.noteid + '-del-form" class="photoannotation-del-form" method="post" action="' + deleteUrl + '"><input type="hidden" name="notetype" value="' + this.note.notetype + '" /><input type="hidden" name="noteid" value="' + this.note.noteid + '" /><input type="hidden" name="csrf" value="' + csrf + '" /></form></div></div>'); this.delarea = $('<div id="photoannotation-area-' + this.note.notetype + "-" + this.note.noteid + '-delete" class="image-annotate-area photoannotation-del-button" rel="photoannotation-area-' + this.note.notetype + "-" + this.note.noteid + '"><div><form id="photoannotation-area-' + this.note.notetype + "-" + this.note.noteid + '-del-form" class="photoannotation-del-form" method="post" action="' + deleteUrl + '"><input type="hidden" name="notetype" value="' + this.note.notetype + '" /><input type="hidden" name="noteid" value="' + this.note.noteid + '" /><input type="hidden" name="csrf" value="' + csrf + '" /></form></div></div>');
this.editarea = $('<div id="photoannotation-edit-' + this.note.noteid + '" class="image-annotate-area photoannotation-edit-button"><div></div></div>'); this.editarea = $('<div id="photoannotation-area-' + this.note.notetype + "-" + this.note.noteid + '-edit" class="image-annotate-area photoannotation-edit-button"><div></div></div>');
image.canvas.children('.image-annotate-view').prepend(this.delarea); image.canvas.children('.image-annotate-view').prepend(this.delarea);
image.canvas.children('.image-annotate-view').prepend(this.editarea); image.canvas.children('.image-annotate-view').prepend(this.editarea);
this.delarea.bind('click',function () { this.delarea.bind('click',function () {
@ -465,6 +476,9 @@
success: function(data) { success: function(data) {
if (data.result == "success") { if (data.result == "success") {
$("#" + data.annotationid).remove(); $("#" + data.annotationid).remove();
$("#" + data.annotationid + "-edit").remove();
$("#" + data.annotationid + "-delete").remove();
$("#" + data.annotationid + "-note").remove();
} }
}, },
dataType: "json" dataType: "json"
@ -494,7 +508,7 @@
if (note.description != "") { if (note.description != "") {
notedescription = "<br />" + note.description; notedescription = "<br />" + note.description;
} }
this.form = $('<div class="image-annotate-note">' + note.text + notedescription + '</div>'); this.form = $('<div id="photoannotation-area-' + this.note.notetype + "-" + this.note.noteid + '-note" class="image-annotate-note">' + note.text + notedescription + '</div>');
this.form.hide(); this.form.hide();
image.canvas.children('.image-annotate-view').append(this.form); image.canvas.children('.image-annotate-view').append(this.form);
this.form.children('span.actions').hide(); this.form.children('span.actions').hide();
@ -573,6 +587,7 @@
this.delarea.css('top', (this.note.top) + 'px'); this.delarea.css('top', (this.note.top) + 'px');
this.editarea.children('div').height('14px'); this.editarea.children('div').height('14px');
this.editarea.children('div').width('14px'); this.editarea.children('div').width('14px');
this.editarea.css('top', (this.note.top + 16) + 'px');
if (rtlsupport == '') { if (rtlsupport == '') {
this.delarea.css('left', (this.note.left + parseInt(this.note.width)) + 'px'); this.delarea.css('left', (this.note.left + parseInt(this.note.width)) + 'px');
this.editarea.css('left', (this.note.left + parseInt(this.note.width)) + 'px'); this.editarea.css('left', (this.note.left + parseInt(this.note.width)) + 'px');
@ -580,7 +595,6 @@
this.delarea.css('left', (this.note.left - 16) + 'px'); this.delarea.css('left', (this.note.left - 16) + 'px');
this.editarea.css('left', (this.note.left - 16) + 'px'); this.editarea.css('left', (this.note.left - 16) + 'px');
} }
this.editarea.css('top', (this.note.top + 16) + 'px');
} }
}; };
@ -663,6 +677,6 @@
'<input type="hidden" value="' + editable.area.position().left + '" name="left"/>' + '<input type="hidden" value="' + editable.area.position().left + '" name="left"/>' +
'<input type="hidden" value="' + editable.note.id + '" name="id"/>'); '<input type="hidden" value="' + editable.note.id + '" name="id"/>');
form.append(areaFields); form.append(areaFields);
} };
})(jQuery); })(jQuery);

File diff suppressed because one or more lines are too long

View File

@ -107,7 +107,7 @@
} }
} }
$legend_display = $legend_users . $legend_faces . $legend_notes; $legend_display = $legend_users . $legend_faces . $legend_notes;
$labels_arraystring = "labels: [ '". t("Tag:") ."','". t("Note Title:") ."','". t("Description (optional)") ."','". t("Are you sure you want to delete this annotation?") ."','". t("or") ."','". t("Yes") ."','". t("No") ."','". t("Confirm deletion") ."','". t("Save") ."','". t("Cancel") ."','". t("Person:") ."','". t("No user selected") ."','". t("Select one of the following") ."','". t("An error ocurred while saving annotation") ."','". t("OK") ."','". t("An error ocurred while deleting annotation") ."' ],"; $labels_arraystring = "labels: [ '". t("Tag:") ."','". t("Note Title:") ."','". t("Description (optional)") ."','". t("Are you sure you want to delete this annotation?") ."','". t("or") ."','". t("Yes") ."','". t("No") ."','". t("Confirm deletion") ."','". t("Save") ."','". t("Cancel") ."','". t("Person:") ."','". t("No user selected") ."','". t("Select one of the following") ."','". t("An error ocurred while saving annotation") ."','". t("OK") ."','". t("An error ocurred while deleting annotation") ."','". t("View fullsize") ."' ],";
?> ?>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {