2019-04-12 21:45:57 +00:00
|
|
|
var electron = require('electron');
|
|
|
|
|
2018-04-15 00:39:59 +00:00
|
|
|
$.postJSON = function(url, data, success=null) {
|
|
|
|
return $.ajax(url, {
|
|
|
|
type: 'POST',
|
|
|
|
data: JSON.stringify(data),
|
|
|
|
contentType: 'application/json',
|
|
|
|
success: success
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-06-04 03:24:26 +00:00
|
|
|
var realistic_rendering = {};
|
2018-06-09 03:16:08 +00:00
|
|
|
var realistic_cache = {};
|
2018-06-04 03:24:26 +00:00
|
|
|
var normal_rendering = {};
|
|
|
|
|
2018-07-12 19:16:22 +00:00
|
|
|
//function to chunk opd view into pieces
|
|
|
|
// source: https://stackoverflow.com/questions/3366529/wrap-every-3-divs-in-a-div
|
|
|
|
$.fn.chunk = function(size) {
|
|
|
|
var arr = [];
|
|
|
|
for (var i = 0; i < this.length; i += size) {
|
|
|
|
arr.push(this.slice(i, i + size));
|
|
|
|
}
|
|
|
|
return this.pushStack(arr, "chunk", size);
|
|
|
|
}
|
|
|
|
|
|
|
|
// build operator detailed view (opd)
|
|
|
|
function buildOpd(thumbnail_size = $('#operator-detailedview-thumbnail-size').val() ) {
|
|
|
|
|
|
|
|
var thumbnail_size = parseInt(thumbnail_size);
|
|
|
|
var thumbnail_size_mm = thumbnail_size + 'mm';
|
|
|
|
|
|
|
|
var thumbnail_layout = (thumbnail_size >= 60) ? 'medium' : 'small';
|
|
|
|
|
|
|
|
// remove old settings
|
2018-10-17 15:03:55 +00:00
|
|
|
$('div.page.operator-detailedview header').remove();
|
|
|
|
$('div.page.operator-detailedview footer').remove();
|
|
|
|
$('div.page.operator-detailedview .job-headline').remove();
|
2018-07-12 19:16:22 +00:00
|
|
|
$('div.page.operator-detailedview .opd-color-block').parentsUntil('div.page.operator-detailedview').addBack().unwrap();
|
|
|
|
$('.opd-color-block').removeClass('medium large');
|
|
|
|
$('.opd-color-block').removeAttr('style');
|
|
|
|
|
|
|
|
// set thumbnail size
|
|
|
|
$('.operator-svg.operator-preview').css({
|
|
|
|
'width': thumbnail_size_mm,
|
|
|
|
'height': thumbnail_size_mm,
|
|
|
|
'max-width': thumbnail_size_mm
|
|
|
|
});
|
|
|
|
|
|
|
|
// calculate number of blocks per page
|
|
|
|
var num_blocks_per_page = 1;
|
|
|
|
if(thumbnail_layout == 'medium') {
|
|
|
|
$('.opd-color-block').addClass('medium');
|
|
|
|
// set width to be able to calculate the height
|
|
|
|
$('.opd-color-block').css({ 'width': thumbnail_size_mm });
|
|
|
|
// calculate max height -> source: https://stackoverflow.com/questions/6060992/element-with-the-max-height-from-a-set-of-elements
|
|
|
|
var color_box_height = Math.max.apply(null, $('.opd-color-block').map(function () { return $(this).height(); }).get());
|
|
|
|
var container_height = $('#opd-info').height();
|
|
|
|
var num_rows = Math.floor(container_height / color_box_height);
|
|
|
|
var num_columns = Math.floor(175 / thumbnail_size);
|
|
|
|
// if only two blocks fit into one row, use 50% of the space for each of them
|
|
|
|
if(num_columns == 2) { $('.opd-color-block').css({ 'width': 'calc(50% - 2mm)' }); }
|
|
|
|
// set equal height for all color blocks
|
|
|
|
$('.opd-color-block').css({ 'height': color_box_height });
|
|
|
|
// set number of color blocks per page for medium thumbnails
|
|
|
|
num_blocks_per_page = num_columns * num_rows;
|
|
|
|
// use layout for large thumbnails if only 2 or less color blocks fit on one page
|
|
|
|
if(num_blocks_per_page <= 2) {
|
|
|
|
$('.opd-color-block').removeClass('medium').removeAttr('style').addClass('large');
|
|
|
|
thumbnail_layout = 'large';
|
|
|
|
// set number of color blocks per page for large thumbnails
|
|
|
|
num_blocks_per_page = 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// set number of color blocks per page for small thumbnails
|
|
|
|
num_blocks_per_page = Math.floor(220 / thumbnail_size);
|
|
|
|
}
|
|
|
|
// set number of color blocks per page to 1 if it defaults to zero
|
|
|
|
// this should never happen, but we want to avoid the browser to crash
|
|
|
|
num_blocks_per_page = (num_blocks_per_page <= 0) ? '1' : num_blocks_per_page;
|
|
|
|
|
|
|
|
// adjust to new settings
|
|
|
|
var header = $('#opd-info header').prop('outerHTML');
|
|
|
|
var footer = $('#opd-info footer').prop('outerHTML');
|
|
|
|
var job_headline = $('#opd-info .job-headline').prop('outerHTML');
|
|
|
|
var opd_visibility = ($('#operator-detailedview').is(':checked')) ? 'block' :'none';
|
|
|
|
var paper_size = $('#printing-size').val();
|
|
|
|
$('.opd-color-block').chunk(num_blocks_per_page).wrap('<div class="page operator-detailedview ' + paper_size + ' ' + thumbnail_layout +'" style="display:'+ opd_visibility +'"><main class="operator-detailedview"><div class="operator-job-info"></div></main></div>');
|
|
|
|
$('div.operator-detailedview').prepend(header);
|
|
|
|
$('.operator-job-info').prepend(job_headline);
|
|
|
|
$('div.operator-detailedview').append(footer);
|
|
|
|
// update page numbers
|
|
|
|
setPageNumbers();
|
|
|
|
}
|
|
|
|
|
2018-03-31 00:37:11 +00:00
|
|
|
// set pagenumbers
|
|
|
|
function setPageNumbers() {
|
|
|
|
var totalPageNum = $('body').find('.page:visible').length;
|
|
|
|
$('span.total-page-num').text(totalPageNum);
|
2018-10-31 00:06:31 +00:00
|
|
|
$('.page:visible span.page-num').each(function( index ) {
|
2018-03-31 00:37:11 +00:00
|
|
|
$(this).text(index + 1);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-31 00:06:31 +00:00
|
|
|
// Calculate estimated time
|
|
|
|
function setEstimatedTime() {
|
|
|
|
var speed = Math.floor($('#machine-speed').val() / 60); // convert to seconds
|
|
|
|
speed = (speed <= 0) ? 1 : speed;
|
|
|
|
var timeTrim = ($('#time-trims').val() == '') ? 0 : parseInt($('#time-trims').val());
|
|
|
|
var addToTotal = ($('#time-additional').val() == '') ? 0 : parseInt($('#time-additional').val());
|
|
|
|
var timeColorChange = ($('#time-color-change').val() == '') ? 0 : parseInt($('#time-color-change').val());
|
|
|
|
|
|
|
|
// operator detailed view
|
|
|
|
$('.estimated-time').each(function(index, item) {
|
|
|
|
var selector = $(this);
|
|
|
|
var stitchCount = parseInt($(selector).closest('p').find('.num-stitches').text().match(/\d+/));
|
|
|
|
var numTrims = parseInt($( selector ).closest('div').find('p span.num-trims').text().match(/\d+/));
|
|
|
|
var estimatedTime = stitchCount/speed + (timeTrim * numTrims);
|
|
|
|
writeEstimatedTime( selector, estimatedTime );
|
|
|
|
});
|
|
|
|
|
|
|
|
// client detailed view
|
|
|
|
$('.cld-estimated-time').each(function(index, item) {
|
|
|
|
var selector = $(this);
|
|
|
|
var stitchCount = parseInt($(selector).closest('div.page').find('main .detailed .color-info span.num-stitches').text().match(/\d+/));
|
|
|
|
var numTrims = parseInt($( selector ).closest('div.page').find('main .detailed .color-info span.num-trims').text().match(/\d+/));
|
|
|
|
var estimatedTime = stitchCount/speed + (timeTrim * numTrims);
|
|
|
|
writeEstimatedTime( selector, estimatedTime );
|
|
|
|
});
|
|
|
|
|
|
|
|
var stitchCount = parseInt($('.total-num-stitches').first().text().match(/\d+/));
|
|
|
|
var numTrims = parseInt($('.total-trims').first().text().match(/\d+/));
|
|
|
|
var numColorBlocks = parseInt($('.num-color-blocks').first().text().match(/\d+/))-1; // the last color-block is not a color change
|
|
|
|
var selector = '.total-estimated-time';
|
|
|
|
var estimatedTime = stitchCount/speed + (timeTrim * numTrims) + (timeColorChange * numColorBlocks) + addToTotal;
|
|
|
|
writeEstimatedTime( selector, estimatedTime );
|
|
|
|
}
|
|
|
|
|
|
|
|
function attachLeadingZero(n) {
|
|
|
|
return (n < 10) ? ("0" + n) : n;
|
|
|
|
}
|
|
|
|
|
|
|
|
function writeEstimatedTime( selector, estimatedTime ) {
|
|
|
|
var hours = attachLeadingZero(Math.floor(estimatedTime / 3600));
|
|
|
|
var minutes = attachLeadingZero(Math.floor((estimatedTime - (hours*3600)) / 60));
|
|
|
|
var seconds = attachLeadingZero(Math.floor(estimatedTime % 60));
|
|
|
|
$(selector).text( hours + ':' + minutes + ':' + seconds );
|
|
|
|
}
|
|
|
|
|
2018-04-09 17:20:02 +00:00
|
|
|
// Scale SVG (fit || full size)
|
|
|
|
function scaleSVG(element, scale = 'fit') {
|
2018-04-21 20:23:13 +00:00
|
|
|
|
2018-04-09 17:20:02 +00:00
|
|
|
// always center svg
|
|
|
|
transform = "translate(-50%, -50%)";
|
2018-04-21 20:23:13 +00:00
|
|
|
|
2018-04-09 17:20:02 +00:00
|
|
|
if(scale == 'fit') {
|
2018-03-31 00:37:11 +00:00
|
|
|
var scale = Math.min(
|
2018-04-21 20:23:13 +00:00
|
|
|
element.width() / element.find('svg').width(),
|
2018-04-09 17:20:02 +00:00
|
|
|
element.height() / element.find('svg').height()
|
2018-03-31 00:37:11 +00:00
|
|
|
);
|
2018-04-09 17:20:02 +00:00
|
|
|
}
|
2018-04-21 20:23:13 +00:00
|
|
|
|
2018-04-09 17:20:02 +00:00
|
|
|
transform += " scale(" + scale + ")";
|
|
|
|
var label = parseInt(scale*100);
|
2018-03-31 00:37:11 +00:00
|
|
|
|
2018-04-09 17:20:02 +00:00
|
|
|
element.find('svg').css({ transform: transform });
|
2018-04-17 19:48:38 +00:00
|
|
|
element.find('.scale').text(label);
|
2018-04-09 17:20:02 +00:00
|
|
|
}
|
2018-03-31 00:37:11 +00:00
|
|
|
|
2018-07-12 19:16:22 +00:00
|
|
|
// set preview svg scale to fit into its box if display block and transform is not set
|
2018-04-11 16:57:55 +00:00
|
|
|
function scaleAllSvg() {
|
2018-10-31 00:06:31 +00:00
|
|
|
$('.page').each(function() {
|
|
|
|
if( $(this).css('display') == 'block' ) {
|
|
|
|
if( $(this).find('.inksimulation svg').css('transform') == 'none') {
|
|
|
|
scaleSVG($(this).find('.inksimulation'), 'fit');
|
2018-04-11 16:57:55 +00:00
|
|
|
}
|
2018-10-31 00:06:31 +00:00
|
|
|
}
|
|
|
|
});
|
2018-03-31 00:37:11 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 20:09:43 +00:00
|
|
|
var saveTimerHandles = {};
|
|
|
|
|
|
|
|
function setSVGTransform(figure, transform) {
|
2018-10-31 00:06:31 +00:00
|
|
|
var field_name = $(figure).data('field-name');
|
|
|
|
var scale = transform.match(/-?[\d\.]+/g)[0];
|
|
|
|
figure.find('svg').css({ transform: transform });
|
|
|
|
figure.find(".scale").text(parseInt(scale*100));
|
|
|
|
|
|
|
|
// avoid spamming updates
|
|
|
|
if (saveTimerHandles[field_name] != null)
|
|
|
|
clearTimeout(saveTimerHandles[field_name]);
|
|
|
|
|
|
|
|
saveTimerHandles[field_name] = setTimeout(function() {
|
|
|
|
$.postJSON('/settings/' + field_name, {value: transform});
|
|
|
|
}, 250);
|
2018-04-18 20:09:43 +00:00
|
|
|
}
|
|
|
|
|
2018-03-31 00:37:11 +00:00
|
|
|
$(function() {
|
2018-04-09 17:20:02 +00:00
|
|
|
/* SCALING AND MOVING SVG */
|
2018-04-21 20:23:13 +00:00
|
|
|
|
2018-04-09 17:20:02 +00:00
|
|
|
/* Mousewheel scaling */
|
|
|
|
$('figure.inksimulation').on( 'DOMMouseScroll mousewheel', function (e) {
|
2018-04-18 17:20:33 +00:00
|
|
|
if(e.ctrlKey == true) {
|
2018-04-21 20:23:13 +00:00
|
|
|
|
2018-04-11 16:57:55 +00:00
|
|
|
var svg = $(this).find('svg');
|
|
|
|
var transform = svg.css('transform').match(/-?[\d\.]+/g);
|
|
|
|
var scale = parseFloat(transform[0]);
|
2018-04-21 20:23:13 +00:00
|
|
|
|
2018-04-17 01:15:39 +00:00
|
|
|
if (e.originalEvent.detail > 0 || e.originalEvent.wheelDelta < 0) {
|
|
|
|
// scroll down = zoom out
|
|
|
|
scale *= 0.97;
|
|
|
|
if (scale < 0.01)
|
|
|
|
scale = 0.01;
|
2018-04-11 16:57:55 +00:00
|
|
|
} else {
|
|
|
|
//scroll up
|
2018-04-17 01:15:39 +00:00
|
|
|
scale *= 1.03;
|
2018-04-11 16:57:55 +00:00
|
|
|
}
|
2018-04-21 20:23:13 +00:00
|
|
|
|
2018-04-11 16:57:55 +00:00
|
|
|
// set modified scale
|
|
|
|
transform[0] = scale;
|
|
|
|
transform[3] = scale;
|
2018-04-18 20:09:43 +00:00
|
|
|
|
|
|
|
setSVGTransform($(this), 'matrix(' + transform + ')');
|
2018-04-08 15:34:35 +00:00
|
|
|
|
2018-04-11 16:57:55 +00:00
|
|
|
//prevent page fom scrolling
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-08 15:34:35 +00:00
|
|
|
});
|
2018-04-21 20:23:13 +00:00
|
|
|
|
2018-04-09 17:20:02 +00:00
|
|
|
/* Fit SVG */
|
|
|
|
$('button.svg-fit').click(function() {
|
|
|
|
var svgfigure = $(this).closest('figure');
|
|
|
|
scaleSVG(svgfigure, 'fit');
|
|
|
|
});
|
2018-04-21 20:23:13 +00:00
|
|
|
|
2018-04-11 16:57:55 +00:00
|
|
|
/* Full Size SVG */
|
2018-04-09 17:20:02 +00:00
|
|
|
$('button.svg-full').click(function() {
|
|
|
|
var svgfigure = $(this).closest('figure');
|
|
|
|
scaleSVG(svgfigure, '1');
|
|
|
|
});
|
2018-04-21 20:23:13 +00:00
|
|
|
|
2018-04-08 15:34:35 +00:00
|
|
|
/* Drag SVG */
|
|
|
|
$('figure.inksimulation').on('mousedown', function(e) {
|
2018-04-17 19:01:38 +00:00
|
|
|
var p0 = { x: e.pageX, y: e.pageY };
|
|
|
|
var start_transform = $(this).find('svg').css('transform').match(/-?[\d\.]+/g);
|
|
|
|
var start_offset = { x: parseFloat(start_transform[4]), y: parseFloat(start_transform[5]) };
|
|
|
|
|
|
|
|
$(this).css({cursor: 'move'});
|
|
|
|
$(this).on('mousemove', function(e) {
|
2018-10-31 00:06:31 +00:00
|
|
|
var p1 = { x: e.pageX, y: e.pageY };
|
|
|
|
// set modified translate
|
|
|
|
var transform = $(this).find('svg').css('transform').match(/-?[\d\.]+/g);
|
|
|
|
transform[4] = start_offset.x + (p1.x - p0.x);
|
|
|
|
transform[5] = start_offset.y + (p1.y - p0.y);
|
|
|
|
|
|
|
|
// I'd ike to use setSVGTransform() here but this code runs many
|
|
|
|
// times per second and it's just too CPU-intensive.
|
|
|
|
$(this).find('svg').css({transform: 'matrix(' + transform + ')'});
|
|
|
|
});
|
2018-04-08 15:34:35 +00:00
|
|
|
}).on('mouseup', function(e) {
|
2018-04-17 19:01:38 +00:00
|
|
|
$(this).css({cursor: 'auto'});
|
|
|
|
$(this).data('p0', null);
|
|
|
|
$(this).off('mousemove');
|
2018-04-18 20:09:43 +00:00
|
|
|
|
|
|
|
// set it using setSVGTransform() to ensure that it's saved to the server
|
|
|
|
setSVGTransform($(this), $(this).find('svg').css('transform'));
|
2018-04-17 19:01:38 +00:00
|
|
|
});
|
2018-04-21 20:23:13 +00:00
|
|
|
|
2018-06-04 03:24:26 +00:00
|
|
|
// ignore mouse events on the buttons (Fill, 100%, Apply to All)
|
|
|
|
$('figure.inksimulation div').on('mousedown mouseup', function(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2018-04-11 16:57:55 +00:00
|
|
|
/* Apply transforms to All */
|
|
|
|
$('button.svg-apply').click(function() {
|
|
|
|
var transform = $(this).parent().siblings('svg').css('transform');
|
|
|
|
$('.inksimulation').each(function() {
|
2018-04-18 20:09:43 +00:00
|
|
|
setSVGTransform($(this), transform);
|
2018-04-11 16:57:55 +00:00
|
|
|
})
|
|
|
|
});
|
2018-04-14 01:23:00 +00:00
|
|
|
|
2018-03-31 00:37:11 +00:00
|
|
|
/* Contendeditable Fields */
|
2018-04-14 01:23:00 +00:00
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
$('body').on('focusout', '[contenteditable="true"]:not(.info-text)', function() {
|
2018-11-15 16:39:25 +00:00
|
|
|
/* change svg scale */
|
2018-10-17 15:03:55 +00:00
|
|
|
var content = $(this).text();
|
2018-04-14 01:23:00 +00:00
|
|
|
var field_name = $(this).attr('data-field-name');
|
2018-04-17 01:03:46 +00:00
|
|
|
if(field_name == 'svg-scale') {
|
|
|
|
var scale = parseInt(content);
|
|
|
|
var svg = $(this).parent().siblings('svg');
|
|
|
|
var transform = svg.css('transform').match(/-?[\d\.]+/g);
|
|
|
|
|
|
|
|
transform[0] = scale / 100;
|
|
|
|
transform[3] = scale / 100;
|
|
|
|
svg.css({ transform: 'matrix(' + transform + ')' });
|
|
|
|
} else {
|
|
|
|
/* When we focus out from a contenteditable field, we want to
|
|
|
|
* set the same content to all fields with the same classname */
|
2018-10-17 15:03:55 +00:00
|
|
|
$('[data-field-name="' + field_name + '"]').text(content);
|
2018-04-17 01:03:46 +00:00
|
|
|
$.postJSON('/settings/' + field_name, {value: content});
|
|
|
|
}
|
2018-03-31 00:37:11 +00:00
|
|
|
});
|
2018-04-14 01:23:00 +00:00
|
|
|
|
2018-04-14 03:39:49 +00:00
|
|
|
// load up initial metadata values
|
2018-04-17 00:17:07 +00:00
|
|
|
$.getJSON('/settings', function(settings) {
|
2018-04-17 19:48:38 +00:00
|
|
|
$.each(settings, function(field_name, value) {
|
2018-10-31 00:06:31 +00:00
|
|
|
$('[data-field-name="' + field_name + '"]').each(function(i, item) {
|
|
|
|
var item = $(item);
|
|
|
|
if (item.is(':checkbox')) {
|
|
|
|
item.prop('checked', value).trigger('initialize');
|
|
|
|
} else if (item.is('img')) {
|
|
|
|
item.attr('src', value);
|
|
|
|
} else if (item.is('select')) {
|
|
|
|
item.val(value).trigger('initialize');
|
|
|
|
} else if (item.is('input[type=range]')) {
|
|
|
|
item.val(value).trigger('initialize');
|
|
|
|
$('#display-thumbnail-size').text(value + 'mm');
|
|
|
|
} else if (item.is('input[type=number]')) {
|
|
|
|
item.val(value).trigger('initialize');
|
|
|
|
} else if (item.is('figure.inksimulation')) {
|
|
|
|
setSVGTransform(item, value);
|
2018-11-15 16:39:25 +00:00
|
|
|
} else if (item.is('div.footer-info')) {
|
2019-04-02 04:21:53 +00:00
|
|
|
$('#footer-info-text').html($.parseHTML(value));
|
|
|
|
item.html($.parseHTML(value));
|
2019-03-26 17:24:02 +00:00
|
|
|
} else if (item.is('#custom-page-content')) {
|
2019-04-02 04:21:53 +00:00
|
|
|
$('#custom-page-content').html($.parseHTML(value));
|
2018-10-31 00:06:31 +00:00
|
|
|
} else {
|
|
|
|
item.text(value);
|
|
|
|
}
|
|
|
|
});
|
2018-04-17 19:48:38 +00:00
|
|
|
});
|
2018-06-04 03:24:26 +00:00
|
|
|
|
2018-07-12 19:16:22 +00:00
|
|
|
// wait until page size is set (if they've specified one) and then scale SVGs to fit and build operator detailed view
|
|
|
|
setTimeout(function() {
|
|
|
|
scaleAllSvg();
|
|
|
|
buildOpd();
|
|
|
|
}, 500);
|
2018-04-14 03:39:49 +00:00
|
|
|
});
|
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
$('body').on('keypress', '[contenteditable="true"]:not(.info-text)', function(e) {
|
2018-10-31 00:06:31 +00:00
|
|
|
if (e.which == 13) {
|
|
|
|
// pressing enter defocuses the element
|
|
|
|
this.blur();
|
|
|
|
// also suppress the enter keystroke to avoid adding a new line
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2018-04-14 01:23:00 +00:00
|
|
|
|
2018-11-15 16:39:25 +00:00
|
|
|
$('#footer-info-text[contenteditable="true"]').keypress(function(e) {
|
|
|
|
if (e.which == 13) {
|
|
|
|
if($(this).find('div').length > 2) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
$('.info-text[contenteditable="true"]').focusout(function() {
|
|
|
|
updateEditableText($(this));
|
2018-11-15 16:39:25 +00:00
|
|
|
});
|
|
|
|
|
2018-03-31 00:37:11 +00:00
|
|
|
/* Settings Bar */
|
2018-04-14 01:23:00 +00:00
|
|
|
|
2018-03-31 00:37:11 +00:00
|
|
|
$('button.close').click(function() {
|
2019-04-11 03:37:16 +00:00
|
|
|
window.close();
|
2018-03-31 00:37:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$('button.print').click(function() {
|
2019-04-12 21:45:57 +00:00
|
|
|
var pageSize = $('select#printing-size').find(':selected').text();
|
2019-04-18 14:15:13 +00:00
|
|
|
electron.ipcRenderer.send('open-pdf', pageSize)
|
2018-03-31 00:37:11 +00:00
|
|
|
});
|
|
|
|
|
2019-04-18 14:15:13 +00:00
|
|
|
$('button.save-pdf').click(function() {
|
|
|
|
var pageSize = $('select#printing-size').find(':selected').text();
|
|
|
|
electron.ipcRenderer.send('save-pdf', pageSize)
|
|
|
|
});
|
|
|
|
|
2018-03-31 00:37:11 +00:00
|
|
|
$('button.settings').click(function(){
|
|
|
|
$('#settings-ui').show();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#close-settings').click(function(){
|
|
|
|
$('#settings-ui').hide();
|
|
|
|
});
|
2018-04-14 01:23:00 +00:00
|
|
|
|
2018-03-31 00:37:11 +00:00
|
|
|
/* Settings */
|
2018-04-14 01:23:00 +00:00
|
|
|
|
2018-07-12 19:16:22 +00:00
|
|
|
// Settings Tabs
|
|
|
|
$('#tabs button').click(function() {
|
|
|
|
var active_fieldset_position = $(this).index() +1;
|
|
|
|
$('#settings-ui #fieldsets-ui > fieldset').css({'display': 'none'});
|
|
|
|
$('#settings-ui #fieldsets-ui > fieldset:nth-child('+active_fieldset_position+')').css({'display': 'block'});
|
|
|
|
$('#tabs .tab.active').removeClass("active");
|
|
|
|
$(this).addClass("active");
|
|
|
|
});
|
|
|
|
|
2018-11-15 16:39:25 +00:00
|
|
|
// Footer
|
2019-03-26 17:24:02 +00:00
|
|
|
function getEditMode(element){
|
|
|
|
return element.closest('fieldset').find('.switch-mode').prop('checked');
|
2018-11-15 16:39:25 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
$('.switch-mode').change(function() {
|
|
|
|
var element = $(this);
|
|
|
|
var info_text = element.closest('fieldset').find('.info-text');
|
|
|
|
var editMode = getEditMode(element);
|
2018-11-15 16:39:25 +00:00
|
|
|
if (editMode) {
|
2019-03-26 17:24:02 +00:00
|
|
|
info_text.text( info_text.html() );
|
|
|
|
element.closest('.tool-bar').find('.tb-button.edit-only').prop("disabled", true);
|
2018-11-15 16:39:25 +00:00
|
|
|
} else {
|
2019-03-26 17:24:02 +00:00
|
|
|
info_text.css('display', 'block');
|
|
|
|
var sourceText = info_text.text();
|
2019-04-02 04:21:53 +00:00
|
|
|
info_text.html( $.parseHTML(sourceText) );
|
2019-03-26 17:24:02 +00:00
|
|
|
element.closest('.tool-bar').find('.tb-button.edit-only').prop('disabled', false);
|
2018-11-15 16:39:25 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
function updateEditableText(element) {
|
|
|
|
var editMode = getEditMode(element);
|
|
|
|
var info_text = element.closest('fieldset').find('.info-text');
|
|
|
|
var editableText = '';
|
|
|
|
|
2018-11-15 16:39:25 +00:00
|
|
|
if (editMode) {
|
2019-03-26 17:24:02 +00:00
|
|
|
editableText = info_text.text();
|
|
|
|
} else {
|
|
|
|
editableText = info_text.html();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(info_text.is('#footer-info-text')) {
|
2019-04-02 04:21:53 +00:00
|
|
|
$('div.footer-info').html($.parseHTML(editableText));
|
|
|
|
$.postJSON('/settings/footer-info', {value: editableText});
|
2018-11-15 16:39:25 +00:00
|
|
|
} else {
|
2019-04-02 04:21:53 +00:00
|
|
|
$.postJSON('/settings/custom-page-content', {value: editableText});
|
2018-11-15 16:39:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatText(selection, value) {
|
|
|
|
if(window.getSelection().toString()){
|
|
|
|
document.execCommand(selection, false, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
$('.tb-bold').click(function() {
|
|
|
|
if(!getEditMode($(this))) {
|
|
|
|
formatText('bold');
|
|
|
|
updateEditableText($(this));
|
|
|
|
}
|
2018-11-15 16:39:25 +00:00
|
|
|
});
|
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
$('.tb-italic').click(function() {
|
|
|
|
if(!getEditMode($(this))) {
|
|
|
|
formatText('italic');
|
|
|
|
updateEditableText($(this));
|
|
|
|
}
|
2018-11-15 16:39:25 +00:00
|
|
|
});
|
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
$('.tb-underline').click(function() {
|
|
|
|
if(!getEditMode($(this))) {
|
|
|
|
formatText('underline');
|
|
|
|
updateEditableText($(this));
|
|
|
|
}
|
2018-11-15 16:39:25 +00:00
|
|
|
});
|
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
$('.tb-remove').click(function() {
|
|
|
|
if(!getEditMode($(this))) {
|
|
|
|
formatText('removeFormat');
|
|
|
|
updateEditableText($(this));
|
|
|
|
}
|
2018-11-15 16:39:25 +00:00
|
|
|
});
|
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
$('.tb-hyperlink').click(function() {
|
|
|
|
if(!getEditMode($(this))) {
|
|
|
|
formatText('createlink', 'tempurl');
|
|
|
|
updateEditableText($(this));
|
|
|
|
$(this).closest('.tool-bar').children('.url-window').css('display', 'block');
|
|
|
|
}
|
2018-11-15 16:39:25 +00:00
|
|
|
});
|
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
$('.url-ok').click(function() {
|
|
|
|
var link = $(this).closest('.tool-bar').find('.user-url').val();
|
|
|
|
$(this).closest('fieldset').find('.info-text').find('a[href="tempurl"]').attr('href', link);
|
|
|
|
$('.user-url').val('https://');
|
|
|
|
$('.url-window').css('display', 'none');
|
|
|
|
updateEditableText($(this));
|
2018-11-15 16:39:25 +00:00
|
|
|
});
|
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
$('.url-cancel').click(function() {
|
|
|
|
$(this).closest('fieldset').find('.info-text').find('a[href="tempurl"]').contents().unwrap();
|
|
|
|
$('.user-url').val('https://');
|
|
|
|
$('.url-window').css('display', 'none');
|
|
|
|
updateEditableText($(this));
|
2018-11-15 16:39:25 +00:00
|
|
|
});
|
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
$('.tb-mail').click(function() {
|
|
|
|
if(!getEditMode($(this))) {
|
|
|
|
formatText('createlink', 'tempurl');
|
|
|
|
updateEditableText($(this));
|
|
|
|
$(this).closest('.tool-bar').find('.mail-window').css('display', 'block');
|
|
|
|
}
|
2018-11-15 16:39:25 +00:00
|
|
|
});
|
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
$('.mail-ok').click(function() {
|
|
|
|
var link = 'mailto:' + $(this).closest('.tool-bar').find('.user-mail').val();
|
|
|
|
$(this).closest('fieldset').find('.info-text').find('a[href="tempurl"]').attr('href', link);
|
|
|
|
$('.user-mail').val('@');
|
|
|
|
$('.mail-window').css('display', 'none');
|
|
|
|
updateEditableText($(this));
|
2018-11-15 16:39:25 +00:00
|
|
|
});
|
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
$('.mail-cancel').click(function() {
|
|
|
|
$(this).closest('fieldset').find('.info-text').find('a[href="tempurl"]').contents().unwrap();
|
|
|
|
$('.user-mail').val('@');
|
|
|
|
$('.mail-window').css('display', 'none');
|
|
|
|
updateEditableText($(this));
|
2018-11-15 16:39:25 +00:00
|
|
|
});
|
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
$('.tb-reset').click(function() {
|
|
|
|
$(this).closest('.tool-bar').find('.reset-window').css('display', 'block');
|
2018-11-15 16:39:25 +00:00
|
|
|
});
|
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
$('.reset-ok').click(function() {
|
|
|
|
var htmlMode = getEditMode($(this));
|
2018-11-15 16:39:25 +00:00
|
|
|
if(!htmlMode) {
|
2019-03-26 17:24:02 +00:00
|
|
|
$(this).closest('fieldset').find('.info-text').html($(this).closest('.tool-bar').find('.original-info').html());
|
2018-11-15 16:39:25 +00:00
|
|
|
} else {
|
2019-03-26 17:24:02 +00:00
|
|
|
$(this).closest('fieldset').find('.info-text').text($(this).closest('.tool-bar').find('.original-info').html());
|
2018-11-15 16:39:25 +00:00
|
|
|
}
|
2019-03-26 17:24:02 +00:00
|
|
|
$('.reset-window').css('display', 'none');
|
|
|
|
updateEditableText($(this));
|
2018-11-15 16:39:25 +00:00
|
|
|
});
|
|
|
|
|
2019-03-26 17:24:02 +00:00
|
|
|
$('.reset-cancel').click(function() {
|
|
|
|
$('.reset-window').css('display', 'none');
|
2018-11-15 16:39:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$('body').on("click", ".edit-footer-link", function() {
|
|
|
|
$("button.settings").trigger("click");
|
|
|
|
$("#branding-tab").trigger("click");
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-03-31 00:37:11 +00:00
|
|
|
// Paper Size
|
2018-04-24 04:22:45 +00:00
|
|
|
$('select#printing-size').on('change initialize', function(){
|
|
|
|
$('.page').toggleClass('a4', $(this).find(':selected').val() == 'a4');
|
|
|
|
}).on('change', function() {
|
|
|
|
$.postJSON('/settings/paper-size', {value: $(this).find(':selected').val()});
|
2018-03-31 00:37:11 +00:00
|
|
|
});
|
2018-07-12 19:16:22 +00:00
|
|
|
|
|
|
|
// Operator detailed view: thumbnail size setting
|
|
|
|
$(document).on('input', '#operator-detailedview-thumbnail-size', function() {
|
|
|
|
var thumbnail_size_mm = $(this).val() + 'mm';
|
2018-10-31 00:06:31 +00:00
|
|
|
$('#display-thumbnail-size').text( thumbnail_size_mm );
|
2018-07-12 19:16:22 +00:00
|
|
|
});
|
2018-10-31 00:06:31 +00:00
|
|
|
|
2018-07-12 19:16:22 +00:00
|
|
|
// Operator detailed view: thumbnail size setting action
|
|
|
|
$('#operator-detailedview-thumbnail-size').change(function() {
|
|
|
|
// set thumbnail size
|
|
|
|
var thumbnail_size = $(this).val();
|
|
|
|
// set page break positions
|
|
|
|
buildOpd(thumbnail_size);
|
|
|
|
|
|
|
|
$.postJSON('/settings/operator-detailedview-thumbnail-size', {value: thumbnail_size});
|
|
|
|
});
|
2018-04-14 01:23:00 +00:00
|
|
|
|
2018-04-24 03:12:48 +00:00
|
|
|
// Thread Palette
|
|
|
|
$('select#thread-palette').change(function(){
|
|
|
|
$('.modal').show();
|
|
|
|
}).on('update', function() {
|
|
|
|
$(this).data('current-value', $(this).find(':selected').val());
|
|
|
|
}).trigger('update');
|
|
|
|
|
|
|
|
$('#modal-yes').on('click', function(){
|
|
|
|
$("select#thread-palette").trigger("update");
|
|
|
|
$('.modal').hide();
|
2018-04-24 04:22:45 +00:00
|
|
|
var body = {'name': $('select#thread-palette').find(':selected').val()};
|
|
|
|
$.postJSON('/palette', body, function() {
|
|
|
|
$.getJSON('/threads', function(threads) {
|
|
|
|
console.log("threads: " + JSON.stringify(threads));
|
|
|
|
$.each(threads, function(i, thread) {
|
|
|
|
console.log("doing: " + JSON.stringify(thread));
|
|
|
|
$('[data-field-name="color-' + thread.hex + '"]').text(thread.name);
|
|
|
|
var thread_description = thread.manufacturer;
|
|
|
|
if (thread.number) {
|
|
|
|
thread_description += " #" + thread.number;
|
|
|
|
}
|
|
|
|
$('[data-field-name="thread-' + thread.hex + '"]').text(thread_description);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-04-24 03:12:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#modal-no').on('click', function(){
|
|
|
|
var select = $("select#thread-palette");
|
|
|
|
select.find('[value="' + select.data('current-value') + '"]').prop('selected', true);
|
|
|
|
$('.modal').hide();
|
|
|
|
});
|
|
|
|
|
2018-06-04 03:24:26 +00:00
|
|
|
// View selection checkboxes
|
|
|
|
$(':checkbox.view').on('change initialize', function() {
|
2018-04-15 00:39:59 +00:00
|
|
|
var field_name = $(this).attr('data-field-name');
|
2018-04-24 04:22:45 +00:00
|
|
|
$('.' + field_name).toggle($(this).prop('checked'));
|
2018-07-12 19:16:22 +00:00
|
|
|
scaleAllSvg();
|
2018-03-31 00:37:11 +00:00
|
|
|
setPageNumbers();
|
2018-04-24 04:22:45 +00:00
|
|
|
}).on('change', function() {
|
2018-06-03 19:57:25 +00:00
|
|
|
var field_name = $(this).attr('data-field-name');
|
2018-04-24 04:22:45 +00:00
|
|
|
$.postJSON('/settings/' + field_name, {value: $(this).prop('checked')});
|
2018-03-31 00:37:11 +00:00
|
|
|
});
|
2018-04-14 01:23:00 +00:00
|
|
|
|
2018-10-31 00:06:31 +00:00
|
|
|
// Estimated Time
|
|
|
|
$('#machine-speed, #time-additional, #time-color-change, #time-trims').on('input initialize', function() {
|
|
|
|
setEstimatedTime();
|
|
|
|
}).on('change', function() {
|
|
|
|
var field_name = $(this).attr('data-field-name');
|
|
|
|
$.postJSON('/settings/' + field_name, {value: $(this).val()});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Display Estimated Time checkboxes
|
|
|
|
$(':checkbox.time-display').on('input initialize', function() {
|
|
|
|
var field_name = $(this).attr('data-field-name');
|
|
|
|
$('.' + field_name).toggle($(this).prop('checked'));
|
|
|
|
}).on('change', function() {
|
|
|
|
var field_name = $(this).attr('data-field-name');
|
|
|
|
$.postJSON('/settings/' + field_name, {value: $(this).prop('checked')});
|
|
|
|
});
|
|
|
|
|
2018-06-04 03:24:26 +00:00
|
|
|
// Realistic rendering checkboxes
|
|
|
|
$(':checkbox.realistic').on('change', function(e) {
|
|
|
|
console.log("realistic rendering checkbox");
|
|
|
|
|
|
|
|
var item = $(this).data('field-name');
|
|
|
|
var figure = $(this).closest('figure');
|
|
|
|
var svg = figure.find('svg');
|
|
|
|
var transform = svg.css('transform');
|
|
|
|
var checked = $(this).prop('checked');
|
|
|
|
|
|
|
|
console.log("" + item + " " + transform);
|
|
|
|
|
2018-06-09 03:16:08 +00:00
|
|
|
function finalize(svg_content) {
|
|
|
|
svg[0].outerHTML = svg_content;
|
|
|
|
// can't use the svg variable here because setting outerHTML created a new tag
|
|
|
|
figure.find('svg').css({transform: transform});
|
|
|
|
}
|
|
|
|
|
2018-06-04 03:24:26 +00:00
|
|
|
// do this later to allow this event handler to return now,
|
|
|
|
// which will cause the checkbox to be checked or unchecked
|
|
|
|
// immediately even if SVG rendering takes awhile
|
|
|
|
setTimeout(function() {
|
|
|
|
if (checked) {
|
|
|
|
if (!(item in normal_rendering)) {
|
|
|
|
normal_rendering[item] = svg[0].outerHTML;
|
|
|
|
}
|
2018-06-09 03:16:08 +00:00
|
|
|
|
|
|
|
if (!(item in realistic_cache)) {
|
|
|
|
// pre-render the realistic SVG to a raster image to spare the poor browser
|
|
|
|
var image = document.createElement('img');
|
|
|
|
image.onload = function() {
|
|
|
|
console.log("rendering!");
|
|
|
|
var canvas = document.createElement('canvas');
|
|
|
|
|
|
|
|
// maybe make DPI configurable? for now, use 600
|
|
|
|
canvas.width = image.width / 96 * 600;
|
|
|
|
canvas.height = image.height / 96 * 600;
|
|
|
|
|
|
|
|
var ctx = canvas.getContext('2d');
|
2019-04-15 23:56:44 +00:00
|
|
|
ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);
|
|
|
|
realistic_cache[item] = '<svg width=' + image.width + ' height=' + image.height + ' xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' +
|
|
|
|
'<image x=0 y=0 width=' + image.width + ' height=' + image.height + ' xlink:href="' + canvas.toDataURL() + '" />' +
|
|
|
|
'</svg>';
|
|
|
|
finalize(realistic_cache[item]);
|
2018-06-09 03:16:08 +00:00
|
|
|
};
|
|
|
|
image.src = '/realistic/' + item;
|
|
|
|
} else {
|
|
|
|
finalize(realistic_cache[item]);
|
|
|
|
}
|
2018-06-04 03:24:26 +00:00
|
|
|
} else {
|
2018-06-09 03:16:08 +00:00
|
|
|
finalize(normal_rendering[item]);
|
2018-06-04 03:24:26 +00:00
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
2018-10-31 00:06:31 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
setEstimatedTime();
|
|
|
|
}, 100);
|
|
|
|
|
2018-06-04 03:24:26 +00:00
|
|
|
$('button.svg-realistic').click(function(e){
|
|
|
|
$(this).find('input').click();
|
|
|
|
});
|
|
|
|
|
2018-04-17 00:17:07 +00:00
|
|
|
// Logo
|
2018-11-15 16:39:25 +00:00
|
|
|
$(document).on("change", ".logo-picker", function(e) {
|
|
|
|
var file = e.currentTarget.files[0];
|
2018-10-31 00:06:31 +00:00
|
|
|
var reader = new FileReader();
|
|
|
|
reader.onloadend = function() {
|
|
|
|
var data = reader.result;
|
|
|
|
$('figure.brandlogo img').attr('src', data);
|
|
|
|
$.postJSON('/settings/logo', {value: data});
|
|
|
|
};
|
|
|
|
reader.readAsDataURL(file);
|
2018-04-17 00:17:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// "save as defaults" button
|
2018-10-31 00:06:31 +00:00
|
|
|
$('button.save-settings').click(function(e) {
|
|
|
|
var settings = {};
|
|
|
|
settings["client-overview"] = $("[data-field-name='client-overview']").is(':checked');
|
|
|
|
settings["client-detailedview"] = $("[data-field-name='client-detailedview']").is(':checked');
|
|
|
|
settings["operator-overview"] = $("[data-field-name='operator-overview']").is(':checked');
|
|
|
|
settings["operator-detailedview"] = $("[data-field-name='operator-detailedview']").is(':checked');
|
|
|
|
settings["operator-detailedview-thumbnail-size"] = $("[data-field-name='operator-detailedview-thumbnail-size']").val();
|
2019-03-26 17:24:02 +00:00
|
|
|
settings["custom-page"] = $("[data-field-name='custom-page']").is(':checked');
|
2018-10-31 00:06:31 +00:00
|
|
|
settings["paper-size"] = $('select#printing-size').find(':selected').val();
|
|
|
|
|
|
|
|
var logo = $("figure.brandlogo img").attr('src');
|
|
|
|
if (logo.startsWith("data:")) {
|
|
|
|
settings["logo"] = logo;
|
|
|
|
}
|
2018-11-15 16:39:25 +00:00
|
|
|
settings["footer-info"] = $("[data-field-name='footer-info']").html();
|
2018-10-31 00:06:31 +00:00
|
|
|
|
|
|
|
settings["machine-speed"] = $("[data-field-name='machine-speed']").val();
|
|
|
|
settings["time-additional"] = $("[data-field-name='time-additional']").val();
|
|
|
|
settings["time-color-change"] = $("[data-field-name='time-color-change']").val();
|
|
|
|
settings["time-trims"] = $("[data-field-name='time-trims']").val();
|
|
|
|
|
|
|
|
settings["time-clo"] = $("[data-field-name='time-clo']").val();
|
|
|
|
settings["time-cld"] = $("[data-field-name='time-cld']").val();
|
|
|
|
settings["time-opo"] = $("[data-field-name='time-opo']").val();
|
|
|
|
settings["time-opd"] = $("[data-field-name='time-opd']").val();
|
2018-04-17 00:17:07 +00:00
|
|
|
|
2018-10-31 00:06:31 +00:00
|
|
|
$.postJSON('/defaults', {'value': settings});
|
2018-04-17 00:17:07 +00:00
|
|
|
});
|
2018-03-31 00:37:11 +00:00
|
|
|
});
|