forked from aureliendavid/mpat-importexport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpat_import_export.js
114 lines (84 loc) · 2.74 KB
/
mpat_import_export.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
document.addEventListener("DOMContentLoaded", function(){
document.getElementById("page-btn").onclick = function() {
document.getElementById("page-fileinput").click();
}
document.getElementById("page-fileinput").onchange = function() {
document.getElementById("page-form").submit();
document.getElementById("page-fileinput").value = "";
}
document.getElementById("layout-btn").onclick = function() {
document.getElementById("layout-fileinput").click();
}
document.getElementById("layout-fileinput").onchange = function() {
document.getElementById("layout-form").submit();
document.getElementById("layout-fileinput").value = "";
}
var checkboxes = document.getElementsByName("pageid[]");
for (var i = 0; i < checkboxes.length; i++) {
checkboxes[i].onchange = function() {
var shouldDisable = true;
var ch = document.getElementsByName("pageid[]");
for (var i = 0; i < ch.length; i++) {
if (ch[i].checked) {
shouldDisable = false;
break;
}
}
document.getElementById("btn-exportpages").disabled = shouldDisable;
document.getElementById("btn-addmedia").disabled = shouldDisable;
document.getElementById("btn-exportlayouts").disabled = shouldDisable;
};
}
});
function fake_submit(id) {
document.getElementById("frm-" + id).click();
}
function fireChange(e) {
if (document.createEvent) {
event = document.createEvent("HTMLEvents");
event.initEvent("change", true, true);
} else {
event = document.createEventObject();
event.eventType = "change";
}
event.eventName = "change";
if (document.createEvent) {
e.dispatchEvent(event);
} else {
e.fireEvent("on" + event.eventType, event);
}
}
function checkAll(ele) {
var checkboxes = document.getElementsByName("pageid[]")
if (ele.checked) {
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].type == 'checkbox') {
checkboxes[i].checked = true;
fireChange(checkboxes[i]);
}
}
} else {
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].type == 'checkbox') {
checkboxes[i].checked = false;
fireChange(checkboxes[i]);
}
}
}
}
function getCtx(id) {
var c = document.getElementById('canvas-'+id);
return c.getContext('2d');
}
function drawComponent(ctx, x, y, w, h, text="") {
ctx.fillStyle = '#333';
ctx.fillRect(x, y, w, h);
if (text != "") {
ctx.textBaseline = 'middle';
ctx.font = '11px Arial';
ctx.fillStyle = 'red';
textX = x+w/2 - ctx.measureText(text).width/2;
textY = y+h/2;
ctx.fillText(text, textX, textY);
}
}