-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprindot.js
3752 lines (3514 loc) · 136 KB
/
prindot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//////////////////////////////////////////////////
var VERSION = "<br><br>[email protected]";
var COPYRIGHT = "(c) 2013 by PRIN DOT GmbH<br>Schnackenburgallee 119 b<br>D-22525 Hamburg";
var LOG_TYPE_STATUS = 0;
var LOG_TYPE_INFO = 1;
var LOG_TYPE_PROGRESS = 2;
var LOG_TYPE_WARNING = 3;
var LOG_TYPE_ERROR = 4;
var LOG_SUBTYPE_APPLICATION = 0;
var LOG_SUBTYPE_MACHINE = 1;
var LOG_SUBTYPE_RASTER = 2;
var LOG_SUBTYPE_JOB = 3;
var LOG_SUBTYPE_IMAGE = 4;
// same defines as in config.inc.php
var JOBSTATUS_CALCSTRAND = -1;
var JOBSTATUS_NEW = 0;
var JOBSTATUS_RUNNING = 1;
var JOBSTATUS_FINISHED = 2;
var JOBSTATUS_CANCELED = 3;
var JOBSTATUS_ERROR = 4;
var JOBSTATUS_NOJOB = 5;
var JOBSTATUS_MACHINE_FILETRANSFER = 6;
var JOBSTATUS_MACHINE_WAITFORMANUALACTION = 7;
var MACHINESTATUS_OK = 0;
var MACHINESTATUS_ERROR = 4;
//////////////////////////////////////////////////
// LOAD OTHER RESOURCES BEFORE:
jQuery.cachedScript = function (url, options) {
// allow user to set any option except for dataType, cache, and url
options = $.extend(options || {}, {
dataType: "script",
cache: true,
async: false,
url: url
});
// Use $.ajax() since it is more flexible than $.getScript
// Return the jqXHR object so we can chain callbacks
return jQuery.ajax(options);
};
/**
*
* @param {type} url
* @returns {undefined}
*/
function loadjs(url) {
$.cachedScript(url).always(function (script, textStatus) {
console.log("loaded script : '" + url + "' : '" + textStatus + "'");
});
}
/**
*
* @param {type} url
* @param {type} option
* @returns {undefined}
*/
function loadcss(url, option) {
$('head').append($('<link rel="stylesheet" type="text/css" ' + option + '/>').attr('href', url));
console.log("loaded stylesheet : '" + url + "'");
}
loadcss('./gridinator_1112.css', 'media="screen"');
loadjs('./jquery-ui/ui/jquery-ui.js');
loadcss('./jquery-ui/themes/base/jquery-ui.css', 'id="theme"'); // option necessary for theme switcher!
// //$.cachedScript("./DataTables/media/js/jquery.dataTables.js").done(function(script, textStatus) { console.log( script + " : " + textStatus ); });
loadjs('./DataTables/media/js/jquery.dataTables.js');
//loadjs('./DataTables/extras/TableTools/media/js/TableTools.js');
//loadjs('./DataTables/extras/TableTools/media/js/ZeroClipboard.js');
// //$.getScript('./DataTables/media/js/jquery.dataTables.js');
// //document.createStyleSheet('./DataTables/media/css/demo_table.css');
// //$('head').append( $('<link rel="stylesheet" type="text/css" />').attr('href', './DataTables/media/css/demo_table.css') );
//loadcss('./DataTables/media/css/demo_table.css');
loadcss('./DataTables/media/css/demo_page.css');
loadcss('./DataTables/media/css/demo_table_jui.css');
//$.cachedScript("./DataTables/media/css/demo_table.css").done(function(script, textStatus) { console.log( script + " : " + textStatus ); });
loadjs('./plupload2/js/plupload.full.min.js');
loadjs('./plupload2/js/jquery.ui.plupload/jquery.ui.plupload.js');
loadjs('./plupload2/js/i18n/de.js');
loadcss('./plupload2/js/jquery.ui.plupload/css/jquery.ui.plupload.css');
loadjs('./jquery.fineuploader-3.7.1.js');
loadcss('./fineuploader-3.7.1.css');
loadcss('./custom.css');
loadjs('./jCanvas/jcanvas.js');
loadjs('./alertify/lib/alertify.js');
loadcss('./alertify/themes/alertify.core.css');
loadcss('./alertify/themes/alertify.default.css');
loadjs('./jquery-cookie/jquery.cookie.js');
loadjs('./jqueryFileTree/jqueryFileTree.js');
loadcss('./jqueryFileTree/jqueryFileTree.css');
loadjs('./jQuery-Validation-Engine/js/languages/jquery.validationEngine-de.js');
loadjs('./jQuery-Validation-Engine/js/jquery.validationEngine.js');
loadcss('./validationEngine.jquery.css');
loadcss('./validationEngine.template.css');
loadjs('./jquery.timers.js');
loadjs('./jquery.blockUI.js');
loadcss('./extra.css', 'media="screen"');
loadcss('./tabs.css');
loadcss('./my.css');
//////////////////////////////////////////////////
// INIT AND LOAD CONFIG
function getAbsolutePath() {
var loc = window.location;
var pathName = loc.pathname.substring(0, loc.pathname.lastIndexOf('/') + 1);
return pathName;
}
var prindot_protocol = window.location.protocol;
var prindot_hostname = window.location.hostname;
var prindot_port = window.location.port;
var prindot_pathname = getAbsolutePath();
var prindot_admin = false;
// should be for admins: "localhost" or "127.0.0.1"
// TODO: load list of IPs from config to allow additionally! ?
if (prindot_hostname === "localhost" || prindot_hostname === "127.0.0.1") {
prindot_admin = true;
}
var phpconfig = new Array();
/**
* dump array etc as like as in php
*
* @param {type} arr
* @param {type} level
* @returns {String}
*/
function print_r(arr, level) {
var dumped_text = "";
if (!level)
level = 0;
//The padding given at the beginning of the line.
var level_padding = "";
for (var j = 0; j < level + 1; j++)
level_padding += " ";
if (typeof(arr) === 'object') { //Array/Hashes/Objects
for (var item in arr) {
var value = arr[item];
if (typeof(value) === 'object') { //If it is an array,
dumped_text += level_padding + "'" + item + "' {\n";
dumped_text += print_r(value, level + 1);
dumped_text += " }\n";
} else {
dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
}
}
} else { //Stings/Chars/Numbers etc.
dumped_text = "===>" + arr + "<===(" + typeof(arr) + ")";
}
return dumped_text;
}
/**
* fetches config from php
* stores data in global array "phpconfig"
* @param {array} dataarray (not used yet)
* @returns -
*
*/
function callgetphpconfigviaajax(dataarray) {
$.ajax({
type: "POST",
dataType: 'json',
url: "getphpconfig.php",
data: dataarray,
async: false,
success: function (result) {
// console.log(print_r(result));
if (result['result'] === 'success') {
// console.log("callgetphpconfigviaajax: ok");
phpconfig = result;
}
else
{
// console.log("callgetphpconfigviaajax: ERROR");
//window.location = 'about:blank';
//document.getElementsByTagName('html')[0].innerHTML = '';
var i = document.childNodes.length-1;
while(i >=0 ) {
document.removeChild(document.childNodes[i--]);
}
alert("cannot read phpconfig ...");
// $.blockUI({message: "cannot read phpconfig ...", title: "Error", timeout: 0});
// echo("cannot read phpconfig ...");
throw '';
// writelog(0, 0, 0, LOG_TYPE_ERROR, LOG_SUBTYPE_APPLICATION, "cannot read phpconfig");
// myerror("cannot read phpconfig ...");
}
//alertify.log(result);
//$("#phpconfiginfos").text("read");
// $("#phpconfiginfos").text(print_r(phpconfig));
// alertify.log(print_r(phpconfig));
// var key;
// for (key in result) {
// alertify.log ("Schlüssel " + key + " mit Wert " + result[key]);
// }
// alertify.log("result-urls-test=" + phpconfig['urls']['test']);
}
});
}
// load config as soon as possible
callgetphpconfigviaajax({action: "get"});
/**
* test only
*
*/
$(function () {
// $("#phpconfiginfos").text(print_r(phpconfig));
// alertify.log(print_r(phpconfig));
});
//////////////////////////////////////////////////
// TABS:
$(function () {
$("#tabs").tabs({
// event: "mouseover",
// fx: {opacity: 'toggle'},
//disabled: [4],
show: {effect: "fadeIn", duration: 400},
hide: {effect: "fadeOut", duration: 200}
// hide: {effect: "drop", direction: "down", duration: 200}
});
});
//////////////////////////////////////////////////
// THEME SWITCHER (not used anymore)
// Initialize the theme switcher:
$(function () {
'use strict';
$('#theme-switcher').change(function () {
var theme = $('#theme');
theme.prop(
'href',
theme.prop('href').replace(
/[\w\-]+\/jquery-ui.css/,
$(this).val() + '/jquery-ui.css'
)
);
//alertify.log("theme switched", "success", 2000);
});
});
//////////////////////////////////////////////////
// COPYRIGHT+VERSION:
var actual_version;
function show_copyright()
{
actual_version = phpconfig['info']['version'];
versiontext = "Version : " + actual_version + VERSION;
$("#versiontext").html(versiontext);
copyrighttext = COPYRIGHT;
$("#copyrighttext").html(copyrighttext);
// TODO: hier timer (10 min) der die config liest und die version vergleicht ... bei unterschied : refresh der seite
$(document).stopTime('autoupdatecheck_timer');
$(document).everyTime(phpconfig['settings']['autoupdatecheck_timer_sec'] * 1000, 'autoupdatecheck_timer', function () {
// TODO: hier function draus machen
// TODO: und ajax call an PHP mit aufforderung dbupdate.sql auszufuehren! (logs.php)
// console.log("checking for new version ...");
callgetphpconfigviaajax({action: "get"});
if (actual_version != phpconfig['info']['version'])
{
// console.log("new version found ... refreshing!");
// confirm("new version found ... refreshing!!");
writelog(0, 0, 0, LOG_TYPE_INFO, LOG_SUBTYPE_APPLICATION, 'new version ' + phpconfig['info']['version'] + ' found (old was ' + actual_version + ') ... application refreshed');
location.reload(true);
}
});
}
$(function () {
show_copyright();
});
//////////////////////////////////////////////////
// PROTOTYPE for l10n (localization)
var l10n_text = new Array;
function init_l10n()
{
l10n_text = {
maintitle: phpconfig['l10n']['text']['maintitle'],
//tab_welcome_str: 'Über'
tab_welcome_str: phpconfig['l10n']['text']['tab_welcome_str'] // geht auch ohne escaping !?! (wg. HTML header charset UTF-8 und editor hier auch UTF-8)
};
}
function unescp(x) {
return $('<div/>').html(x).text();
}
var l10n_attr_src = {
prindotlogosmall: 'images/prindotlogosmall.png',
prindotlogoa: 'images/prindotlogoa.png'
};
//var l10n_text = {
// maintitle: 'PRIN DOT - pro line - pro dot',
// //tab_welcome_str: 'Über'
// tab_welcome_str: 'Über' // geht auch ohne escaping !?! (wg. HTML header charset UTF-8 und editor hier auch UTF-8)
//};
var l10n_attr_title = {
machineselector: 'Hier werden keine NEUEN Maschinen definiert, sondern nur gemeldete mit weiteren Werten angereichert und verändert. (... und zur Produktion ausgewählt)'
};
var l10n = {
deletestoragefile_success: 'Datei wurde gelöscht!',
deletestoragefile_error: 'Datei wurde nicht gelöscht!'
};
$(document).ready(function () {
init_l10n();
// TEST: dynamically set attributes in HTML after loaded
//$('#prindotlogosmall').attr('src', l10n_attr_src['prindotlogosmall']);
//$('#prindotlogoa').attr('src', l10n_attr_src['prindotlogoa']);
// oder: nur die ersetzen, die im array definiert sind:
$.each(l10n_attr_src, function (i, v) {
$('#' + i).attr('src', v);
});
$('#maintitle').text(l10n_text['maintitle']);
//$('#tab_welcome_str').html('Über');
// $('#tab_welcome_str').text(unescp('Über'));
$('#tab_welcome_str').text(l10n_text['tab_welcome_str']);
$('#machine_selector_legend').html('Maschine auswählen');
$('#machine_describe_legend').html('Maschine beschreiben');
$('#machineselector').attr('title', unescp(l10n_attr_title['machineselector']));
//$('#machineselector').attr('title', $('#machineselector').attr('title') + unescp("ä"));
$('#prindot_machine_name_str').text(unescp('Name :'));
/// ... usw.
});
//////////////////////////////////////////////////
// WRITE LOG
/**
*
* @param {type} JID
* @param {type} MID
* @param {type} HID
* @param {type} type (0=status, 1=info, 2=progress, 3=warning, 4=error)
* @param {type} subtype
* @param {type} description
* @returns {undefined}
*/
function writelog(JID, MID, HID, type, subtype, description) {
JID = JID || 0;
MID = MID || 0;
HID = HID || 0;
type = type || 0;
subtype = subtype || 0;
description = description || '';
var action = {action: "create"};
writelog_r = $.ajax({
type: "POST",
dataType: 'json',
url: phpconfig['urls']['logs'],
data: $.extend({}, action, {JID: JID, MID: MID, HID: HID, type: type, subtype: subtype, description: description})
});
writelog_r.done(function (result) {
// alertify.success("writelog() : " + print_r(result));
});
writelog_r.fail(function (jqXHR, textStatus) {
alertify.error("writelog() Request failed: " + textStatus);
// TODO: meldung in db-logs schreiben ... hmpf
alertify.error('ERROR: cannot write to logs table in database', 0);
});
// TODO: neee ... alerts nicht hier, sondern im refresh der logtable (mit cookie seit dem letzten logdisplay etc)
if (type === LOG_TYPE_ERROR) {
alertify.error(description, 0);
}
}
//////////////////////////////////////////////////
// TOOLTIP INIT
$(function () {
$(document).tooltip({
position: {
// my: "left bottom",
// at: "left top-3"}
// ,track: true
my: "left top",
at: "left bottom",
of: "#howto"
}
});
});
//////////////////////////////////////////////////
// ALERTIFY
$(function () {
(function () {
var proxied = window.alert;
// fetch alerts from outside
window.alert = function () {
// do something here
writelog(0, 0, 0, LOG_TYPE_WARNING, LOG_SUBTYPE_APPLICATION, "Alermmeldung abgefangen: " + arguments[0]);
alertify.log("catched foreign alert: " + arguments[0]);
//return proxied.apply(this, arguments);
return false;
};
})();
});
$(function () {
// alert("test-x"); // TEST: grab normal alerts into alertify (works well!)
});
/**
* show error alert for 60 seconds with additional timestamp
* @param msg
*/
function myerror(msg) {
var dn = new Date();
alertify.error('<b>[' + dn.toLocaleString() + ']</b></br> ' + msg, 60000);
}
//////////////////////////////////////////////////
// SELECT, PREVIEW AND DELETE IMAGE
var prindot_selectedfile_infos = new Array();
var prindot_selectedfile = '';
var fileTreeSelect_selectedfile = '';
function show_selectedfile_infos() {
//TODO : hier wg. rotate +/-90 grad die werte in org speichern und jeweils richtig ausgeben (die Verwendung in der auftragsdefinition ("breite uebernehmen") entsprechend anpassen !
var tmp;
var resx = parseFloat(prindot_selectedfile_infos['res']['x']);
var resy = parseFloat(prindot_selectedfile_infos['res']['y']);
if (prindot_imagerotate === 90 || prindot_imagerotate === 270) {tmp=resx; resx=resy; resy=tmp;}
var width = parseInt(prindot_selectedfile_infos['size']['width']);
var height = parseInt(prindot_selectedfile_infos['size']['height']);
if (prindot_imagerotate == 90 || prindot_imagerotate == 270) {tmp=width; width=height; height=tmp;}
var width_mm = Math.round(parseFloat(prindot_selectedfile_infos['size']['width_mm']) * 100.0) / 100.0;
var height_mm = Math.round(parseFloat(prindot_selectedfile_infos['size']['height_mm']) * 100.0) / 100.0;
if (prindot_imagerotate == 90 || prindot_imagerotate == 270) {tmp=width_mm; width_mm=height_mm; height_mm=tmp;}
var pixel_width_mm = Math.round(parseFloat(prindot_selectedfile_infos['size']['width_mm']) / parseInt(prindot_selectedfile_infos['size']['width']) * 10000.0) / 10000.0;
var pixel_height_mm = Math.round(parseFloat(prindot_selectedfile_infos['size']['height_mm']) / parseInt(prindot_selectedfile_infos['size']['height']) * 10000.0) / 10000.0;
if (prindot_imagerotate == 90 || prindot_imagerotate == 270) {tmp=pixel_width_mm; pixel_width_mm=pixel_height_mm; pixel_height_mm=tmp;}
$('#selectedfileinfo').html("" + prindot_selectedfile + " : " + width_mm + " x " + height_mm + " mm" + "<br />" + width + " x " + height + " pixel mit " + resx + " x " + resy + " dpi" + "<br />" + "Pixelgröße: " + pixel_width_mm + " x " + pixel_height_mm + " mm");
$('#selectedfileinfob').html("" + prindot_selectedfile + " : " + width_mm + " x " + height_mm + " mm" + "<br />" + width + " x " + height + " pixel mit " + resx + " x " + resy + " dpi" + "<br />" + "Pixelgröße: " + pixel_width_mm + " x " + pixel_height_mm + " mm");
}
/**
* get info (width dpi etc) about given filen (image)
*
* @param {type} filename
* @returns {undefined}
*/
function getimageinfo(filename) {
getimageinfo_r = $.ajax({
type: "POST",
dataType: 'json',
url: phpconfig['urls']['getimageinfo'],
data: {name: filename}
});
getimageinfo_r.done(function (result) {
if (result['result'] === 'success') {
prindot_selectedfile_infos = result['value'];
//alertify.success(print_r(prindot_selectedfile_infos));
show_selectedfile_infos();
alertify.log("Wird zur Produktion genommen: " + prindot_selectedfile_infos['name'] + " ", "success");
$("#settings_form").children().prop('disabled', false);
//$("#job_settings").hide("slide", {}, 600);
$("#settings_form").show();
$("#tabs").tabs("enable", 3);
// $("#tabs").tabs("option", "active", 3);
}
else {
// TODO log und selectedfile ungueltig und tabs sperren
alertify.error("cannot use image because : " + result['reason']);
$('#selectedfileinfo').text("" + result['reason']);
$('#selectedfileinfob').text("" + result['reason']);
prindot_selectedfile = '';
$("#settings_form").children().prop('disabled', true);
$("#settings_form").hide();
$("#tabs").tabs("disable", 3);
}
});
getimageinfo_r.fail(function (jqXHR, textStatus) {
myerror("Request failed: " + textStatus);
$('#selectedfileinfo').text("Request failed: " + textStatus);
$('#selectedfileinfob').text("Request failed: " + textStatus);
prindot_selectedfile = '';
$("#settings_form").children().prop('disabled', true);
$("#settings_form").hide();
$("#tabs").tabs("disable", 3);
});
}
/**
* show file tree and handle selection
*
* @returns {undefined}
*/
function fileTreeSelect() {
$('#fileTreeSelect').fileTree({
//root: './prindot/plupload2/examples/uploads/',
root: prindot_pathname + phpconfig['paths']['storage_root_js'],
script: phpconfig['urls']['filetreescript'],
folderEvent: 'click',
expandSpeed: 750,
collapseSpeed: 350,
multiFolder: false,
height: 300
}, function (file) {
prindot_selectedfile = file;
fileTreeSelect_selectedfile = file; // used for delete operation only
thumbnail = phpconfig['paths']['storage_root_js'] + phpconfig['paths']['thumbnails'] + '/' + prindot_selectedfile + '.jpg';
$('#selectedfilesrc').attr('src', thumbnail);
$('#selectedfilesrcb').attr('src', thumbnail);
getimageinfo(prindot_selectedfile);
// if (prindot_selectedfile != '')
// {
// alertify.log("Wird zur Produktion genommen: " + file + " ", "success");
// $("#settings_form").children().prop('disabled', false);
// //$("#job_settings").hide("slide", {}, 600);
// $("#settings_form").show();
// $("#tabs").tabs("enable", 3);
// }
//$("#tabs").tabs("option", {disable 3});
});
};
/**
* delete given file (image) from filesystem
* including thumbnails and previews
*
* @param {type} filename
* @returns {undefined}
*/
function deletestoragefile(filename) {
deletestoragefile_r = $.ajax({
type: "POST",
dataType: 'json',
url: phpconfig['urls']['storage'],
data: {action: 'delete', filename: filename}
});
deletestoragefile_r.done(function (result) {
if (result['result'] === 'success') {
alertify.log(l10n['deletestoragefile_success'] + ' : ' + filename);
//TODO writelog()
writelog(0, 0, 0, LOG_TYPE_INFO, LOG_SUBTYPE_IMAGE, l10n['deletestoragefile_success'] + ' : ' + filename);
prindot_selectedfile = '';
fileTreeSelect_selectedfile = '';
// $(document).oneTime(1000, 'filetreetimer', function() { // damit auch die 100% noch dargestellt werden
fileTreeSelect();
// });
// und thumbnail zuruecksetzen
$('#selectedfilesrc').attr('src', noimage);
$('#selectedfilesrcb').attr('src', noimage);
// und auftrags-tab-deaktivieren (bzw. form)
$("#tabs").tabs("disable", 3);
//$("#tabs").tabs("option", {disable 3});
//$("#tabs").tabs("option", {active: 1});
}
else {
// alertify.error(l10n['deletestoragefile_error'] + ' : ' + prindot_selectedfile);
writelog(0, 0, 0, LOG_TYPE_ERROR, LOG_SUBTYPE_IMAGE, l10n['deletestoragefile_error'] + ' : ' + filename);
}
});
deletestoragefile_r.fail(function (jqXHR, textStatus) {
// alertify.error("Request failed: " + textStatus);
// alertify.error(l10n['deletestoragefile_error'] + ' : ' + prindot_selectedfile);
writelog(0, 0, 0, LOG_TYPE_ERROR, LOG_SUBTYPE_IMAGE, l10n['deletestoragefile_error'] + ' : ' + filename);
});
}
var noimage = "./images/noimage.png";
$(function () {
$("#tabs").tabs("disable", 3); // disable tab 3 ("Auftrag" by default - will be enabled when selected an image
/**
* show preview when clicked on thumbnail
*/
$("#selectedfilepreview").click(function () {
if (prindot_selectedfile !== '') {
preview = phpconfig['paths']['storage_root_js'] + phpconfig['paths']['previews'] + '/' + prindot_selectedfile + '.jpg';
alertify.set({labels: {ok: "Ok"}});
// alertify.alert('<div><h3>Datei preview : ' + prindot_selectedfile + '?</h3><img style="border:4px red solid" src="' + preview + '"/><br/></div>');
alertify.alert('<div><h3>Datei preview : ' + prindot_selectedfile + '?</h3><img class="redwideborder" src="' + preview + '"/><br/></div>');
}
});
$("#selectedfilepreviewb").click(function () {
if (prindot_selectedfile !== '') {
preview = phpconfig['paths']['storage_root_js'] + phpconfig['paths']['previews'] + '/' + prindot_selectedfile + '.jpg';
alertify.set({labels: {ok: "Ok"}});
// alertify.alert('<div><h3>Datei preview : ' + prindot_selectedfile + '?</h3><img style="border:4px red solid" src="' + preview + '"/><br/></div>');
alertify.alert('<div><h3>Datei preview : ' + prindot_selectedfile + '?</h3><img class="redwideborder" src="' + preview + '"/><br/></div>');
}
});
$("#buttondeleteimage").click(function () {
if (fileTreeSelect_selectedfile !== '') {
thumbnail = phpconfig['paths']['storage_root_js'] + phpconfig['paths']['thumbnails'] + '/' + fileTreeSelect_selectedfile + '.jpg';
//preview = phpconfig['paths']['storage_root_js'] + phpconfig['paths']['previews'] + '/' + file + '.jpg';
alertify.set({labels: {ok: "Löschen", cancel: "nicht löschen"}});
alertify.set({buttonFocus: "cancel"}); // "none", "ok", "cancel"
alertify.confirm('<h3>Datei löschen : ' + fileTreeSelect_selectedfile + '?</h3><img src="' + thumbnail + '"/><br/>', function (e) {
if (e) {
//alertify.success("You've clicked OK");
//alertify.log("Wird gelöscht: " + prindot_selectedfile + " ...");
// call an storage.php mit loeschen von file (+thumb +preview)
deletestoragefile(fileTreeSelect_selectedfile);
} else {
//alertify.log("Abgebrochen");
}
});
}
else {
//alertify.log("kein bild");
}
});
});
// Initialize jqueryFileTree and update button
$(function () {
fileTreeSelect();
$("#fileTreeSelectUpdateButton").click(function () {
fileTreeSelect();
});
});
//////////////////////////////////////////////////
// READ AND WRITE MACHINES
// array to hold actual job definition to be saved to db (or read beforehand from db into this array)
var prindot_job = new Array();
// TODO: liste im tab loeschen
var prindot_machines = new Array();
function resetallmachines() {
$("#machineselector").children().remove();
prindot_machines = new Array();
}
function readallmachines() {
readallmachines_r = $.ajax({
type: "POST",
dataType: 'json',
url: phpconfig['urls']['machines'],
data: {action: "fetchall"}
});
readallmachines_r.done(function (result) {
if (result['result'] === 'success')
{
// hier die result-liste in maschinen-tab-auswahl-liste eintragen (und vorselektierte (ggf. letzte aus cookie) die werte uebertragen in felder
prindot_machines.length = 0;
for (id in result['value']) {
prindot_machines[result['value'][id]['MID']] = result['value'][id];
}
for (MID in prindot_machines) {
$("#machineselector").append('<option value="' + MID + '">' + prindot_machines[MID]['name'] + '</option>');
}
// den aktiven ggf. aus Cookie laden
selected_machine = $.cookie('selected_machine');
if (selected_machine === undefined) {
// alertify.log("cookie undefined! ... defining last machine");
selected_machine = MID;
$.cookie('selected_machine', selected_machine);
}
else {
// alertify.log("cookie = " + selected_machine + " selecting");
// $.removeCookie('selected_machine');
}
// TODO: pruefen, ob cookie ueberhaupt mit einem aus der liste uebereinstimmt ... sonst ersten selected setzen
$("#machineselector option[value='" + selected_machine + "']").attr('selected', true);
// DONE: funktion bauen, die die werte aus der selektion (oder ersten maschine) liest und unten alles ausfuellt
$("#machineselector").change();
writelog(0, 0, 0, LOG_TYPE_INFO, LOG_SUBTYPE_MACHINE, 'successfully read machines from database');
}
else
{
writelog(0, 0, 0, LOG_TYPE_ERROR, LOG_SUBTYPE_MACHINE, 'ERROR reading machines from database (result!=success)');
}
});
readallmachines_r.fail(function (jqXHR, textStatus) {
writelog(0, 0, 0, LOG_TYPE_ERROR, LOG_SUBTYPE_MACHINE, 'ERROR reading machines from database (ajax failed)');
//alertify.error("Request failed: " + textStatus);
});
}
function writemachine(MID) {
var action = {action: "update"};
writemachine_r = $.ajax({
type: "POST",
dataType: 'json',
url: phpconfig['urls']['machines'],
data: $.extend({}, action, prindot_machines[MID])
});
writemachine_r.done(function (result) {
if (result['result'] === 'success')
{
alertify.success('successfully update machine "' + prindot_machines[MID]['name'] + '" [' + MID + '] in database');
writelog(0, 0, 0, LOG_TYPE_INFO, LOG_SUBTYPE_MACHINE, 'successfully update machine "' + prindot_machines[MID]['name'] + '" [' + MID + '] in database');
}
else
{
writelog(0, 0, 0, LOG_TYPE_ERROR, LOG_SUBTYPE_MACHINE, 'error while update machine "' + prindot_machines[MID]['name'] + '" [' + MID + '] in database (result!=success)');
}
});
writemachine_r.fail(function (jqXHR, textStatus) {
// alertify.error('error while update machine "' + prindot_machines[MID]['name'] + '" [" + MID + "]in database' + ' - Request failed: ' + textStatus);
writelog(0, 0, 0, LOG_TYPE_ERROR, LOG_SUBTYPE_MACHINE, 'error while update machine "' + prindot_machines[MID]['name'] + '" [' + MID + '] in database (' + textStatus + ', ajax failed)');
});
}
/**
* doc ready: load machines
*
*/
$(function () {
resetallmachines();
readallmachines();
});
//////////////////////////////////////////////////
// READ RASTER
var prindot_rasters = new Array();
function resetallraster() {
$("#rasterselector").children().remove();
prindot_rasters = new Array();
}
function readallraster() {
readallraster_r = $.getJSON(
phpconfig['urls']['raster']
);
readallraster_r.done(function (result) {
if (result['result'] === 'success')
{
prindot_rasters.length = 0;
j = 0;
prindot_rasters[j] = {'name': '-', 'dx': 0, 'dy': 0};
for (i in result['raster']) {
++j;
//console.log("i=" + i + " : " + print_r(result['raster'][i]));
prindot_rasters[j] = result['raster'][i];
}
for (i in prindot_rasters) {
$("#rasterselector").append('<option value="' + i + '">' + prindot_rasters[i]['name'] + '</option>');
}
prindot_raster = 0;
$("#rasterselector option[value='" + prindot_raster + "']").attr('selected', true);
$("#rasterselector").change();
writelog(0, 0, 0, LOG_TYPE_INFO, LOG_SUBTYPE_RASTER, 'successfully read ' + prindot_rasters.length + ' raster settings from file');
}
else
{
writelog(0, 0, 0, LOG_TYPE_ERROR, LOG_SUBTYPE_RASTER, 'ERROR reading raster settings from file (result!=success)');
}
});
readallraster_r.fail(function (jqXHR, textStatus) {
//alertify.error("Request failed: " + textStatus);
// alertify.error("ERROR reading raster settings from file");
writelog(0, 0, 0, LOG_TYPE_ERROR, LOG_SUBTYPE_RASTER, 'ERROR reading raster settings from file (ajax failed)');
});
}
/**
* doc ready: load raster
*
*/
$(function () {
resetallraster();
readallraster();
});
//////////////////////////////////////////////////
// CREATE JOB
/**
* create job into database
* @returns {undefined}
*/
function createjob() {
var action = {action: "create"};
createjob_r = $.ajax({
type: "POST",
dataType: 'json',
url: phpconfig['urls']['jobs'],
data: $.extend({}, action, prindot_job)
});
createjob_r.done(function (result) {
if (result['result'] === 'success') {
alertify.success('sucessfully created job in database');
writelog(0, 0, 0, LOG_TYPE_INFO, LOG_SUBTYPE_JOB, 'sucessfully created job (' + prindot_job['name'] + ') in database');
// hier dann tab ausgrauen, bild zuruecksetzen und aktuellen tab auf jobtable setzen
prindot_selectedfile = '';
$('#selectedfilesrc').attr('src', noimage);
$('#selectedfilesrcb').attr('src', noimage);
$("#settings_form").children().prop('disabled', true);
$("#settings_form").hide();
$("#job_settings").hide();
$("#tabs").tabs("option", "active", 4);
$("#tabs").tabs("disable", 3);
}
else {
// alertify.error('error while creating job in database : ' + result['reason'], 0);
// !! writelog with LOG_TYPE_ERROR will display same message as alertify to stay
writelog(0, 0, 0, LOG_TYPE_ERROR, LOG_SUBTYPE_JOB, 'error while creating job in database : ' + result['reason']);
}
});
createjob_r.fail(function (jqXHR, textStatus) {
// alertify.error('error while creating job in database : Request failed: ' + textStatus, 0);
writelog(0, 0, 0, LOG_TYPE_ERROR, LOG_SUBTYPE_JOB, 'error while creating job in database : Request failed: ' + textStatus);
});
}
//////////////////////////////////////////////////
// LOGTABLE
var LogTable;
var asInitVals = new Array();
function init_logtable() {
LogTable = $('#logtable').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": phpconfig['urls']['tablelogs'],
"iDisplayLength": 20,
"aLengthMenu": [
[3, 10, 20],
[3, 10, 20]
],
"aaSorting": [
[0, 'desc']
],
"aoColumnDefs": [
{"aTargets": [0], "mRender": function (data, type, full) {
//return '# <b>"' + data + '"</b>';
return '<i>' + data + '</i>';
}},
{"aTargets": [1], "mRender": function (data, type, full) { // JID == 0
if (parseInt(data) == 0) return '-';
return data;
}},
{"aTargets": [2], "mRender": function (data, type, full) { // MID == 0
if (parseInt(data) == 0) return '-';
if (prindot_machines[data])
data = '' + prindot_machines[data]['name'] + '';
return data;
}},
{"aTargets": [3], "mRender": function (data, type, full) { // HID == 0
if (parseInt(data) == 0) return '-';
return data;
}},
{"sWidth": "50%", "aTargets": [4], "mRender": function (data, type, full) { // timestamp
if (data !== null) {
return data.replace(' ', ' ');
} else {
return data;
}
}},
{"aTargets": [5], "mRender": function (data, type, full) { // address
// data = data.replace('::1', 'localhost');
if (data.substring(0,3) == "::1")
{
return '(local)';
}
else
{
return data.slice(0, data.lastIndexOf(':'));
}
}},
{"aTargets": [6], "mRender": function (data, type, full) {
switch (parseInt(data)) {
case LOG_TYPE_STATUS:
return 'Status';
break;
case LOG_TYPE_INFO:
return 'Info';
break;
case LOG_TYPE_PROGRESS: // never used
return 'Fortschritt';
break;
case LOG_TYPE_WARNING:
return 'Warnung';
break;
case LOG_TYPE_ERROR:
return 'Fehler';
break;
default:
return 'unbekannt : ' + data;
break;
}
}
},
{"aTargets": [7], "mRender": function (data, type, full) {
switch (parseInt(data)) {
case LOG_SUBTYPE_APPLICATION:
return 'GUI';
break;
case LOG_SUBTYPE_MACHINE:
return 'Maschine';
break;
case LOG_SUBTYPE_RASTER:
return 'Raster';
break;
case LOG_SUBTYPE_JOB:
return 'Auftrag';
break;
case LOG_SUBTYPE_IMAGE:
return 'Bild';
break;
default:
return 'unbekannt : ' + data;
break;
}
}
}
],
"aoColumns": [
{"mData": 'LID'},
{"mData": 'JID'},
{"mData": 'MID'},
{"mData": 'HID'},
{"sWidth": "140px", "mData": 'timestamp'},
{"mData": 'remoteaddr'},
{"mData": 'type'},
{"mData": 'subtype'},
{"mData": 'description'}
],
"oLanguage": {
"sProcessing": "Bitte warten...",
"sLengthMenu": "_MENU_ Einträge anzeigen",
"sZeroRecords": "Keine Einträge vorhanden.",
"sInfo": "_START_ bis _END_ von _TOTAL_ Einträgen",
"sInfoEmpty": "0 bis 0 von 0 Einträgen",
"sInfoFiltered": "(gefiltert von _MAX_ Einträgen)",
"sInfoPostFix": "",
"sSearch": "alles durchsuchen",
"sUrl": "",
"oPaginate": {
"sFirst": "Erster",
"sPrevious": "Zurück",
"sNext": "Nächster",
"sLast": "Letzter"
}
},
"sScrollY": 400,
"bJQueryUI": true,
"sPaginationType": "full_numbers"
});
LogTable.fnSetColumnVis(5, false, false); // spalte ausblenden
LogTable.fnAdjustColumnSizing(true);
/*
* Support functions to provide a little bit of 'user friendlyness' to the textboxes in
* the footer
*/
$("tfoot input").keyup(function () {
// var dt1_offset = 0;
// var dt1_end = 41;
// var dt2_offset = 42;
// var dt2_end = 50;
var dt1_offset = -1;
var dt1_end = -1;
var dt2_offset = 0;
var dt2_end = 8;
i = $("tfoot input").index(this);
console.log("keyup i=" + i);
if (i >= dt1_offset && i <= dt1_end) {
console.log("keyup ... jobtable");
JobTable.fnFilter( this.value, i-dt1_offset );
} else
if (i >= dt2_offset && i <= dt2_end) {
console.log("keyup ... logtable");
LogTable.fnFilter( this.value, i-dt2_offset );
}
});