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;
|
2013-02-22 15:39:08 +01:00
|
|
|
var is_typing = false;
|
|
|
|
|
2013-02-01 19:53:15 +01:00
|
|
|
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-22 19:34:32 +01:00
|
|
|
var active_image;
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-02-22 19:34:32 +01:00
|
|
|
function get_image(id) {
|
|
|
|
for (var ii = 0; ii < config.images.length; ii++) {
|
|
|
|
if (config.images[ii].id == id) {
|
|
|
|
return config.images[ii];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function select_image(image_id) {
|
|
|
|
var image = get_image(image_id);
|
|
|
|
active_image = image;
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-02-22 19:34:32 +01:00
|
|
|
var main = JX.$(config.mainID);
|
|
|
|
main.src = image.fullURI;
|
|
|
|
JX.DOM.show(main);
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-02-22 19:34:32 +01:00
|
|
|
// NOTE: This is to clear inline comment reticles.
|
|
|
|
JX.DOM.setContent(wrapper, main);
|
|
|
|
|
|
|
|
load_inline_comments();
|
|
|
|
}
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'click',
|
|
|
|
'mock-thumbnail',
|
|
|
|
function(e) {
|
|
|
|
e.kill();
|
|
|
|
select_image(e.getNodeData('mock-thumbnail').imageID);
|
2013-02-01 19:53:15 +01:00
|
|
|
});
|
|
|
|
|
2013-02-22 19:34:32 +01:00
|
|
|
// Select and show the first image.
|
|
|
|
select_image(config.images[0].id);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
if (is_typing) {
|
|
|
|
JX.DOM.remove(JX.$('pholio-new-inline-comment-dialog'));
|
|
|
|
JX.DOM.remove(selection_fill);
|
|
|
|
JX.DOM.remove(selection_border);
|
|
|
|
}
|
|
|
|
|
2013-02-01 19:53:15 +01:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2013-02-23 15:27:35 +01:00
|
|
|
JX.Stratcom.listen(
|
|
|
|
['mouseover', 'mouseout'],
|
|
|
|
'image_selection',
|
|
|
|
function(e) {
|
|
|
|
var data = e.getNodeData('image_selection');
|
|
|
|
var comment = JX.$(data.phid + "_comment");
|
|
|
|
var highlight = (e.getType() == 'mouseover');
|
|
|
|
|
|
|
|
JX.DOM.alterClass(
|
|
|
|
comment,
|
|
|
|
'pholio-mock-inline-comment-highlight',
|
|
|
|
highlight);
|
|
|
|
});
|
|
|
|
|
2013-02-01 19:53:15 +01:00
|
|
|
JX.Stratcom.listen(
|
|
|
|
'mouseup',
|
|
|
|
null,
|
|
|
|
function(e) {
|
|
|
|
if (!is_dragging) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
is_dragging = false;
|
2013-02-22 15:39:08 +01:00
|
|
|
is_typing = true;
|
2013-02-01 19:53:15 +01:00
|
|
|
|
|
|
|
endPos = getRealXY(JX.$V(wrapper), JX.$V(e));
|
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
var create_inline = new JX.Request("/pholio/inline/save/", function(r) {
|
|
|
|
JX.DOM.appendContent(JX.$('pholio-mock-image-container'), JX.$H(r));
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
var dialog = JX.$('pholio-new-inline-comment-dialog');
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
var wrapperVector = JX.$V(wrapper);
|
|
|
|
var wrapperDimensions = JX.Vector.getDim(wrapper);
|
2013-02-06 20:28:03 +01:00
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
JX.$V(
|
|
|
|
wrapperVector.x + Math.max(startPos.x,endPos.x),
|
|
|
|
wrapperVector.y + Math.max(startPos.y,endPos.y)
|
|
|
|
).setPos(dialog);
|
|
|
|
|
|
|
|
});
|
|
|
|
create_inline.addData({mockID: config.mockID});
|
|
|
|
create_inline.send();
|
2013-02-06 20:28:03 +01:00
|
|
|
|
2013-01-28 20:18:50 +01:00
|
|
|
});
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-02-08 16:24:17 +01:00
|
|
|
function load_inline_comments() {
|
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
|
|
|
|
2013-02-22 19:34:32 +01:00
|
|
|
var id = active_image.id;
|
|
|
|
var inline_comments_uri = "/pholio/inline/" + id + "/";
|
2013-02-22 15:39:08 +01:00
|
|
|
var inline_comments = new JX.Request(inline_comments_uri, function(r) {
|
2013-02-08 16:24:17 +01:00
|
|
|
|
|
|
|
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-19 23:12:33 +01:00
|
|
|
className: 'pholio-mock-select-border'
|
2013-02-08 16:24:17 +01:00
|
|
|
});
|
|
|
|
|
2013-02-13 16:10:14 +01:00
|
|
|
JX.Stratcom.addData(
|
|
|
|
inlineSelection,
|
|
|
|
{phid: r[i].phid});
|
|
|
|
|
|
|
|
JX.Stratcom.addSigil(inlineSelection, "image_selection");
|
2013-02-19 23:12:33 +01:00
|
|
|
JX.DOM.appendContent(comment_holder, JX.$H(r[i].contentHTML));
|
2013-02-13 16:10:14 +01:00
|
|
|
|
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(
|
2013-02-19 23:12:33 +01:00
|
|
|
'div',
|
|
|
|
{
|
|
|
|
className: 'pholio-mock-select-fill',
|
|
|
|
id: r[i].phid + "_fill"
|
|
|
|
});
|
2013-02-13 16:10:14 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2013-02-08 16:24:17 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
inline_comments.send();
|
|
|
|
}
|
|
|
|
|
2013-02-22 15:39:08 +01:00
|
|
|
JX.Stratcom.listen(
|
|
|
|
'click',
|
|
|
|
'inline-delete',
|
|
|
|
function(e) {
|
|
|
|
var data = e.getNodeData('inline-delete');
|
|
|
|
e.kill();
|
|
|
|
interrupt_typing();
|
|
|
|
|
|
|
|
JX.DOM.hide(
|
|
|
|
JX.$(data.phid + "_comment"),
|
|
|
|
JX.$(data.phid + "_fill"),
|
|
|
|
JX.$(data.phid + "_selection"));
|
|
|
|
|
|
|
|
var deleteURI = '/pholio/inline/delete/' + data.id + '/';
|
|
|
|
var del = new JX.Request(deleteURI, function(r) {
|
|
|
|
|
|
|
|
});
|
|
|
|
del.send();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'click',
|
|
|
|
'inline-edit',
|
|
|
|
function(e) {
|
|
|
|
var data = e.getNodeData('inline-edit');
|
|
|
|
e.kill();
|
|
|
|
|
|
|
|
interrupt_typing();
|
|
|
|
|
|
|
|
var editURI = "/pholio/inline/edit/" + data.id + '/';
|
|
|
|
|
|
|
|
var edit_dialog = new JX.Request(editURI, function(r) {
|
|
|
|
var dialog = JX.$N(
|
|
|
|
'div',
|
|
|
|
{
|
|
|
|
className: 'pholio-edit-inline-popup'
|
|
|
|
},
|
|
|
|
JX.$H(r));
|
|
|
|
|
|
|
|
JX.DOM.setContent(JX.$(data.phid + '_comment'), dialog);
|
|
|
|
});
|
|
|
|
|
|
|
|
edit_dialog.send();
|
|
|
|
});
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'click',
|
|
|
|
'inline-edit-cancel',
|
|
|
|
function(e) {
|
|
|
|
var data = e.getNodeData('inline-edit-cancel');
|
|
|
|
e.kill();
|
|
|
|
load_inline_comment(data.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'click',
|
|
|
|
'inline-edit-submit',
|
|
|
|
function(e) {
|
|
|
|
var data = e.getNodeData('inline-edit-submit');
|
|
|
|
var editURI = "/pholio/inline/edit/" + data.id + '/';
|
|
|
|
e.kill();
|
|
|
|
|
|
|
|
var edit = new JX.Request(editURI, function(r) {
|
|
|
|
load_inline_comment(data.id);
|
|
|
|
});
|
|
|
|
edit.addData({
|
|
|
|
op: 'update',
|
|
|
|
content: JX.DOM.find(JX.$(data.phid + '_comment'), 'textarea').value
|
|
|
|
});
|
|
|
|
edit.send();
|
|
|
|
});
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'click',
|
|
|
|
'inline-save-cancel',
|
|
|
|
function(e) {
|
|
|
|
e.kill();
|
|
|
|
|
|
|
|
interrupt_typing();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'click',
|
|
|
|
'inline-save-submit',
|
|
|
|
function(e) {
|
|
|
|
e.kill();
|
|
|
|
|
|
|
|
var new_content = JX.DOM.find(
|
|
|
|
JX.$('pholio-new-inline-comment-dialog'),
|
|
|
|
'textarea').value;
|
|
|
|
|
|
|
|
if (new_content == null || new_content.length == 0) {
|
|
|
|
alert("Empty comment")
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var saveURI = "/pholio/inline/save/";
|
|
|
|
|
|
|
|
var inlineComment = new JX.Request(saveURI, function(r) {
|
|
|
|
if (!r.success) return;
|
|
|
|
|
|
|
|
JX.DOM.appendContent(
|
|
|
|
JX.$('mock-inline-comments'),
|
|
|
|
JX.$H(r.contentHTML));
|
|
|
|
|
|
|
|
JX.Stratcom.addSigil(selection_fill, 'image_selection');
|
|
|
|
selection_fill.id = r.phid + '_fill';
|
|
|
|
JX.Stratcom.addData(selection_fill, {phid: r.phid});
|
|
|
|
selection_border.id = r.phid + '_selection';
|
|
|
|
|
|
|
|
JX.DOM.remove(JX.$('pholio-new-inline-comment-dialog'));
|
|
|
|
is_typing = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
var commentToAdd = {
|
|
|
|
mockID: config.mockID,
|
|
|
|
op: 'save',
|
2013-02-22 19:34:32 +01:00
|
|
|
imageID: active_image.id,
|
2013-02-22 15:39:08 +01:00
|
|
|
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: new_content
|
|
|
|
};
|
|
|
|
|
|
|
|
inlineComment.addData(commentToAdd);
|
|
|
|
inlineComment.send();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
function load_inline_comment(id) {
|
|
|
|
var viewInlineURI = '/pholio/inline/view/' + id + '/';
|
|
|
|
var inline_comment = new JX.Request(viewInlineURI, function(r) {
|
|
|
|
JX.DOM.replace(JX.$(r.phid + '_comment'), JX.$H(r.contentHTML));
|
|
|
|
});
|
|
|
|
inline_comment.send();
|
|
|
|
}
|
|
|
|
|
|
|
|
function interrupt_typing() {
|
|
|
|
if (is_typing == true) {
|
|
|
|
JX.DOM.remove(selection_fill);
|
|
|
|
JX.DOM.remove(selection_border);
|
|
|
|
JX.DOM.remove(JX.$('pholio-new-inline-comment-dialog'));
|
|
|
|
is_typing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 16:24:17 +01:00
|
|
|
load_inline_comments();
|
2013-01-28 20:18:50 +01:00
|
|
|
});
|