2016-07-21 19:11:15 +08:00
|
|
|
//= require Sortable.min
|
|
|
|
|
2023-08-29 20:18:28 +08:00
|
|
|
var protocolSteps = function() {
|
|
|
|
(function(global) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Creates handsontable where needed
|
|
|
|
function initHandsOnTable(root) {
|
|
|
|
root.find("[data-role='hot-table']").each(function() {
|
|
|
|
var $container = $(this).find("[data-role='step-hot-table']");
|
|
|
|
var contents = $(this).find('.hot-contents');
|
|
|
|
|
|
|
|
$container.handsontable({
|
|
|
|
startRows: <%= Constants::HANDSONTABLE_INIT_ROWS_CNT %>,
|
|
|
|
startCols: <%= Constants::HANDSONTABLE_INIT_COLS_CNT %>,
|
|
|
|
rowHeaders: true,
|
|
|
|
colHeaders: true,
|
|
|
|
fillHandle: false,
|
|
|
|
formulas: true,
|
|
|
|
cells: function (row, col, prop) {
|
|
|
|
var cellProperties = {};
|
|
|
|
|
|
|
|
if (col >= 0)
|
|
|
|
cellProperties.readOnly = true;
|
|
|
|
else
|
|
|
|
cellProperties.readOnly = false;
|
|
|
|
|
|
|
|
return cellProperties;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var hot = $container.handsontable('getInstance');
|
|
|
|
|
|
|
|
if (contents.attr("value")) {
|
|
|
|
var data = JSON.parse(contents.attr("value"));
|
|
|
|
if (Array.isArray(data.data)) hot.loadData(data.data);
|
|
|
|
setTimeout(() => {
|
|
|
|
hot.render()
|
|
|
|
}, 0)
|
2017-05-16 17:52:07 +08:00
|
|
|
}
|
|
|
|
});
|
2023-08-29 20:18:28 +08:00
|
|
|
}
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2023-08-29 20:18:28 +08:00
|
|
|
// On init
|
2017-05-16 17:52:07 +08:00
|
|
|
|
2023-08-29 20:18:28 +08:00
|
|
|
initHandsOnTable($(document));
|
2023-01-19 20:09:48 +08:00
|
|
|
|
2023-08-29 20:18:28 +08:00
|
|
|
SmartAnnotation.preventPropagation('.atwho-user-popover');
|
2018-07-19 23:56:42 +08:00
|
|
|
|
2023-08-29 20:18:28 +08:00
|
|
|
$(function () {
|
|
|
|
$("[data-action='collapse-steps']").click(function () {
|
|
|
|
$('.step .panel-collapse').collapse('hide');
|
|
|
|
});
|
2016-09-05 21:06:48 +08:00
|
|
|
});
|
|
|
|
|
2023-08-29 20:18:28 +08:00
|
|
|
global.initHandsOnTable = initHandsOnTable;
|
|
|
|
})(window);
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
// Reorder attachments
|
|
|
|
function reorderAttachmentsInit() {
|
|
|
|
$('#steps').on('click', '.attachments-actions .change-order', function(e){
|
|
|
|
var orderDropdown = $(this).closest('.dropdown-menu');
|
|
|
|
var assetsContainer = $(`.attachments[data-step-id=${orderDropdown.data('step-id')}]`)
|
|
|
|
var order = $(this).data('order');
|
|
|
|
e.preventDefault();
|
|
|
|
assetsContainer.data('order', order);
|
|
|
|
orderDropdown.find('.change-order').removeClass('selected');
|
|
|
|
$(this).addClass('selected');
|
|
|
|
assetsContainer.trigger('reorder');
|
|
|
|
$.post(orderDropdown.data('state-save-url'), {
|
|
|
|
assets: { order: order }
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
|
|
|
$('#steps').on('reorder', '.attachments', function() {
|
|
|
|
var assets = $(`.attachments[data-step-id=${$(this).data('step-id')}] .asset`);
|
|
|
|
var order = $(this).data('order');
|
|
|
|
var sortedAssets = assets.sort(function(a, b) {
|
|
|
|
if (a.dataset.assetOrder == b.dataset.assetOrder) {
|
|
|
|
if (order == 'new') {
|
|
|
|
return b.dataset.assetUpdatedAt - a.dataset.assetUpdatedAt;
|
|
|
|
} if (order == 'old') {
|
|
|
|
return a.dataset.assetUpdatedAt - b.dataset.assetUpdatedAt;
|
|
|
|
} if (order == 'atoz') {
|
|
|
|
return a.dataset.assetFileName.toLowerCase() > b.dataset.assetFileName.toLowerCase() ? 1 : -1;
|
|
|
|
} if (order == 'ztoa') {
|
|
|
|
return b.dataset.assetFileName.toLowerCase() > a.dataset.assetFileName.toLowerCase() ? 1 : -1;
|
|
|
|
}
|
2020-09-25 21:06:09 +08:00
|
|
|
}
|
2019-06-11 16:08:33 +08:00
|
|
|
|
2023-08-29 20:18:28 +08:00
|
|
|
return a.dataset.assetOrder > b.dataset.assetOrder ? 1 : -1
|
|
|
|
})
|
2020-09-25 21:06:09 +08:00
|
|
|
|
2023-08-29 20:18:28 +08:00
|
|
|
$.each(sortedAssets, function(i, element){
|
|
|
|
element.style.order = i
|
|
|
|
})
|
2020-09-25 21:06:09 +08:00
|
|
|
})
|
2023-08-29 20:18:28 +08:00
|
|
|
.on('DOMSubtreeModified', '.attachments', function() {
|
|
|
|
$(this).trigger('reorder');
|
2020-08-31 15:23:56 +08:00
|
|
|
})
|
2023-08-29 20:18:28 +08:00
|
|
|
$('.attachments').trigger('reorder');
|
|
|
|
}
|
|
|
|
|
|
|
|
function initAssetViewModeToggle(){
|
|
|
|
$('#steps').on('click', '.attachments-actions .attachments-view-mode', function () {
|
|
|
|
var viewModeBtn = $(this);
|
|
|
|
$.post(viewModeBtn.closest('.dropdown-menu').data('view-mode-url'), {
|
|
|
|
assets_view_mode: viewModeBtn.data('assets-view-mode')
|
|
|
|
}, function(result) {
|
|
|
|
viewModeBtn.closest('.dropdown-menu').find('.attachments-view-mode').removeClass('selected');
|
|
|
|
viewModeBtn.addClass('selected');
|
|
|
|
viewModeBtn.closest('.step').find('.attachments').html(result.html);
|
|
|
|
PdfPreview.initCanvas();
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2020-08-31 15:23:56 +08:00
|
|
|
|
2023-08-29 20:18:28 +08:00
|
|
|
reorderAttachmentsInit();
|
|
|
|
initAssetViewModeToggle();
|
|
|
|
});
|
|
|
|
}
|