2021-06-04 15:35:29 +03:00
// for toolkit.js
function gettext ( val ) { return val ; } ;
2020-12-19 19:39:48 +03:00
function draw _labels ( target _id , label _list , page _layout , calibration ) {
let max _labels = compute _max _labels ( page _layout ) ;
let count _fixed = 0 ;
let count _fill = 0 ;
for ( i = 0 ; i < label _list . length ; i ++ ) {
let item = label _list [ i ] ;
if ( item . end === null || item . end === '' || item . end === undefined ) {
count _fill += 1 ;
continue ;
}
if ( item . end <= item . start ) {
count _fixed += 1 ;
continue ;
}
count _fixed += ( item . end - item . start ) + 1 ;
}
let rest = max _labels - count _fixed ;
let fill _size = 1 ;
if ( rest >= count _fill ) {
fill _size = Math . floor ( rest / count _fill ) ;
}
let list = [ ] ;
let count _fill _2 = 0 ;
for ( i = 0 ; i < label _list . length ; i ++ ) {
let item = label _list [ i ] ;
let count ;
if ( item . end === null || item . end === '' || item . end === undefined ) {
count _fill _2 += 1 ;
if ( count _fill _2 === count _fill ) {
count = rest ;
} else {
count = fill _size ;
}
rest -= count ;
2021-02-12 15:49:38 +03:00
} else if ( item . end <= item . start ) {
count = 1 ;
2020-12-19 19:39:48 +03:00
} else {
2021-02-12 15:49:38 +03:00
count = ( item . end - item . start ) + 1 ;
2020-12-19 19:39:48 +03:00
}
for ( j = 0 ; j < count ; j ++ ) {
let id = item . start + j ;
if ( item . prefix . length == 6 ) {
list . push ( {
label : item . prefix ,
tape _type : item . tape _type ,
mode : item . mode ,
id : id ,
} ) ;
rest += count - j - 1 ;
break ;
} else {
let pad _len = 6 - item . prefix . length ;
let label = item . prefix + id . toString ( ) . padStart ( pad _len , 0 ) ;
if ( label . length != 6 ) {
rest += count - j ;
break ;
}
list . push ( {
label : label ,
tape _type : item . tape _type ,
mode : item . mode ,
id : id ,
} ) ;
}
}
}
generate _barcode _page ( target _id , page _layout , list , calibration ) ;
}
Ext . define ( 'MainView' , {
extend : 'Ext.container.Viewport' ,
alias : 'widget.mainview' ,
layout : {
type : 'vbox' ,
align : 'stretch' ,
pack : 'start' ,
} ,
width : 800 ,
controller : {
xclass : 'Ext.app.ViewController' ,
update _barcode _preview : function ( ) {
let me = this ;
let view = me . getView ( ) ;
let list _view = view . down ( "labelList" ) ;
let store = list _view . getStore ( ) ;
let label _list = [ ] ;
store . each ( ( record ) => {
label _list . push ( record . data ) ;
} ) ;
2021-02-12 15:49:38 +03:00
let page _layout _view = view . down ( "pageLayoutPanel" ) ;
2020-12-19 19:39:48 +03:00
let page _layout = page _layout _view . getValues ( ) ;
2021-02-12 15:49:38 +03:00
let calibration _view = view . down ( "pageCalibration" ) ;
2020-12-19 19:39:48 +03:00
let page _calibration = calibration _view . getValues ( ) ;
draw _labels ( "print_frame" , label _list , page _layout , page _calibration ) ;
} ,
update _calibration _preview : function ( ) {
let me = this ;
let view = me . getView ( ) ;
2021-02-12 15:49:38 +03:00
let page _layout _view = view . down ( "pageLayoutPanel" ) ;
2020-12-19 19:39:48 +03:00
let page _layout = page _layout _view . getValues ( ) ;
2021-02-12 15:49:38 +03:00
let calibration _view = view . down ( "pageCalibration" ) ;
2020-12-19 19:39:48 +03:00
let page _calibration = calibration _view . getValues ( ) ;
console . log ( page _calibration ) ;
generate _calibration _page ( 'print_frame' , page _layout , page _calibration ) ;
} ,
control : {
labelSetupPanel : {
listchanged : function ( store ) {
this . update _barcode _preview ( ) ;
} ,
activate : function ( ) {
this . update _barcode _preview ( ) ;
} ,
} ,
pageLayoutPanel : {
pagechanged : function ( layout ) {
this . update _barcode _preview ( ) ;
} ,
activate : function ( ) {
this . update _barcode _preview ( ) ;
} ,
} ,
pageCalibration : {
calibrationchanged : function ( ) {
this . update _calibration _preview ( ) ;
} ,
activate : function ( ) {
this . update _calibration _preview ( ) ;
} ,
} ,
} ,
} ,
items : [
{
xtype : 'tabpanel' ,
items : [
{
xtype : 'labelSetupPanel' ,
title : 'Proxmox LTO Barcode Label Generator' ,
bodyPadding : 10 ,
} ,
{
xtype : 'pageLayoutPanel' ,
title : 'Page Layout' ,
bodyPadding : 10 ,
} ,
{
xtype : 'pageCalibration' ,
title : 'Printer Calibration' ,
bodyPadding : 10 ,
} ,
] ,
} ,
{
xtype : 'panel' ,
layout : "center" ,
title : 'Print Preview' ,
bodyStyle : "background-color: grey;" ,
bodyPadding : 10 ,
html : '<center><iframe id="print_frame" frameBorder="0"></iframe></center>' ,
border : false ,
flex : 1 ,
scrollable : true ,
2021-02-12 15:49:38 +03:00
tools : [ {
2020-12-19 19:39:48 +03:00
type : 'print' ,
tooltip : 'Open Print Dialog' ,
handler : function ( event , toolEl , panelHeader ) {
printBarcodePage ( ) ;
2021-02-12 15:49:38 +03:00
} ,
2020-12-19 19:39:48 +03:00
} ] ,
} ,
] ,
} ) ;
Ext . onReady ( function ( ) {
Ext . create ( 'MainView' , {
renderTo : Ext . getBody ( ) ,
} ) ;
} ) ;