2013-07-19 00:04:08 +02:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-pholio-mock-edit
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-stratcom
|
|
|
|
* javelin-dom
|
|
|
|
* javelin-workflow
|
Quicksand and Pholio - make mock edit work
Summary: Fixes T8036. In addition to making the mock edit work, this tightens quicksand code such that the correct page id is returned even if start() has not been called yet. It also tightens mock view where some functions should respect statics.enabled a bit more.
Test Plan:
clicked edit mock, mock crumb, edit mock, mock crum, edit mock, made edits and they worked! clicked edit mock, mock crumb, edit mock, mock crumb, edit mock, profile icon, hit browser back to edit mock, made edits and they worked!
also observed mock view page not occasionally wigging out from image_onload race not having statics.enabled respect during the above
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T8036
Differential Revision: https://secure.phabricator.com/D12739
2015-05-07 19:42:07 +02:00
|
|
|
* javelin-quicksand
|
2013-07-19 00:04:08 +02:00
|
|
|
* phabricator-phtize
|
|
|
|
* phabricator-drag-and-drop-file-upload
|
2013-08-12 21:08:54 +02:00
|
|
|
* phabricator-draggable-list
|
2013-07-19 00:04:08 +02:00
|
|
|
*/
|
Quicksand and Pholio - make mock edit work
Summary: Fixes T8036. In addition to making the mock edit work, this tightens quicksand code such that the correct page id is returned even if start() has not been called yet. It also tightens mock view where some functions should respect statics.enabled a bit more.
Test Plan:
clicked edit mock, mock crumb, edit mock, mock crum, edit mock, made edits and they worked! clicked edit mock, mock crumb, edit mock, mock crumb, edit mock, profile icon, hit browser back to edit mock, made edits and they worked!
also observed mock view page not occasionally wigging out from image_onload race not having statics.enabled respect during the above
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T8036
Differential Revision: https://secure.phabricator.com/D12739
2015-05-07 19:42:07 +02:00
|
|
|
JX.behavior('pholio-mock-edit', function(config, statics) {
|
2013-07-19 00:04:08 +02:00
|
|
|
var pht = JX.phtize(config.pht);
|
|
|
|
var uploading = [];
|
|
|
|
|
|
|
|
|
|
|
|
/* -( Deleting Images )---------------------------------------------------- */
|
|
|
|
|
2013-07-19 17:50:49 +02:00
|
|
|
|
|
|
|
// When the user clicks the "X" on an image, we replace it with a "click to
|
|
|
|
// undo" element. If they click to undo, we put the original node back in the
|
|
|
|
// DOM.
|
Quicksand and Pholio - make mock edit work
Summary: Fixes T8036. In addition to making the mock edit work, this tightens quicksand code such that the correct page id is returned even if start() has not been called yet. It also tightens mock view where some functions should respect statics.enabled a bit more.
Test Plan:
clicked edit mock, mock crumb, edit mock, mock crum, edit mock, made edits and they worked! clicked edit mock, mock crumb, edit mock, mock crumb, edit mock, profile icon, hit browser back to edit mock, made edits and they worked!
also observed mock view page not occasionally wigging out from image_onload race not having statics.enabled respect during the above
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T8036
Differential Revision: https://secure.phabricator.com/D12739
2015-05-07 19:42:07 +02:00
|
|
|
var pholio_drop_remove = function(e) {
|
2013-07-19 00:04:08 +02:00
|
|
|
e.kill();
|
2013-07-19 17:50:49 +02:00
|
|
|
|
|
|
|
var node = e.getNode('pholio-drop-image');
|
|
|
|
var undo = render_undo();
|
|
|
|
|
|
|
|
JX.DOM.listen(undo, 'click', 'pholio-drop-undo', function(e) {
|
|
|
|
e.kill();
|
|
|
|
JX.DOM.replace(undo, node);
|
2013-08-12 22:09:07 +02:00
|
|
|
synchronize_order();
|
2013-07-19 17:50:49 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
JX.DOM.replace(node, undo);
|
2013-08-12 22:09:07 +02:00
|
|
|
synchronize_order();
|
Quicksand and Pholio - make mock edit work
Summary: Fixes T8036. In addition to making the mock edit work, this tightens quicksand code such that the correct page id is returned even if start() has not been called yet. It also tightens mock view where some functions should respect statics.enabled a bit more.
Test Plan:
clicked edit mock, mock crumb, edit mock, mock crum, edit mock, made edits and they worked! clicked edit mock, mock crumb, edit mock, mock crumb, edit mock, profile icon, hit browser back to edit mock, made edits and they worked!
also observed mock view page not occasionally wigging out from image_onload race not having statics.enabled respect during the above
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T8036
Differential Revision: https://secure.phabricator.com/D12739
2015-05-07 19:42:07 +02:00
|
|
|
};
|
2013-07-19 00:04:08 +02:00
|
|
|
|
2013-07-19 17:50:49 +02:00
|
|
|
|
2013-08-12 21:08:54 +02:00
|
|
|
/* -( Reordering Images )-------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
// Reflect the display order in a hidden input.
|
|
|
|
var synchronize_order = function() {
|
Quicksand and Pholio - make mock edit work
Summary: Fixes T8036. In addition to making the mock edit work, this tightens quicksand code such that the correct page id is returned even if start() has not been called yet. It also tightens mock view where some functions should respect statics.enabled a bit more.
Test Plan:
clicked edit mock, mock crumb, edit mock, mock crum, edit mock, made edits and they worked! clicked edit mock, mock crumb, edit mock, mock crumb, edit mock, profile icon, hit browser back to edit mock, made edits and they worked!
also observed mock view page not occasionally wigging out from image_onload race not having statics.enabled respect during the above
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T8036
Differential Revision: https://secure.phabricator.com/D12739
2015-05-07 19:42:07 +02:00
|
|
|
var items = statics.draglist.findItems();
|
2013-08-12 21:08:54 +02:00
|
|
|
var order = [];
|
|
|
|
for (var ii = 0; ii < items.length; ii++) {
|
|
|
|
order.push(JX.Stratcom.getData(items[ii]).filePHID);
|
|
|
|
}
|
Quicksand and Pholio - make mock edit work
Summary: Fixes T8036. In addition to making the mock edit work, this tightens quicksand code such that the correct page id is returned even if start() has not been called yet. It also tightens mock view where some functions should respect statics.enabled a bit more.
Test Plan:
clicked edit mock, mock crumb, edit mock, mock crum, edit mock, made edits and they worked! clicked edit mock, mock crumb, edit mock, mock crumb, edit mock, profile icon, hit browser back to edit mock, made edits and they worked!
also observed mock view page not occasionally wigging out from image_onload race not having statics.enabled respect during the above
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T8036
Differential Revision: https://secure.phabricator.com/D12739
2015-05-07 19:42:07 +02:00
|
|
|
statics.nodes.order.value = order.join(',');
|
2013-08-12 21:08:54 +02:00
|
|
|
};
|
|
|
|
|
Quicksand and Pholio - make mock edit work
Summary: Fixes T8036. In addition to making the mock edit work, this tightens quicksand code such that the correct page id is returned even if start() has not been called yet. It also tightens mock view where some functions should respect statics.enabled a bit more.
Test Plan:
clicked edit mock, mock crumb, edit mock, mock crum, edit mock, made edits and they worked! clicked edit mock, mock crumb, edit mock, mock crumb, edit mock, profile icon, hit browser back to edit mock, made edits and they worked!
also observed mock view page not occasionally wigging out from image_onload race not having statics.enabled respect during the above
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T8036
Differential Revision: https://secure.phabricator.com/D12739
2015-05-07 19:42:07 +02:00
|
|
|
|
|
|
|
var build_draglist = function(node) {
|
|
|
|
var draglist = new JX.DraggableList('pholio-drop-image', node)
|
|
|
|
.setGhostNode(JX.$N('div', {className: 'drag-ghost'}))
|
|
|
|
.setFindItemsHandler(function() {
|
|
|
|
return JX.DOM.scry(node, 'div', 'pholio-drop-image');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Only let the user drag images by the handle, not the whole entry.
|
|
|
|
draglist.listen('shouldBeginDrag', function(e) {
|
|
|
|
if (!e.getNode('pholio-drag-handle')) {
|
|
|
|
JX.Stratcom.context().prevent();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
draglist.listen('didDrop', synchronize_order);
|
|
|
|
return draglist;
|
|
|
|
};
|
2013-08-12 21:08:54 +02:00
|
|
|
|
|
|
|
|
2013-07-19 23:07:22 +02:00
|
|
|
/* -( Build )-------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
var build_drop_upload = function(node) {
|
|
|
|
var drop = new JX.PhabricatorDragAndDropFileUpload(node)
|
|
|
|
.setURI(config.uploadURI);
|
|
|
|
|
2014-06-23 19:27:47 +02:00
|
|
|
drop.listen('didBeginDrag', function() {
|
2013-07-19 23:07:22 +02:00
|
|
|
JX.DOM.alterClass(node, 'pholio-drop-active', true);
|
|
|
|
});
|
|
|
|
|
2014-06-23 19:27:47 +02:00
|
|
|
drop.listen('didEndDrag', function() {
|
2013-07-19 23:07:22 +02:00
|
|
|
JX.DOM.alterClass(node, 'pholio-drop-active', false);
|
|
|
|
});
|
|
|
|
|
|
|
|
return drop;
|
|
|
|
};
|
|
|
|
|
|
|
|
var build_add_control = function(add_node) {
|
|
|
|
var drop = build_drop_upload(add_node);
|
|
|
|
|
|
|
|
drop.listen('willUpload', function(file) {
|
|
|
|
var node = render_uploading();
|
|
|
|
uploading.push({node: node, file: file});
|
Quicksand and Pholio - make mock edit work
Summary: Fixes T8036. In addition to making the mock edit work, this tightens quicksand code such that the correct page id is returned even if start() has not been called yet. It also tightens mock view where some functions should respect statics.enabled a bit more.
Test Plan:
clicked edit mock, mock crumb, edit mock, mock crum, edit mock, made edits and they worked! clicked edit mock, mock crumb, edit mock, mock crumb, edit mock, profile icon, hit browser back to edit mock, made edits and they worked!
also observed mock view page not occasionally wigging out from image_onload race not having statics.enabled respect during the above
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T8036
Differential Revision: https://secure.phabricator.com/D12739
2015-05-07 19:42:07 +02:00
|
|
|
statics.nodes.list.appendChild(node);
|
2013-07-19 23:07:22 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
drop.listen('didUpload', function(file) {
|
|
|
|
var node;
|
|
|
|
for (var ii = 0; ii < uploading.length; ii++) {
|
|
|
|
if (uploading[ii].file === file) {
|
|
|
|
node = uploading[ii].node;
|
|
|
|
uploading.splice(ii, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-09 17:34:00 +02:00
|
|
|
render_upload(node, file);
|
|
|
|
});
|
|
|
|
|
|
|
|
drop.start();
|
|
|
|
|
|
|
|
JX.DOM.listen(add_node, 'click', null, function(e) {
|
|
|
|
e.kill();
|
2013-07-19 23:07:22 +02:00
|
|
|
|
2016-06-09 17:34:00 +02:00
|
|
|
new JX.Workflow('/file/uploaddialog/')
|
2013-07-19 23:07:22 +02:00
|
|
|
.setHandler(function(response) {
|
2016-06-09 17:34:00 +02:00
|
|
|
var files = response.files;
|
|
|
|
for (var ii = 0; ii < files.length; ii++) {
|
|
|
|
var file = files[ii];
|
2013-07-19 23:07:22 +02:00
|
|
|
|
2016-06-09 17:34:00 +02:00
|
|
|
var upload = new JX.PhabricatorFileUpload()
|
|
|
|
.setID(file.id)
|
|
|
|
.setPHID(file.phid)
|
|
|
|
.setURI(file.uri);
|
|
|
|
|
|
|
|
var node = render_uploading();
|
|
|
|
statics.nodes.list.appendChild(node);
|
|
|
|
|
|
|
|
render_upload(node, upload);
|
|
|
|
}
|
2013-07-19 23:07:22 +02:00
|
|
|
})
|
|
|
|
.start();
|
|
|
|
});
|
2016-06-09 17:34:00 +02:00
|
|
|
};
|
2013-07-19 23:07:22 +02:00
|
|
|
|
2016-06-09 17:34:00 +02:00
|
|
|
var render_upload = function(node, file) {
|
|
|
|
JX.DOM.setContent(node, pht('uploaded'));
|
|
|
|
|
|
|
|
new JX.Workflow(config.renderURI, {filePHID: file.getPHID()})
|
|
|
|
.setHandler(function(response) {
|
|
|
|
var new_node = JX.$H(response.markup).getFragment().firstChild;
|
|
|
|
build_update_control(new_node);
|
|
|
|
|
|
|
|
JX.DOM.replace(node, new_node);
|
|
|
|
synchronize_order();
|
|
|
|
})
|
|
|
|
.start();
|
2013-07-19 23:07:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var build_list_controls = function(list_node) {
|
|
|
|
var nodes = JX.DOM.scry(list_node, 'div', 'pholio-drop-image');
|
|
|
|
for (var ii = 0; ii < nodes.length; ii++) {
|
|
|
|
build_update_control(nodes[ii]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var build_update_control = function(node) {
|
2016-06-09 17:34:00 +02:00
|
|
|
var did_upload = function(node, file) {
|
2013-07-19 23:07:22 +02:00
|
|
|
var node_data = JX.Stratcom.getData(node);
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
filePHID: file.getPHID(),
|
|
|
|
replacesPHID: node_data.replacesPHID || node_data.filePHID || null,
|
|
|
|
title: JX.DOM.find(node, 'input', 'image-title').value,
|
|
|
|
description: JX.DOM.find(node, 'textarea', 'image-description').value
|
|
|
|
};
|
|
|
|
|
|
|
|
new JX.Workflow(config.renderURI, data)
|
|
|
|
.setHandler(function(response) {
|
|
|
|
var new_node = JX.$H(response.markup).getFragment().firstChild;
|
|
|
|
build_update_control(new_node);
|
|
|
|
|
|
|
|
JX.DOM.replace(node, new_node);
|
|
|
|
JX.DOM.alterClass(node, 'pholio-replacing', false);
|
2013-08-12 22:09:07 +02:00
|
|
|
synchronize_order();
|
2013-07-19 23:07:22 +02:00
|
|
|
})
|
|
|
|
.start();
|
2016-06-09 17:34:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var drop = build_drop_upload(node);
|
|
|
|
|
|
|
|
drop.listen('willUpload', function() {
|
|
|
|
JX.DOM.alterClass(node, 'pholio-replacing', true);
|
|
|
|
});
|
|
|
|
|
|
|
|
drop.listen('didUpload', function(file) {
|
|
|
|
did_upload(node, file);
|
2013-07-19 23:07:22 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
drop.start();
|
2016-06-09 17:34:00 +02:00
|
|
|
|
|
|
|
JX.DOM.listen(node, 'click', 'pholio-uploaded-thumb', function(e) {
|
|
|
|
e.kill();
|
|
|
|
|
|
|
|
new JX.Workflow('/file/uploaddialog/single/')
|
|
|
|
.setHandler(function(response) {
|
|
|
|
var files = response.files;
|
|
|
|
for (var ii = 0; ii < files.length; ii++) {
|
|
|
|
var file = files[ii];
|
|
|
|
|
|
|
|
var upload = new JX.PhabricatorFileUpload()
|
|
|
|
.setID(file.id)
|
|
|
|
.setPHID(file.phid)
|
|
|
|
.setURI(file.uri);
|
|
|
|
|
|
|
|
did_upload(node, upload);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.start();
|
|
|
|
});
|
2013-07-19 23:07:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-07-19 17:50:49 +02:00
|
|
|
/* -( Rendering )---------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
var render_uploading = function() {
|
|
|
|
return JX.$N(
|
|
|
|
'div',
|
|
|
|
{className: 'pholio-drop-uploading'},
|
|
|
|
pht('uploading'));
|
|
|
|
};
|
|
|
|
|
|
|
|
var render_undo = function() {
|
|
|
|
var link = JX.$N(
|
|
|
|
'a',
|
|
|
|
{href: '#', sigil: 'pholio-drop-undo'},
|
|
|
|
pht('undo'));
|
|
|
|
|
|
|
|
return JX.$N(
|
|
|
|
'div',
|
|
|
|
{className: 'pholio-drop-undo'},
|
|
|
|
[pht('removed'), ' ', link]);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-07-19 23:07:22 +02:00
|
|
|
/* -( Init )--------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
Quicksand and Pholio - make mock edit work
Summary: Fixes T8036. In addition to making the mock edit work, this tightens quicksand code such that the correct page id is returned even if start() has not been called yet. It also tightens mock view where some functions should respect statics.enabled a bit more.
Test Plan:
clicked edit mock, mock crumb, edit mock, mock crum, edit mock, made edits and they worked! clicked edit mock, mock crumb, edit mock, mock crumb, edit mock, profile icon, hit browser back to edit mock, made edits and they worked!
also observed mock view page not occasionally wigging out from image_onload race not having statics.enabled respect during the above
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T8036
Differential Revision: https://secure.phabricator.com/D12739
2015-05-07 19:42:07 +02:00
|
|
|
function update_statics(data, page_id, no_build) {
|
|
|
|
statics.nodes = {
|
|
|
|
list: JX.$(data.listID),
|
|
|
|
drop: JX.$(data.dropID),
|
|
|
|
order: JX.$(data.orderID)
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!statics.mockEditCache[page_id]) {
|
|
|
|
statics.mockEditCache[page_id] = {};
|
|
|
|
}
|
|
|
|
statics.mockEditCache[page_id].config = config;
|
|
|
|
statics.mockEditCache[page_id].nodes = statics.nodes;
|
|
|
|
|
|
|
|
if (no_build !== true) {
|
|
|
|
build_add_control(statics.nodes.drop);
|
|
|
|
build_list_controls(statics.nodes.list);
|
|
|
|
statics.draglist = build_draglist(statics.nodes.list);
|
|
|
|
statics.mockEditCache[page_id].draglist = statics.draglist;
|
|
|
|
} else {
|
|
|
|
statics.draglist = statics.mockEditCache[page_id].draglist;
|
|
|
|
}
|
|
|
|
synchronize_order();
|
|
|
|
}
|
|
|
|
|
|
|
|
function install() {
|
|
|
|
statics.mockEditCache = {};
|
|
|
|
JX.Stratcom.listen('click', 'pholio-drop-remove', pholio_drop_remove);
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'quicksand-redraw',
|
|
|
|
null,
|
|
|
|
function (e) {
|
|
|
|
e.kill();
|
|
|
|
|
|
|
|
var data = e.getData();
|
|
|
|
if (!data.newResponse.mockEditConfig) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (data.fromServer) {
|
|
|
|
// we ran update_statics(config) below already
|
|
|
|
} else {
|
|
|
|
var page_id = data.newResponseID;
|
|
|
|
var new_config = statics.mockEditCache[page_id].config;
|
|
|
|
update_statics(new_config, page_id, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
statics.installed = statics.installed || install();
|
|
|
|
update_statics(config, JX.Quicksand.getCurrentPageID(), false);
|
2013-07-19 00:04:08 +02:00
|
|
|
});
|