57aa86b8 by Insu Mun

Update interface script.

1 parent b1561eb7
1 //var pluginUrl = "http://localhost:8888/Forms"; 1 //var pluginUrl = "http://contact-form.dev";
2 //var pdf_customizer = "http://localhost:8888/pdf-customizer/public"; 2 //var pdf_customizer = "http://pdf-customizer.dev/public";
3 3
4 var pluginUrl = "http://contact.gotenzing.com"; 4 var pluginUrl = "http://contact.gotenzing.com";
5 var pdf_customizer = "http://pdf-customizer.synapsus.co"; 5 var pdf_customizer = "http://pdf-customizer.synapsus.co";
6
7 function getAuth() {
8 6
7 function getAuth() {
9 jQuery(document).ready(function($) { 8 jQuery(document).ready(function($) {
10
11 var settings = { 9 var settings = {
12 "async": true, 10 "async": true,
13 "crossDomain": true, 11 "crossDomain": true,
...@@ -24,38 +22,26 @@ ...@@ -24,38 +22,26 @@
24 //alert(xhr.status); 22 //alert(xhr.status);
25 document.getElementById('contentArea').innerHTML = xhr.responseText; 23 document.getElementById('contentArea').innerHTML = xhr.responseText;
26 } 24 }
27 25 };
28 }
29 26
30 $.ajax(settings).done(function(response) { 27 $.ajax(settings).done(function(response) {
31 console.log(response); 28 console.log(response);
32 token = response; 29 token = response;
33 }); 30 });
34
35 }); 31 });
36 32 }
37 }
38
39
40
41
42 function offFocus(id) {
43 33
44 34
35 function offFocus(id) {
45 jQuery(document).ready(function($) { 36 jQuery(document).ready(function($) {
46
47
48 $("#select" + id + "").removeClass("focus"); 37 $("#select" + id + "").removeClass("focus");
49 $(".entry_block").mouseleave(function() { 38 $(".entry_block").mouseleave(function() {
50 $("#select" + id + "").addClass("focus"); 39 $("#select" + id + "").addClass("focus");
51 }); 40 });
52 }); 41 });
53 } 42 }
54
55
56 function ShowBox(pheight, pwidth, up, right, height, width, count, example) {
57
58 43
44 function ShowBox(pheight, pwidth, up, right, height, width, count, example) {
59 jQuery(document).ready(function($) { 45 jQuery(document).ready(function($) {
60 $('span').hide(); 46 $('span').hide();
61 $('#span' + count).show(); 47 $('#span' + count).show();
...@@ -66,8 +52,6 @@ ...@@ -66,8 +52,6 @@
66 Qctx.clearRect(0, 0, Qc.width, Qc.height); 52 Qctx.clearRect(0, 0, Qc.width, Qc.height);
67 Qctx.restore(); 53 Qctx.restore();
68 54
69
70
71 var down = pheight - (up + height); 55 var down = pheight - (up + height);
72 var scaleH = $("Canvas").height() / pheight; 56 var scaleH = $("Canvas").height() / pheight;
73 var scaleW = $("Canvas").width() / pwidth; 57 var scaleW = $("Canvas").width() / pwidth;
...@@ -85,24 +69,20 @@ ...@@ -85,24 +69,20 @@
85 ctx.stroke(); 69 ctx.stroke();
86 //console.log(pheight, pwidth,up, right, height, width); 70 //console.log(pheight, pwidth,up, right, height, width);
87 // console.log(myrect ) 71 // console.log(myrect )
88
89
90
91 }); 72 });
92 73 }
93 }
94 74
95 75
96 function SetFocus(i) { 76 function SetFocus(i) {
97 jQuery(document).ready(function($) { 77 jQuery(document).ready(function($) {
98 $("label#focusButton"+i).css({"border": "2px solid #F7A800 !important"}); 78 $("label#focusButton" + i).css({"border": "2px solid #F7A800 !important"});
99 console.log($("label#focusButton"+i)); 79 console.log($("label#focusButton" + i));
100 80
101 }); 81 });
102 } 82 }
103 83
104 84
105 function HideBox() { 85 function HideBox() {
106 jQuery(document).ready(function($) { 86 jQuery(document).ready(function($) {
107 $('span').hide(); 87 $('span').hide();
108 88
...@@ -112,9 +92,9 @@ function SetFocus(i) { ...@@ -112,9 +92,9 @@ function SetFocus(i) {
112 ctx.save(); // store the current transformation matrix 92 ctx.save(); // store the current transformation matrix
113 }); 93 });
114 94
115 } 95 }
116 96
117 function HideBoxwithdate() { 97 function HideBoxwithdate() {
118 jQuery(document).ready(function($) { 98 jQuery(document).ready(function($) {
119 var cnv = document.getElementById("Canvas"); 99 var cnv = document.getElementById("Canvas");
120 var ctx = cnv.getContext('2d'); // gets reference to canvas context 100 var ctx = cnv.getContext('2d'); // gets reference to canvas context
...@@ -122,77 +102,51 @@ function SetFocus(i) { ...@@ -122,77 +102,51 @@ function SetFocus(i) {
122 ctx.save(); // store the current transformation matrix 102 ctx.save(); // store the current transformation matrix
123 }); 103 });
124 104
125 } 105 }
126
127
128 106
129 function getJson(user_id) {
130 107
108 function getJson(user_id) {
131 jQuery(document).ready(function($) { 109 jQuery(document).ready(function($) {
132
133 $.getJSON("" + pdf_customizer + "/api/v1/get-list/" + user_id, function(data) { 110 $.getJSON("" + pdf_customizer + "/api/v1/get-list/" + user_id, function(data) {
134 // Get the element with id summary and set the inner text to the result. 111 // Get the element with id summary and set the inner text to the result.
135 var json = JSON.stringify(data); 112 var json = JSON.stringify(data);
136 pickPdfFromList(json); 113 pickPdfFromList(json);
137
138 }); 114 });
139
140
141
142 }); 115 });
143 } 116 }
144
145 function getOneJson(id) {
146 117
118 function getOneJson(id) {
147 jQuery(document).ready(function($) { 119 jQuery(document).ready(function($) {
148
149 $.getJSON("" + pdf_customizer + "/api/v1/get-pdf-google/" + id, function(data) { 120 $.getJSON("" + pdf_customizer + "/api/v1/get-pdf-google/" + id, function(data) {
150 // Get the element with id summary and set the inner text to the result. 121 // Get the element with id summary and set the inner text to the result.
151 var json = JSON.stringify(data); 122 var json = JSON.stringify(data);
152 123
153 changePdfOptions(json); 124 changePdfOptions(json);
154
155 }); 125 });
156
157
158
159 }); 126 });
160 } 127 }
161 128
162 function pickPdfFromList(json) { 129 function pickPdfFromList(json) {
130 jQuery(document).ready(function($) {
163 json = JSON.parse(json); 131 json = JSON.parse(json);
164 132
165
166
167
168 var strVar = ""; 133 var strVar = "";
169
170
171 var i; 134 var i;
172 var pdflist = ""; 135 var pdflist = "";
173 for (i = 0; i < json.length; ++i) { 136 for (i = 0; i < json.length; ++i) {
174 pdflist += '<div class="column">'; 137 pdflist += '<div class="column">';
175 pdflist += '<a href="#" onclick="getOneJson(' + json[i].idPDF + ');"> <img class="thumbnail" src="' + pdf_customizer + '/fileentry/getImage/' + json[i].folder + '/' + json[i].image + '" height="270px"></a>'; 138 pdflist += '<a href="#" onclick="getOneJson(' + json[i].idPDF + ');"><img class="thumbnail" src="' + pdf_customizer + '/fileentry/getImage/' + json[i].folder + '/' + json[i].image + '" height="270px"></a>';
176 pdflist += " <h5>" + json[i].name + "</h5>"; 139 pdflist += " <h5>" + json[i].name + "</h5>";
177 pdflist += "</div>"; 140 pdflist += "</div>";
178 } 141 }
179 142
180
181 strVar += ' <div class="callout primary"><div class="row column"> <h1 class="pdfeditortitle">CUBOS COLLATERAL MATERIAL</h1>'; 143 strVar += ' <div class="callout primary"><div class="row column"> <h1 class="pdfeditortitle">CUBOS COLLATERAL MATERIAL</h1>';
182 strVar += ' '; 144 strVar += ' ';
183
184
185
186
187 document.getElementById('contentArea').innerHTML = strVar; 145 document.getElementById('contentArea').innerHTML = strVar;
146 });
147 }
188 148
189 149 function changePdfOptions(json) {
190
191
192 }
193
194
195 function changePdfOptions(json) {
196 jQuery(function($) { 150 jQuery(function($) {
197 json = JSON.parse(json); 151 json = JSON.parse(json);
198 $(document).ready(function() { 152 $(document).ready(function() {
...@@ -213,41 +167,35 @@ function SetFocus(i) { ...@@ -213,41 +167,35 @@ function SetFocus(i) {
213 $("#changes").validate(); 167 $("#changes").validate();
214 }); 168 });
215 169
216
217
218 var strVar2 = ""; 170 var strVar2 = "";
219
220
221 var pdflist = ""; 171 var pdflist = "";
222 var pdfChange = ""; 172 var pdfChange = "";
223 var f = 0; 173 var f = 0;
224 174
225
226 var scaleImage = 400 / json[0].pwidth; 175 var scaleImage = 400 / json[0].pwidth;
227 var imageHeight = json[0].pheight * scaleImage; 176 var imageHeight = json[0].pheight * scaleImage;
228 var imageWidth = '400'; 177 var imageWidth = '400';
229 console.log(json[0].pheight, scaleImage, imageHeight); 178 console.log(json[0].pheight, scaleImage, imageHeight);
230 179
231
232 pdflist += '<div id="pdfPreview" class="column">'; 180 pdflist += '<div id="pdfPreview" class="column">';
233 // pdflist += '<img id="pdfimage" src="' + pdf_customizer + '/fileentry/getImage/' + json[0].folder + '/' + json[0].example + '" width="300px">'; 181 // pdflist += '<img id="pdfimage" src="' + pdf_customizer + '/fileentry/getImage/' + json[0].folder + '/' + json[0].example + '" width="300px">';
234 pdflist += '<canvas id="Canvas" width="' + imageWidth + '" height="' + imageHeight + '" style=" margin-top:60px; border-style: solid; border-width:1px; background-image: url(' + pdf_customizer + '/fileentry/getImage/' + json[0].folder + '/' + json[0].example + '); background-size:' + imageWidth + 'px ' + imageHeight + 'px"></div>'; 182 pdflist += '<canvas id="Canvas" width="' + imageWidth + '" height="' + imageHeight + '" style=" margin-top:60px; border-style: solid; border-width:1px; background-image: url(' + pdf_customizer + '/fileentry/getImage/' + json[0].folder + '/' + json[0].example + '); background-size:' + imageWidth + 'px ' + imageHeight + 'px"></div>';
235 pdfChange += '<form id="changes" name="changes" enctype="multipart/form-data" action="" METHOD="POST"></br><h4>' + json[0].name + '</h4>'; 183 pdfChange += '<form id="changes" name="changes" enctype="multipart/form-data" action="" METHOD="POST"></br><h4>' + json[0].name + '</h4>';
236 pdfChange += '<input type="hidden" id="id" name="id" value="' + json[0].idPDF + '">'; 184 pdfChange += '<input type="hidden" id="id" name="id" value="' + json[0].idPDF + '">';
237 for (i = 0; i < json.length; ++i) { 185 for (i = 0; i < json.length; ++i) {
238 var example = json[0].folder + '/' + json[i].example 186 var example = json[0].folder + '/' + json[i].example;
239 187
240 if (json[i].change_type == "textflow") { 188 if (json[i].change_type == "textflow") {
241 pdfChange += json[i].names + ': <textarea onfocus="ShowBox(' + json[0].pheight + ',' + json[0].pwidth + ',' + json[i].locationUp + ',' + json[i].locationRight + ',' + json[i].height + ',' + json[i].width + ',' + i + ',\'' + example + '\')" id="changescontent' + [f] + '" class="textarea required" value="' + json[i].content + '" name="content[' + i + ']">' + json[i].content + '</textarea>'; 189 pdfChange += json[i].names + ': <textarea onfocus="ShowBox(' + json[0].pheight + ',' + json[0].pwidth + ',' + json[i].locationUp + ',' + json[i].locationRight + ',' + json[i].height + ',' + json[i].width + ',' + i + ',\'' + example + '\')" id="changescontent' + [f] + '" class="textarea required" value="' + json[i].content + '" name="content[' + i + ']">' + json[i].content + '</textarea>';
242 ++f 190 ++f;
243 pdfChange += '<span id="span' + i + '">' + json[i].tips + '</span><br/>'; 191 pdfChange += '<span id="span' + i + '">' + json[i].tips + '</span><br/>';
244 } 192 }
245 if (json[i].change_type == "text") { 193 if (json[i].change_type == "text") {
246 pdfChange += json[i].names + ': <input onfocusout="HideBox()" onfocus="ShowBox(' + json[0].pheight + ',' + json[0].pwidth + ',' + json[i].locationUp + ',' + json[i].locationRight + ',' + json[i].height + ',' + json[i].width + ',' + i + ',\'' + example + '\')" id="changescontent['+i+']" type="text" class="required" name="content[' + i + ']" value="' + json[i].content + '"">'; 194 pdfChange += json[i].names + ': <input onfocusout="HideBox()" onfocus="ShowBox(' + json[0].pheight + ',' + json[0].pwidth + ',' + json[i].locationUp + ',' + json[i].locationRight + ',' + json[i].height + ',' + json[i].width + ',' + i + ',\'' + example + '\')" id="changescontent[' + i + ']" type="text" class="required" name="content[' + i + ']" value="' + json[i].content + '"">';
247 pdfChange += '<span id="span' + i + '">' + json[i].tips + '</span><br/>'; 195 pdfChange += '<span id="span' + i + '">' + json[i].tips + '</span><br/>';
248 } 196 }
249 if (json[i].change_type == "img") { 197 if (json[i].change_type == "img") {
250 pdfChange += json[i].names + ':<label id="focusButton' + i + '" class="custom-file-input"><input onfocusout="HideBox()" onfocus="SetFocus('+i+'), ShowBox(' + json[0].pheight + ',' + json[0].pwidth + ',' + json[i].locationUp + ',' + json[i].locationRight + ',' + json[i].height + ',' + json[i].width + ',' + i + ',\'' + example + '\')" class="fileupload upload required" id="changescontent[' + i + ']" type="file" name="content[' + i + ']" ></label>'; 198 pdfChange += json[i].names + ':<label id="focusButton' + i + '" class="custom-file-input" tabindex="0"><input tabindex="-1" onfocusout="HideBox()" onfocus="SetFocus(' + i + '), ShowBox(' + json[0].pheight + ',' + json[0].pwidth + ',' + json[i].locationUp + ',' + json[i].locationRight + ',' + json[i].height + ',' + json[i].width + ',' + i + ',\'' + example + '\')" class="fileupload upload required" id="changescontent[' + i + ']" type="file" name="content[' + i + ']" ><span class="file-button"><span class="file-name file-button"></span><strong>Browse</strong></span></label>';
251 pdfChange += '<span id="span' + i + '">' + json[i].tips + '</span><br/>'; 199 pdfChange += '<span id="span' + i + '">' + json[i].tips + '</span><br/>';
252 } 200 }
253 if (json[i].change_type == "date") { 201 if (json[i].change_type == "date") {
...@@ -264,17 +212,11 @@ function SetFocus(i) { ...@@ -264,17 +212,11 @@ function SetFocus(i) {
264 strVar2 += ' </div></div><div id="wrapper" class="black small-up-2 medium-up-3 large-up-3">'; 212 strVar2 += ' </div></div><div id="wrapper" class="black small-up-2 medium-up-3 large-up-3">';
265 strVar2 += pdflist + '<div id="changesColumn" style="height:' + $("#changes").height() + ';" class="column" >' + pdfChange + '<div id="tezingLogo"></div></div><div id="pdfFooter"></div></div>'; 213 strVar2 += pdflist + '<div id="changesColumn" style="height:' + $("#changes").height() + ';" class="column" >' + pdfChange + '<div id="tezingLogo"></div></div><div id="pdfFooter"></div></div>';
266 214
267
268
269 document.getElementById('contentArea').innerHTML = strVar2; 215 document.getElementById('contentArea').innerHTML = strVar2;
270 document.getElementById('google_drive').innerHTML = " "; 216 document.getElementById('google_drive').innerHTML = " ";
271 217
272
273
274
275 if ($(window).width() > 700) { 218 if ($(window).width() > 700) {
276 219
277
278 $('#pdfPreview').css('position', 'relative'); 220 $('#pdfPreview').css('position', 'relative');
279 var stickySidebar = $('#pdfPreview'); 221 var stickySidebar = $('#pdfPreview');
280 222
...@@ -309,47 +251,69 @@ function SetFocus(i) { ...@@ -309,47 +251,69 @@ function SetFocus(i) {
309 stickyHeight = stickySidebar.height(); 251 stickyHeight = stickySidebar.height();
310 } 252 }
311 }); 253 });
312
313
314 } 254 }
315 255
316 tinymce.init({ 256 var tinymces = tinymce.init({
317 selector: '.textarea', 257 selector: '.textarea',
318 entity_encoding: "raw", 258 entity_encoding: "raw",
319 menubar: false, 259 menubar: false,
320 toolbar: ' bold italic', 260 toolbar: ' bold italic',
321 remove_linebreaks: false, 261 remove_linebreaks: false,
322 remove_trailing_brs: false, 262 remove_trailing_brs: false,
323 263 init_instance_callback: function(editor) {
324 264 var editorDoc = document.getElementById(editor.id + '_ifr');
265 var editorDocContent = editorDoc.contentDocument;
266 editorDoc.style.border = "2px solid #131212";
267 editorDocContent.body.style.backgroundColor = "#131212";
268 editorDocContent.body.style.color = "#ccc";
269 },
325 setup: function(editor) { 270 setup: function(editor) {
326 editor.on('focus', function(e) { 271 editor.on('focus', function(e) {
327 console.log(editor.id); 272 console.log(editor.id);
328 $('#' + editor.id).trigger("onfocus"); 273
329 $(this).css('border', '2px solid #F7A800 !important'); 274 var editorDoc = document.getElementById(editor.id + '_ifr');
275 var editorDocContent = editorDoc.contentDocument;
276 editorDoc.style.border = "2px solid #F7A800";
277
278 //$('#' + editor.id).trigger("focus");
279 //$(this).css('border', '2px solid #F7A800 !important');
330 }); 280 });
331 editor.on('focusout', function(e) { 281 editor.on('blur', function(e) {
332 // console.log('out'+editor.id); 282 console.log('out' + editor.id);
333 $(this).css('border', '0px solid #F7A800 !important'); 283 var editorDoc = document.getElementById(editor.id + '_ifr');
334 HideBox(); 284 var editorDocContent = editorDoc.contentDocument;
285 editorDoc.style.border = "2px solid #131212";
286
287 //$(this).css('border', '0px solid #F7A800 !important');
288 //HideBox();
335 }); 289 });
336 } 290 }
337
338
339
340 }); 291 });
341 292
342 var files; 293 var files;
343 var imagefiles = [];; 294 var imagefiles = [];
344
345 295
346 $(".fileupload").change(function(e) { 296 $(".fileupload").change(function(e) {
297 var target = e.target;
347 files = e.target.files; 298 files = e.target.files;
299 console.log(files);
300
301 if(files.length >= 1) {
348 for (var i = 0, file; file = files[i]; i++) { 302 for (var i = 0, file; file = files[i]; i++) {
349 //console.log(file); 303 var fileName = file.name;
304 // insert file name
305 if(fileName) {
306 $(target).parent('label').find('.file-name').text(fileName);
307 } else {
308 $(target).parent('label').find('.file-name').text('');
309 }
310
350 imagefiles.push(file); 311 imagefiles.push(file);
351 // console.log(imagefiles); 312 // console.log(imagefiles);
352 } 313 }
314 } else {
315 $(target).parent('label').find('.file-name').text('');
316 }
353 }); 317 });
354 318
355 319
...@@ -377,10 +341,10 @@ function SetFocus(i) { ...@@ -377,10 +341,10 @@ function SetFocus(i) {
377 341
378 }); 342 });
379 343
380 } 344 }
381 345
382 346
383 function returnfileOptions(files, form) { 347 function returnfileOptions(files, form) {
384 jQuery(function($) { 348 jQuery(function($) {
385 349
386 var data = new FormData(); 350 var data = new FormData();
...@@ -414,14 +378,10 @@ function SetFocus(i) { ...@@ -414,14 +378,10 @@ function SetFocus(i) {
414 }); 378 });
415 379
416 }); 380 });
417 } 381 }
418
419
420 function returnOptions(form) {
421
422
423 382
424 383
384 function returnOptions(form) {
425 jQuery(function($) { 385 jQuery(function($) {
426 386
427 $.getJSON("" + pdf_customizer + "/api/v1/get-pdf/" + id.value, function(dataReturnd) { 387 $.getJSON("" + pdf_customizer + "/api/v1/get-pdf/" + id.value, function(dataReturnd) {
...@@ -435,13 +395,11 @@ function SetFocus(i) { ...@@ -435,13 +395,11 @@ function SetFocus(i) {
435 for (i = 0; i < json.length; ++i) { 395 for (i = 0; i < json.length; ++i) {
436 396
437 397
438
439 var style = JSON.stringify(json[i].style); 398 var style = JSON.stringify(json[i].style);
440 var content = JSON.stringify(form[0][e].value); 399 var content = JSON.stringify(form[0][e].value);
441 console.log(form[0][e].value); 400 console.log(form[0][e].value);
442 401
443 402
444
445 jsonReturn += '{"label":"' + json[i].label + '", "locationUp":"' + json[i].locationUp + '", "locationRight":"' + json[i].locationRight + '","width":"' + json[i].width + '","height":"' + json[i].height + '", "pages":"' + json[i].pages + '", "content":' + content + ', "z-index":null, "idstylesPDF":"' + json[i].idstylesPDF + '", "style":' + style + ', "order":"' + json[i].order + '", "idchange_typePDF":"' + json[i].idchange_typePDF + '", "change_type":"' + json[i].change_type + '", "fileLocation":"' + pluginUrl + '/wp-content/uploads/pdf/"}'; 403 jsonReturn += '{"label":"' + json[i].label + '", "locationUp":"' + json[i].locationUp + '", "locationRight":"' + json[i].locationRight + '","width":"' + json[i].width + '","height":"' + json[i].height + '", "pages":"' + json[i].pages + '", "content":' + content + ', "z-index":null, "idstylesPDF":"' + json[i].idstylesPDF + '", "style":' + style + ', "order":"' + json[i].order + '", "idchange_typePDF":"' + json[i].idchange_typePDF + '", "change_type":"' + json[i].change_type + '", "fileLocation":"' + pluginUrl + '/wp-content/uploads/pdf/"}';
446 404
447 405
...@@ -454,8 +412,6 @@ function SetFocus(i) { ...@@ -454,8 +412,6 @@ function SetFocus(i) {
454 // console.log(jsonReturn); 412 // console.log(jsonReturn);
455 413
456 414
457
458
459 $.ajax({ 415 $.ajax({
460 url: "" + pdf_customizer + "/api/update", 416 url: "" + pdf_customizer + "/api/update",
461 type: "POST", 417 type: "POST",
...@@ -478,16 +434,8 @@ function SetFocus(i) { ...@@ -478,16 +434,8 @@ function SetFocus(i) {
478 alert(xhr.status); 434 alert(xhr.status);
479 document.getElementById('contentArea').innerHTML = xhr.responseText; 435 document.getElementById('contentArea').innerHTML = xhr.responseText;
480 } 436 }
481
482 }); 437 });
483 438
484
485
486
487 }); 439 });
488
489
490 }); 440 });
491
492
493 }
...\ No newline at end of file ...\ No newline at end of file
441 }
...\ No newline at end of file ...\ No newline at end of file
......