2016-07-21 19:11:15 +08:00
|
|
|
//= require Sortable.min
|
|
|
|
|
2017-05-16 17:52:07 +08:00
|
|
|
(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');
|
2017-01-23 16:47:04 +08:00
|
|
|
|
2017-05-16 17:52:07 +08:00
|
|
|
$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"));
|
2019-09-18 17:47:33 +08:00
|
|
|
if (Array.isArray(data.data)) hot.loadData(data.data);
|
2019-09-05 14:35:28 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
hot.render()
|
|
|
|
}, 0)
|
2017-05-16 17:52:07 +08:00
|
|
|
}
|
2016-02-12 23:52:43 +08:00
|
|
|
});
|
2017-05-16 17:52:07 +08:00
|
|
|
}
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2022-10-24 19:07:10 +08:00
|
|
|
// On init
|
2017-05-16 17:52:07 +08:00
|
|
|
|
2018-07-19 23:56:42 +08:00
|
|
|
initHandsOnTable($(document));
|
2023-01-19 20:09:48 +08:00
|
|
|
|
2018-07-19 23:56:42 +08:00
|
|
|
SmartAnnotation.preventPropagation('.atwho-user-popover');
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
$("[data-action='collapse-steps']").click(function () {
|
|
|
|
$('.step .panel-collapse').collapse('hide');
|
2016-09-05 21:06:48 +08:00
|
|
|
});
|
2018-07-19 23:56:42 +08:00
|
|
|
});
|
2016-09-05 21:06:48 +08:00
|
|
|
|
2017-06-06 14:02:01 +08:00
|
|
|
global.initHandsOnTable = initHandsOnTable;
|
2023-01-19 20:09:48 +08:00
|
|
|
})(window);
|
2020-11-03 16:07:49 +08:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
// Reorder attachments
|
2020-09-25 21:06:09 +08:00
|
|
|
function reorderAttachmentsInit() {
|
2020-11-03 16:07:49 +08:00
|
|
|
$('#steps').on('click', '.attachments-actions .change-order', function(e){
|
2020-11-03 01:47:08 +08:00
|
|
|
var orderDropdown = $(this).closest('.dropdown-menu');
|
2020-09-25 21:06:09 +08:00
|
|
|
var assetsContainer = $(`.attachments[data-step-id=${orderDropdown.data('step-id')}]`)
|
|
|
|
var order = $(this).data('order');
|
|
|
|
e.preventDefault();
|
|
|
|
assetsContainer.data('order', order);
|
2020-11-03 01:47:08 +08:00
|
|
|
orderDropdown.find('.change-order').removeClass('selected');
|
|
|
|
$(this).addClass('selected');
|
2020-09-25 21:06:09 +08:00
|
|
|
assetsContainer.trigger('reorder');
|
2020-11-03 01:47:08 +08:00
|
|
|
$.post(orderDropdown.data('state-save-url'), {
|
2020-09-25 21:06:09 +08:00
|
|
|
assets: { order: order }
|
|
|
|
});
|
|
|
|
})
|
2019-06-11 16:08:33 +08:00
|
|
|
|
2020-11-03 16:07:49 +08:00
|
|
|
$('#steps').on('reorder', '.attachments', function() {
|
2020-10-16 17:00:57 +08:00
|
|
|
var assets = $(`.attachments[data-step-id=${$(this).data('step-id')}] .asset`);
|
2020-09-25 21:06:09 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2019-06-11 16:08:33 +08:00
|
|
|
|
2020-09-25 21:06:09 +08:00
|
|
|
return a.dataset.assetOrder > b.dataset.assetOrder ? 1 : -1
|
|
|
|
})
|
|
|
|
|
|
|
|
$.each(sortedAssets, function(i, element){
|
|
|
|
element.style.order = i
|
|
|
|
})
|
|
|
|
})
|
2020-11-04 20:08:40 +08:00
|
|
|
.on('DOMSubtreeModified', '.attachments', function() {
|
2020-10-28 18:45:47 +08:00
|
|
|
$(this).trigger('reorder');
|
|
|
|
})
|
2020-09-25 21:06:09 +08:00
|
|
|
$('.attachments').trigger('reorder');
|
2019-04-09 16:00:56 +08:00
|
|
|
}
|
|
|
|
|
2020-11-03 16:07:49 +08:00
|
|
|
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');
|
2020-12-22 22:25:30 +08:00
|
|
|
viewModeBtn.closest('.step').find('.attachments').html(result.html);
|
|
|
|
PdfPreview.initCanvas();
|
2020-08-31 15:23:56 +08:00
|
|
|
})
|
2020-11-03 16:07:49 +08:00
|
|
|
})
|
2020-08-31 15:23:56 +08:00
|
|
|
}
|
|
|
|
|
2020-11-03 16:07:49 +08:00
|
|
|
reorderAttachmentsInit();
|
|
|
|
initAssetViewModeToggle();
|
2022-09-09 21:42:53 +08:00
|
|
|
});
|