2013-01-28 20:18:50 +01:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-pholio-mock-view
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-stratcom
|
2013-02-01 19:53:15 +01:00
|
|
|
* javelin-dom
|
|
|
|
* javelin-vector
|
2013-02-07 15:26:36 +01:00
|
|
|
* javelin-magical-init
|
|
|
|
* javelin-request
|
2013-01-28 20:18:50 +01:00
|
|
|
*/
|
|
|
|
JX.behavior('pholio-mock-view', function(config) {
|
2013-02-01 19:53:15 +01:00
|
|
|
var is_dragging = false;
|
|
|
|
var wrapper = JX.$('mock-wrapper');
|
|
|
|
var image;
|
|
|
|
var imageData;
|
|
|
|
var startPos;
|
|
|
|
var endPos;
|
2013-02-07 15:26:36 +01:00
|
|
|
|
|
|
|
var selection_border;
|
|
|
|
var selection_fill;
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-01-28 20:18:50 +01:00
|
|
|
JX.Stratcom.listen(
|
|
|
|
'click', // Listen for clicks...
|
|
|
|
'mock-thumbnail', // ...on nodes with sigil "mock-thumbnail".
|
|
|
|
function(e) {
|
|
|
|
var data = e.getNodeData('mock-thumbnail');
|
|
|
|
|
|
|
|
var main = JX.$(config.mainID);
|
2013-02-01 19:53:15 +01:00
|
|
|
JX.Stratcom.addData(
|
|
|
|
main,
|
|
|
|
{
|
|
|
|
fullSizeURI: data['fullSizeURI'],
|
|
|
|
imageID: data['imageID']
|
|
|
|
});
|
|
|
|
|
2013-01-28 20:18:50 +01:00
|
|
|
main.src = data.fullSizeURI;
|
2013-02-01 19:53:15 +01:00
|
|
|
|
|
|
|
JX.DOM.setContent(wrapper,main);
|
2013-02-08 16:24:17 +01:00
|
|
|
load_inline_comments();
|
2013-02-01 19:53:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-02-07 15:26:36 +01:00
|
|
|
function draw_rectangle(nodes, current, init) {
|
|
|
|
for (var ii = 0; ii < nodes.length; ii++) {
|
|
|
|
var node = nodes[ii];
|
|
|
|
|
|
|
|
JX.$V(
|
|
|
|
Math.abs(current.x-init.x),
|
|
|
|
Math.abs(current.y-init.y))
|
|
|
|
.setDim(node);
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-02-07 15:26:36 +01:00
|
|
|
JX.$V(
|
|
|
|
(current.x-init.x < 0) ? current.x:init.x,
|
|
|
|
(current.y-init.y < 0) ? current.y:init.y)
|
|
|
|
.setPos(node);
|
|
|
|
}
|
2013-02-01 19:53:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function getRealXY(parent, point) {
|
|
|
|
var pos = {x: (point.x - parent.x), y: (point.y - parent.y)};
|
2013-02-07 15:26:36 +01:00
|
|
|
var dim = JX.Vector.getDim(image);
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-02-07 15:26:36 +01:00
|
|
|
pos.x = Math.max(0, Math.min(pos.x, dim.x));
|
|
|
|
pos.y = Math.max(0, Math.min(pos.y, dim.y));
|
2013-02-01 19:53:15 +01:00
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
JX.Stratcom.listen('mousedown', 'mock-wrapper', function(e) {
|
|
|
|
if (!e.isNormalMouseEvent()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
image = JX.$(config.mainID);
|
|
|
|
imageData = JX.Stratcom.getData(image);
|
|
|
|
|
|
|
|
e.getRawEvent().target.draggable = false;
|
|
|
|
is_dragging = true;
|
|
|
|
|
|
|
|
startPos = getRealXY(JX.$V(wrapper),JX.$V(e));
|
|
|
|
|
2013-02-07 15:26:36 +01:00
|
|
|
selection_border = JX.$N(
|
2013-02-01 19:53:15 +01:00
|
|
|
'div',
|
2013-02-07 15:26:36 +01:00
|
|
|
{className: 'pholio-mock-select-border'});
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-02-07 15:26:36 +01:00
|
|
|
selection_fill = JX.$N(
|
|
|
|
'div',
|
|
|
|
{className: 'pholio-mock-select-fill'});
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-02-07 15:26:36 +01:00
|
|
|
JX.$V(startPos.x, startPos.y).setPos(selection_border);
|
|
|
|
JX.$V(startPos.x, startPos.y).setPos(selection_fill);
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-02-07 15:26:36 +01:00
|
|
|
JX.DOM.appendContent(wrapper, [selection_border, selection_fill]);
|
2013-02-01 19:53:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
JX.enableDispatch(document.body, 'mousemove');
|
|
|
|
JX.Stratcom.listen('mousemove',null, function(e) {
|
|
|
|
if (!is_dragging) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-07 15:26:36 +01:00
|
|
|
draw_rectangle(
|
|
|
|
[selection_border, selection_fill],
|
|
|
|
getRealXY(JX.$V(wrapper),
|
|
|
|
JX.$V(e)), startPos);
|
2013-02-01 19:53:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'mouseup',
|
|
|
|
null,
|
|
|
|
function(e) {
|
|
|
|
if (!is_dragging) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
is_dragging = false;
|
|
|
|
|
|
|
|
endPos = getRealXY(JX.$V(wrapper), JX.$V(e));
|
|
|
|
|
|
|
|
comment = window.prompt("Add your comment");
|
|
|
|
if (comment == null || comment == "") {
|
2013-02-07 15:26:36 +01:00
|
|
|
JX.DOM.remove(selection_border);
|
|
|
|
JX.DOM.remove(selection_fill);
|
2013-02-01 19:53:15 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-07 15:26:36 +01:00
|
|
|
selection_fill.title = comment;
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-02-08 16:24:17 +01:00
|
|
|
var saveURL = "/pholio/inline/save/";
|
2013-02-06 20:28:03 +01:00
|
|
|
|
|
|
|
var inlineComment = new JX.Request(saveURL, function(r) {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
var commentToAdd = {
|
|
|
|
mockID: config.mockID,
|
|
|
|
imageID: imageData['imageID'],
|
|
|
|
startX: Math.min(startPos.x, endPos.x),
|
|
|
|
startY: Math.min(startPos.y, endPos.y),
|
|
|
|
endX: Math.max(startPos.x,endPos.x),
|
|
|
|
endY: Math.max(startPos.y,endPos.y),
|
|
|
|
comment: comment};
|
|
|
|
|
|
|
|
inlineComment.addData(commentToAdd);
|
|
|
|
inlineComment.send();
|
2013-02-13 16:10:14 +01:00
|
|
|
load_inline_comments();
|
2013-01-28 20:18:50 +01:00
|
|
|
});
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-02-13 16:10:14 +01:00
|
|
|
function forge_inline_comment(data) {
|
|
|
|
var comment_head = data.username;
|
|
|
|
if (data.transactionphid == null) comment_head += " (draft)";
|
|
|
|
|
|
|
|
var links = null;
|
|
|
|
if (data.canEdit && data.transactionphid == null) {
|
|
|
|
links = JX.$N(
|
|
|
|
'span',
|
|
|
|
{
|
|
|
|
className: 'pholio-inline-head-links'
|
|
|
|
},
|
|
|
|
[
|
|
|
|
JX.$N('a',{href: 'http://www.google.fi'},'Edit'),
|
|
|
|
JX.$N('a',{href: 'http://www.google.fi'},'Delete')
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var comment_header = JX.$N(
|
|
|
|
'div',
|
|
|
|
{
|
|
|
|
className: 'pholio-inline-comment-header'
|
|
|
|
},
|
|
|
|
[comment_head, links]);
|
|
|
|
|
|
|
|
var comment_body = JX.$N(
|
|
|
|
'div',
|
|
|
|
{},
|
|
|
|
data.content);
|
|
|
|
|
|
|
|
var inline_comment = JX.$N(
|
|
|
|
'div',
|
|
|
|
{
|
|
|
|
id: data.phid + "_comment",
|
|
|
|
className: 'pholio-inline-comment'
|
|
|
|
},
|
|
|
|
[comment_header, comment_body]);
|
|
|
|
|
|
|
|
return inline_comment;
|
|
|
|
}
|
|
|
|
|
2013-02-08 16:24:17 +01:00
|
|
|
function load_inline_comments() {
|
|
|
|
var data = JX.Stratcom.getData(JX.$(config.mainID));
|
2013-02-13 16:10:14 +01:00
|
|
|
var comment_holder = JX.$('mock-inline-comments');
|
|
|
|
JX.DOM.setContent(comment_holder, '');
|
2013-02-08 16:24:17 +01:00
|
|
|
|
|
|
|
var inline_comments_url = "/pholio/inline/" + data['imageID'] + "/";
|
|
|
|
var inline_comments = new JX.Request(inline_comments_url, function(r) {
|
|
|
|
|
|
|
|
if (r.length > 0) {
|
|
|
|
for(i=0; i < r.length; i++) {
|
|
|
|
var inlineSelection = JX.$N(
|
|
|
|
'div',
|
|
|
|
{
|
2013-02-13 16:10:14 +01:00
|
|
|
id: r[i].phid + "_selection",
|
2013-02-08 16:24:17 +01:00
|
|
|
className: 'pholio-mock-select-border',
|
|
|
|
title: r[i].content
|
|
|
|
});
|
|
|
|
|
2013-02-13 16:10:14 +01:00
|
|
|
JX.Stratcom.addData(
|
|
|
|
inlineSelection,
|
|
|
|
{phid: r[i].phid});
|
|
|
|
|
|
|
|
JX.Stratcom.addSigil(inlineSelection, "image_selection");
|
|
|
|
JX.DOM.appendContent(comment_holder, forge_inline_comment(r[i]));
|
|
|
|
|
2013-02-08 16:24:17 +01:00
|
|
|
JX.DOM.appendContent(wrapper, inlineSelection);
|
|
|
|
|
|
|
|
JX.$V(r[i].x, r[i].y).setPos(inlineSelection);
|
2013-02-13 16:10:14 +01:00
|
|
|
JX.$V(r[i].width, r[i].height).setDim(inlineSelection);
|
|
|
|
|
|
|
|
if (r[i].transactionphid == null) {
|
|
|
|
|
|
|
|
var inlineDraft = JX.$N(
|
|
|
|
'div',{className: 'pholio-mock-select-fill'});
|
|
|
|
|
|
|
|
JX.$V(r[i].x, r[i].y).setPos(inlineDraft);
|
|
|
|
JX.$V(r[i].width, r[i].height).setDim(inlineDraft);
|
|
|
|
|
|
|
|
JX.Stratcom.addData(
|
|
|
|
inlineDraft,
|
|
|
|
{phid: r[i].phid});
|
|
|
|
|
|
|
|
JX.Stratcom.addSigil(inlineDraft, "image_selection");
|
|
|
|
JX.DOM.appendContent(wrapper, inlineDraft);
|
|
|
|
}
|
2013-02-08 16:24:17 +01:00
|
|
|
}
|
|
|
|
}
|
2013-02-13 16:10:14 +01:00
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'mouseover',
|
|
|
|
'image_selection',
|
|
|
|
function(e) {
|
|
|
|
var data = e.getNodeData('image_selection');
|
|
|
|
|
|
|
|
var inline_comment = JX.$(data.phid + "_comment");
|
|
|
|
JX.DOM.alterClass(inline_comment,
|
|
|
|
'pholio-mock-inline-comment-highlight', true);
|
|
|
|
});
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'mouseout',
|
|
|
|
'image_selection',
|
|
|
|
function(e) {
|
|
|
|
var data = e.getNodeData('image_selection');
|
|
|
|
|
|
|
|
var inline_comment = JX.$(data.phid + "_comment");
|
|
|
|
JX.DOM.alterClass(inline_comment,
|
|
|
|
'pholio-mock-inline-comment-highlight', false);
|
|
|
|
});
|
2013-02-08 16:24:17 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
inline_comments.send();
|
|
|
|
}
|
|
|
|
|
|
|
|
load_inline_comments();
|
2013-01-28 20:18:50 +01:00
|
|
|
});
|
|
|
|
|
2013-02-01 19:53:15 +01:00
|
|
|
|
|
|
|
|