2016-08-19 09:19:06 +02:00
|
|
|
/* Edit Node */
|
|
|
|
|
|
|
|
|
|
|
|
/* Move Node */
|
|
|
|
var movingMode = Cookies.getJSON('bcloud_moving_node');
|
|
|
|
|
|
|
|
|
|
|
|
function editNode(nodeId) {
|
|
|
|
|
|
|
|
// Remove the 'n_' suffix from the id
|
|
|
|
if (nodeId.substring(0, 2) == 'n_') {
|
|
|
|
nodeId = nodeId.substr(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
var url = '/nodes/' + nodeId + '/edit?embed=1';
|
|
|
|
$.get(url, function(dataHtml) {
|
|
|
|
// Update the DOM injecting the generate HTML into the page
|
|
|
|
$('#project_context').html(dataHtml);
|
|
|
|
updateUi(nodeId, 'edit');
|
|
|
|
})
|
|
|
|
.fail(function(dataResponse) {
|
|
|
|
$('#project_context').html($('<iframe id="server_error"/>'));
|
|
|
|
$('#server_error').attr('src', url);
|
|
|
|
})
|
|
|
|
.always(function(){
|
|
|
|
$('.button-edit-icon').addClass('pi-edit').removeClass('pi-spin spin');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Add Node */
|
|
|
|
function addNode(nodeTypeName, parentId) {
|
|
|
|
var url = '/nodes/create';
|
|
|
|
var node_props = {node_type_name: nodeTypeName, project_id: ProjectUtils.projectId()};
|
|
|
|
if (typeof(parentId) != 'undefined') {node_props.parent_id = parentId};
|
|
|
|
$.post(url, node_props)
|
|
|
|
.done(function(data) {
|
|
|
|
editNode(data.data.asset_id);
|
|
|
|
})
|
|
|
|
.always(function(){
|
|
|
|
$('.button-add-group-icon').addClass('pi-collection-plus').removeClass('pi-spin spin');
|
|
|
|
})
|
|
|
|
.fail(function(data){
|
2017-10-02 19:31:52 +02:00
|
|
|
toastr.error(data.status + ' - ' + data.statusText, 'Error creating node');
|
2016-08-19 09:19:06 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Edit Button */
|
|
|
|
$('#item_edit').click(function(e){
|
|
|
|
$('.button-edit-icon').addClass('pi-spin spin').removeClass('pi-edit');
|
|
|
|
// When clicking on the edit icon, embed the edit
|
|
|
|
e.preventDefault();
|
|
|
|
if (ProjectUtils.isProject()) {
|
|
|
|
window.location.replace(urlProjectEdit);
|
|
|
|
} else {
|
|
|
|
editNode(ProjectUtils.nodeId());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function moveModeEnter() {
|
|
|
|
$('#overlay-mode-move-container').addClass('visible');
|
|
|
|
$('.button-move').addClass('disabled');
|
|
|
|
|
|
|
|
// Scroll to top so we can see the instructions/buttons
|
|
|
|
$("#project_context-container").scrollTop(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveModeExit() {
|
|
|
|
/* Remove cookie, display current node, remove UI */
|
|
|
|
if (ProjectUtils.isProject()) {
|
|
|
|
displayProject(ProjectUtils.projectId());
|
|
|
|
} else {
|
|
|
|
displayNode(ProjectUtils.nodeId());
|
|
|
|
}
|
|
|
|
$('#overlay-mode-move-container').removeClass('visible');
|
|
|
|
$('.button-move').removeClass('disabled');
|
|
|
|
$('#item_move_accept').html('<i class="pi-check"></i> Move Here');
|
|
|
|
Cookies.remove('bcloud_moving_node');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$( document ).ready(function() {
|
|
|
|
if (movingMode) {
|
|
|
|
moveModeEnter();
|
|
|
|
} else {
|
|
|
|
$('#overlay-mode-move-container').removeClass('visible');
|
|
|
|
$('.button-move').removeClass('disabled');
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add Node Type Button */
|
|
|
|
$('.item_add_node').click(function(e){
|
|
|
|
e.preventDefault();
|
|
|
|
var nodeTypeName = $(this).data('node-type-name');
|
|
|
|
if (ProjectUtils.isProject()) {
|
|
|
|
addNode(nodeTypeName);
|
|
|
|
} else {
|
|
|
|
addNode(nodeTypeName, ProjectUtils.nodeId());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#item_move').click(function(e){
|
|
|
|
e.preventDefault();
|
|
|
|
moveModeEnter();
|
|
|
|
// Set the nodeId in the cookie
|
|
|
|
Cookies.set('bcloud_moving_node', { node_id: ProjectUtils.nodeId(), node_type: ProjectUtils.nodeType()});
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#item_move_accept").click(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var movingNodeId = Cookies.getJSON('bcloud_moving_node').node_id;
|
|
|
|
var moveNodeParams = {node_id: movingNodeId};
|
|
|
|
// If we are not at the root of the project, add the parent node id to the
|
|
|
|
// request params
|
|
|
|
if (!ProjectUtils.isProject()) {
|
|
|
|
moveNodeParams.dest_parent_node_id = ProjectUtils.nodeId();
|
|
|
|
}
|
|
|
|
|
|
|
|
$(this).html('<i class="pi-spin spin"></i> Moving...');
|
|
|
|
|
|
|
|
$.post(urlNodeMove, moveNodeParams,
|
|
|
|
function(data){
|
|
|
|
}).done(function() {
|
2017-10-02 19:31:52 +02:00
|
|
|
toastr.success('Moved!');
|
2016-08-19 09:19:06 +02:00
|
|
|
Cookies.remove('bcloud_moving_node');
|
|
|
|
moveModeExit();
|
|
|
|
$('#project_tree').jstree("refresh");
|
|
|
|
})
|
|
|
|
.fail(function(data){
|
2017-10-02 19:31:52 +02:00
|
|
|
toastr.error(data.status + ' - ' + data.statusText, 'Error moving node');
|
2016-08-19 09:19:06 +02:00
|
|
|
$(this).html('<i class="pi-check"></i> Move Here');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#item_move_cancel").click(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$('.button-edit-icon').addClass('pi-spin spin').removeClass('pi-cancel');
|
|
|
|
|
|
|
|
moveModeExit();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/* Featured Toggle */
|
|
|
|
$('#item_featured').click(function(e){
|
|
|
|
e.preventDefault();
|
|
|
|
$.post(urlNodeFeature, {node_id : ProjectUtils.nodeId()},
|
|
|
|
function(data){
|
|
|
|
// Feedback logic
|
|
|
|
})
|
|
|
|
.done(function(){
|
2017-10-02 19:31:52 +02:00
|
|
|
toastr.success('Featured status toggled');
|
2016-08-19 09:19:06 +02:00
|
|
|
})
|
|
|
|
.fail(function(data){
|
2017-10-02 19:31:52 +02:00
|
|
|
toastr.error(data.status + ' - ' + data.statusText, 'Error toggling featured status');
|
2016-08-19 09:19:06 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/* Project Header toggle */
|
|
|
|
$('#item_toggle_projheader').click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
$.post(urlNodeToggleProjHeader, {node_id: ProjectUtils.nodeId()})
|
|
|
|
.done(function (data) {
|
2017-10-02 19:31:52 +02:00
|
|
|
toastr.success('Project header ' + data.action + '!');
|
2016-08-19 09:19:06 +02:00
|
|
|
})
|
|
|
|
.fail(function (jsxhr) {
|
|
|
|
var content_type = jsxhr.getResponseHeader('Content-Type');
|
|
|
|
|
|
|
|
if(content_type.startsWith('application/json')) {
|
|
|
|
var data = jsxhr.responseJSON;
|
2017-10-02 19:31:52 +02:00
|
|
|
toastr.error(data.message, 'Error toggling header');
|
2016-08-19 09:19:06 +02:00
|
|
|
} else {
|
2017-10-02 19:31:52 +02:00
|
|
|
toastr.error(jsxhr.responseText, 'Error toggling header');
|
2016-08-19 09:19:06 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/* Delete */
|
|
|
|
$('#item_delete').click(function(e){
|
|
|
|
e.preventDefault();
|
|
|
|
if (ProjectUtils.isProject()) {
|
2017-12-22 16:27:05 +01:00
|
|
|
$.post(urlProjectDelete, {project_id: ProjectUtils.projectId()})
|
|
|
|
.done(function () {
|
|
|
|
// Redirect to the /p/ URL that shows deleted projects.
|
|
|
|
window.location.replace('/p/?deleted=1');
|
|
|
|
})
|
|
|
|
.fail(function(err) {
|
|
|
|
toastr.error(xhrErrorResponseMessage(err), 'Project deletion failed');
|
2016-08-19 09:19:06 +02:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$.post(urlNodeDelete, {node_id: ProjectUtils.nodeId()},
|
|
|
|
function (data) {
|
|
|
|
// Feedback logic
|
|
|
|
})
|
|
|
|
.done(function () {
|
2017-10-02 19:31:52 +02:00
|
|
|
toastr.success('Deleted!');
|
2016-08-19 09:19:06 +02:00
|
|
|
|
|
|
|
if (ProjectUtils.parentNodeId() != '') {
|
|
|
|
displayNode(ProjectUtils.parentNodeId());
|
|
|
|
} else {
|
|
|
|
// Display the project when the group is at the root of the tree
|
|
|
|
displayProject(ProjectUtils.projectId());
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(function(){
|
|
|
|
$('#project_tree').jstree('refresh');
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
})
|
|
|
|
.fail(function (data) {
|
2017-10-02 19:31:52 +02:00
|
|
|
toastr.error(data.status + ' - ' + data.statusText, 'Error deleting');
|
2016-08-19 09:19:06 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/* Toggle public */
|
|
|
|
$('#item_toggle_public').click(function(e){
|
|
|
|
e.preventDefault();
|
|
|
|
var currentNodeId = ProjectUtils.nodeId();
|
|
|
|
$.post(urlNodeTogglePublic, {node_id : currentNodeId},
|
|
|
|
function(data){
|
|
|
|
// Feedback logic
|
|
|
|
})
|
|
|
|
.done(function(data){
|
2017-10-02 19:31:52 +02:00
|
|
|
toastr.success(data.data.message);
|
2016-08-19 09:19:06 +02:00
|
|
|
displayNode(currentNodeId);
|
|
|
|
})
|
|
|
|
.fail(function(data){
|
2017-10-02 19:31:52 +02:00
|
|
|
toastr.error(data.status + ' - ' + data.statusText, 'Error toggling status');
|
2016-08-19 09:19:06 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$('ul.project-edit-tools').removeClass('disabled');
|
|
|
|
});
|