Advertisement
okardec

Untitled

Nov 5th, 2015
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.20 KB | None | 0 0
  1.  
  2. function sliceChapter() {
  3. //#region proprieades privadas
  4. this._id = null;
  5. this._userId = null;
  6. this._status = slice.list.interation.status.None; //define se esta sendo enviado
  7.  
  8. this._idChapter = 0;
  9. this._mangaUrl = "";
  10. this._chap = "";
  11. this._chapLast = "";
  12. this._chapNext = "";
  13.  
  14. this._viewType = 0; /// 0 > uma imagem por pagina, 1 > todas imagens por pagina (lista)
  15. this._totalPag = 0;
  16. this._pageView = 1;
  17.  
  18. this._lightShow = false;
  19.  
  20. this._setStatus = function (status) {
  21. this._status = status;
  22. return this;
  23. };
  24. this._getStatus = function () {
  25. return this._status;
  26. };
  27.  
  28. this._store = function () {
  29. window._sliceChapter = this;
  30.  
  31.  
  32. var o = new Object();
  33. o = {
  34. view_type: this._getViewType(),
  35. light_show: this._isLightShow()
  36. }
  37. var storage = new sliceStorage(slice.list.storage.method.Local);
  38. storage.setField('sliceChapter', o);
  39. };
  40. this._load = function () {
  41.  
  42.  
  43. var storage = new sliceStorage(slice.list.storage.method.Local);
  44. if (storage.issetField('sliceChapter')) {
  45. var st = storage.getField('sliceChapter');
  46. this._setViewType(st.view_type);
  47. this._setLightShow(st.light_show);
  48. }
  49.  
  50. var o = window._sliceChapter;
  51. if (!o) {
  52. return;
  53. }
  54. this.setIdChapter(o.getIdChapter());
  55. this.setId(o.getId());
  56. this.setUserId(o.getUserId());
  57. this._setStatus(o._getStatus());
  58. this._setViewType(o._getViewType());
  59. this.setTotalPag(o.getTotalPag());
  60. this._setLightShow(o._isLightShow());
  61. };
  62.  
  63. this._setViewType = function (i) {
  64. this._viewType = i;
  65. this._store();
  66. return this;
  67. };
  68. this._getViewType = function () {
  69. return this._viewType;
  70. };
  71.  
  72. this._setLightShow = function (i) {
  73. this._lightShow = i;
  74. this._store();
  75. return this;
  76. };
  77. this._isLightShow = function () {
  78. return this._lightShow;
  79. };
  80.  
  81.  
  82.  
  83. this._lightChange = function () {
  84.  
  85. var d = document.getElementById('chapter-overley');
  86. if (!d) {
  87. return;
  88. }
  89.  
  90. if (d.style.display == "none") {
  91. d.style.display = "block";
  92. this._setLightShow(true);
  93. return;
  94. }
  95. d.style.display = "none";
  96. this._setLightShow(false);
  97.  
  98. }
  99.  
  100. this._changeView = function () {
  101.  
  102. var d = null;
  103. /// 0 > uma imagem por pagina, 1 > todas imagens por pagina (lista)
  104. var vType = (this._getViewType() == 1 ? 0 : 1);
  105. var display = "block";
  106.  
  107. this._setViewType(vType);
  108.  
  109. for (var n = 0; n <= this.getTotalPag(); n++) {
  110.  
  111. d = document.getElementById('page_view_' + n);
  112. if (d) {
  113.  
  114. display = "none";
  115. if (vType == 1) {
  116. display = "block";
  117. }
  118. if (n <= 1) {
  119. display = "block";
  120. }
  121.  
  122. d.style.display = display;
  123.  
  124. }
  125. };
  126.  
  127. }
  128.  
  129. this._pageChange = function (page) {
  130.  
  131. this._load();
  132.  
  133. if (page > this.getTotalPag()) {
  134. ///console.log('chegou ao fim. ' + this.getChapNext());
  135. window.location = this.getChapNext();
  136. return;
  137. }
  138. if (page <= 0) {
  139. ///console.log('volta o cap. ' + this.getChapLast());
  140. window.location = this.getChapLast();
  141. return;
  142. }
  143.  
  144. /// 0 > uma imagem por pagina, 1 > todas imagens por pagina (lista)
  145. if (this._getViewType() == 1) {
  146. var d = document.getElementById('page_view_' + page);
  147. if (d) {
  148. ///joga encima do div
  149. this.setPageView(page);
  150. this._pageSelectChange();
  151. d.scrollIntoView();
  152. }
  153. return;
  154. }
  155.  
  156. for (var n = 0; n <= this.getTotalPag(); n++) {
  157. var d = document.getElementById('page_view_' + n);
  158. if (d) {
  159. d.style.display = "none";
  160. }
  161. };
  162.  
  163. var d = document.getElementById('page_view_' + page);
  164. if (d) {
  165. this.setPageView(page);
  166. this._pageSelectChange();
  167. d.style.display = "block";
  168. //d.scrollIntoView();
  169. }
  170.  
  171. var d = document.getElementById('chapter-view-controls-top');
  172. if (d) {
  173. d.scrollIntoView();
  174. }
  175.  
  176.  
  177. }
  178.  
  179. this._pageSelectChange = function () {
  180. var d = document.getElementById('pag-select-top');
  181. if (d) {
  182. d.value = this.getPageView();
  183. }
  184.  
  185. var d = document.getElementById('pag-select-bottom');
  186. if (d) {
  187. d.value = this.getPageView();
  188. }
  189.  
  190. new sliceContainer('page-count-view').write(this.getPageView());
  191. }
  192. this._next = function () {
  193. this._pageChange(this.getPageView() + 1);
  194. }
  195. this._last = function () {
  196. this._pageChange(this.getPageView() - 1);
  197. }
  198.  
  199.  
  200. this._rand = function (min, max) {
  201. return Math.floor(Math.random() * (max - min + 1) + min);
  202. }
  203.  
  204. this._initFormWarning = function () {
  205.  
  206. var s = "";
  207.  
  208. //s += '<div class="modal-form-title">Informar erros no capítulo</div>';
  209.  
  210. s += '<div class="modal-form-content">';
  211.  
  212. s += '<div class="modal-form-line"><div class="input-field col s12">';
  213. s += '<input id="name" type="text" class="validate">';
  214. s += '<label for="name" data-error="Informe seu nome" data-success="OK">Informe seu nome</label>';
  215. s += '</div>';
  216. s += '<div class="input-field col s12">';
  217. s += '<input id="email" type="email" class="validate">';
  218. s += '<label for="email" data-error="Email inválido" data-success="OK">Informe seu e-mail</label>';
  219. s += '</div>';
  220. s += '<div class="input-field col s12">';
  221. s += '<select id="erro_type" class="browser-default">';
  222. s += '<option value="0" disabled selected>Qual erro você encontrou?</option>';
  223. s += '<option value="1">As imagens das páginas não aparecem</option>';
  224. s += '<option value="2">Algumas páginas estão quebradas</option>';
  225. s += '<option value="3">Imagens do capítulo errado</option>';
  226. s += '<option value="4">Imagens embaralhadas (fora da ordem)</option>';
  227. s += '<option value="5">Faltam páginas no capítulo</option>';
  228. s += '<option value="6">Capítulo de um mangá diferente do informado</option>';
  229. s += '<option value="7">Imagens que não condizem com o capítulo ou ao mangá</option>';
  230. s += '</select>';
  231. s += '</div>';
  232.  
  233. s += '<div class="modal-form-line col s12">';
  234. s += '<div class="form-check-box">';
  235. s += '<div class="form-check-box-title">Informe corretamente a <strong>SOMA</strong> dos valores</div>';
  236. s += '<div class="input-field col s12">';
  237. s += '<div class="input-field input-field-med">'; //col s4 m4 l4
  238. s += '<input disabled value="' + this._rand(1, 20) + '" id="value_check_1" type="text" class="validate">';
  239. //s += '<label for="value_check_1">Valor 1</label>';
  240. s += '</div>';
  241. s += '<div class="input-field input-field-med">'; //col s4 m4 l4
  242. s += '<input disabled value="'+this._rand(1,20)+'" id="value_check_2" type="text" class="validate">';
  243. //s += '<label for="value_check_2">Valor 2</label>';
  244. s += '</div>';
  245. s += '<div class="input-field input-field-med">'; //col s4 m4 l4
  246. s += '<input id="value_check" type="text" class="validate">';
  247. s += '<label for="value_check">Resultado?</label>';
  248. s += '</div>';
  249.  
  250. s += '</div>';
  251. s += '</div>';
  252. s += '</div>';
  253.  
  254. s += '</div>'; //modal-form-content
  255.  
  256. new sliceBox().setViewClose(true).setWidth(600).setHeight(200).setForm('form_warning')
  257. .setTitle('Informar erros no capítulo')
  258. .setContent(s)
  259. .appendButton('Enviar', slice.list.box.button.Button, function () { new sliceChapter()._sendWarning(); })
  260. .appendButton('Cancelar', slice.list.box.button.Close)
  261. .show();
  262.  
  263. }
  264.  
  265. this._sendWarning = function () {
  266.  
  267. var ed1 = document.getElementById('name');
  268. if (!ed1) {
  269. return;
  270. }
  271. var ed2 = document.getElementById('email');
  272. if (!ed2) {
  273. return;
  274. }
  275. var ed3 = document.getElementById('erro_type');
  276. if (!ed3) {
  277. return;
  278. }
  279. var ed4 = document.getElementById('value_check_1');
  280. if (!ed4) {
  281. return;
  282. }
  283. var ed5 = document.getElementById('value_check_2');
  284. if (!ed5) {
  285. return;
  286. }
  287. var ed6 = document.getElementById('value_check');
  288. if (!ed6) {
  289. return;
  290. }
  291.  
  292.  
  293. if (ed1.value.length <= 3) {
  294. new sliceLoader().show("Informe seu nome corretamente", slice.list.loader.type.Info, 5);
  295. ed1.focus();
  296. return;
  297. }
  298. if (ed2.value.length <= 3) {
  299. new sliceLoader().show("Informe seu email corretamente", slice.list.loader.type.Info, 5);
  300. ed2.focus();
  301. return;
  302. }
  303. if (ed3.value <= 0) {
  304. new sliceLoader().show("Informe qual foi o erro encontrato", slice.list.loader.type.Info, 5);
  305. return;
  306. }
  307.  
  308. var vCheck = parseInt(ed4.value) + parseInt(ed5.value);
  309. if (vCheck != parseInt(ed6.value)) {
  310. //console.log(parseInt(ed3.value) + " - " + parseInt(ed4.value) + " - " + vCheck + " - " + parseInt(ed5.value));
  311. new sliceLoader().show("Confirme corretamente a conta", slice.list.loader.type.Info, 5);
  312. ed5.focus();
  313. return;
  314. }
  315.  
  316.  
  317. console.log('enviando');
  318.  
  319.  
  320. var o = new sliceRequest(slice.list.request.method.Post, 'sys/send/chapter/warning');
  321. ///o.addPostVar('id', this.getId())
  322. o.addPostVar('name', new sliceString(ed1.value).replaceWordChars())
  323. .addPostVar('email', new sliceString(ed2.value).replaceWordChars())
  324. .addPostVar('erro_type', ed3.value)
  325. .addPostVar('id_chapter', this.getIdChapter())
  326. ;
  327.  
  328. o.obj = this;
  329. o.onSubmit = function () {
  330. this.obj._setStatus(slice.list.interation.status.Sending)._store();
  331. new sliceLoader().show("Enviando, aguarde um momento", slice.list.loader.type.Progress);
  332. };
  333. o.onReady = function () {
  334. this.obj._setStatus(slice.list.interation.status.None)._store();
  335. if (!this.isValidResponse()) {
  336. new sliceLoader().show(this.getErrorDescription(), slice.list.loader.type.Info, 5);
  337. return;
  338. }
  339. new sliceLoader().show("Obrigado por nos avisar. Logo iremos analisar a mensagem e resolver os problemas encontrados", slice.list.loader.type.Info, 5);
  340. new sliceBox().close();
  341.  
  342. };
  343. o.send();
  344.  
  345. }
  346.  
  347. this._keyDown = function (key) {
  348.  
  349. var d = document.getElementById('sliceBox');
  350. if (d) {
  351. return;
  352. }
  353.  
  354. //detecta se a seta foi pressionada
  355. switch (key.keyCode) {
  356. case 39:
  357. case 68:
  358. //right
  359. this._next();
  360. break;
  361. case 37:
  362. case 65:
  363. //left
  364. this._last();
  365. break;
  366. }
  367. };
  368.  
  369. this._initImages = function () {
  370.  
  371. this.showProgress();
  372. var jsonCode = new sliceContainer('js_co_chap_imgs').read();
  373.  
  374. if (jsonCode.length < 0) {
  375. new sliceLoader().show("As imagens não foram carregadas corretamente :( ", slice.list.loader.type.Info, 5);
  376. return;
  377. }
  378.  
  379. jsonCode = jsonCode.slice(0, -2);
  380. var objJ = JSON.parse(window.atob(jsonCode));
  381.  
  382. for (var n = 0; n != objJ.length; n++) {
  383. var d = document.getElementById('page_view_src_' + objJ[n].page);
  384. if (d) {
  385. var image = new Image();
  386. image.obj = d;
  387. image.onload = function () {
  388. this.obj.src = this.src;
  389. };
  390. image.src = objJ[n].image;
  391. ///d.src = objJ[n].image;
  392.  
  393. d.obj = this;
  394. d.onclick = function () {
  395. this.obj._next();
  396. }
  397. }
  398. };
  399. new sliceContainer('js_co_chap_imgs').remove();
  400. this.hideProgress();
  401. }
  402.  
  403. this.showProgress = function () {
  404. new sliceContainer('progress_top').show();
  405. new sliceContainer('progress_bottom').show();
  406. }
  407. this.hideProgress = function () {
  408. new sliceContainer('progress_top').hide();
  409. new sliceContainer('progress_bottom').hide();
  410. }
  411.  
  412. this._initSaveState = function () {
  413.  
  414. ///exibe o box de visualizacao
  415. if (this._isLightShow()) {
  416. var d = document.getElementById('chapter-overley');
  417. if (d) {
  418. d.style.display = "block";
  419. }
  420. }
  421.  
  422. ////muda a visualizaçao
  423. if (this._getViewType() == 1) {
  424. for (var n = 0; n <= this.getTotalPag(); n++) {
  425. d = document.getElementById('page_view_' + n);
  426. if (d) {
  427. d.style.display = "block";
  428. }
  429. }
  430. }
  431.  
  432. }
  433. //#endregion
  434. //#region propriedades públicas
  435.  
  436. this.setId = function (i) {
  437. this._id = i;
  438. this._store();
  439. return this;
  440. };
  441. this.getId = function () {
  442. return this._id;
  443. };
  444. this.setIdChapter = function (i) {
  445. this._idChapter = i;
  446. this._store();
  447. return this;
  448. };
  449. this.getIdChapter = function () {
  450. return this._idChapter;
  451. };
  452. this.setUserId = function (i) {
  453. this._userId = i;
  454. this._store();
  455. return this;
  456. };
  457. this.getUserId = function () {
  458. return this._userId;
  459. };
  460.  
  461. this.addView = function () {
  462. if (this.getId() <= 0) {
  463. return;
  464. }
  465.  
  466. var o = new sliceRequest(slice.list.request.method.Get, 'sys/chapter/add/view/' + this.getId());
  467. o.obj = this;
  468. o.onSubmit = function () {
  469. //this.obj._setStatus(slice.list.interation.status.Sending)._store();
  470. };
  471. o.onReady = function () {
  472. //this.obj._setStatus(slice.list.interation.status.None)._store();
  473. if (!this.isValidResponse()) {
  474. //new sliceLoader().show(this.getErrorDescription(), slice.list.loader.type.Info, 5);
  475. return;
  476. }
  477. };
  478. o.send();
  479. return;
  480. };
  481.  
  482. this.init = function () {
  483. setTimeout('new sliceChapter().addView();', (10 * 1000));
  484.  
  485. document.obj = this;
  486. document.onkeydown = function (event) { this.obj._keyDown(event); };
  487.  
  488. this._initImages();
  489.  
  490. this._initSaveState();
  491.  
  492. var d = document.getElementById('chapter-select-top');
  493. if (d) {
  494. d.value = this.getChap();
  495. d.obj = this;
  496. d.onchange = function () {
  497. window.location = this.obj.getMangaUrl() + "capitulo-" + this.value + '/';
  498. ////console.log(this.obj.getMangaUrl() + "capitulo-" + this.value + '/');
  499. }
  500. }
  501.  
  502. var d = document.getElementById('chapter-select-bottom');
  503. if (d) {
  504. d.value = this.getChap();
  505. d.obj = this;
  506. d.onchange = function () {
  507. window.location = this.obj.getMangaUrl() + "capitulo-" + this.value + '/';
  508. ////console.log(this.obj.getMangaUrl() +"capitulo-"+ this.value + '/');
  509. }
  510. }
  511.  
  512. var d = document.getElementById('bt-light-bottom');
  513. if (d) {
  514. d.obj = this;
  515. d.onclick = function () {
  516. this.obj._lightChange();
  517. }
  518. }
  519. var d = document.getElementById('bt-light-top');
  520. if (d) {
  521. d.obj = this;
  522. d.onclick = function () {
  523. this.obj._lightChange();
  524. }
  525. }
  526.  
  527. var d = document.getElementById('bt-view-bottom');
  528. if (d) {
  529. d.obj = this;
  530. d.onclick = function () {
  531. this.obj._changeView();
  532. }
  533. }
  534. var d = document.getElementById('bt-view-top');
  535. if (d) {
  536. d.obj = this;
  537. d.onclick = function () {
  538. this.obj._changeView();
  539. }
  540. }
  541.  
  542. var d = document.getElementById('pag-select-top');
  543. if (d) {
  544. d.obj = this;
  545. d.onchange = function () {
  546. this.obj._pageChange(parseInt(this.value));
  547. }
  548. }
  549. var d = document.getElementById('pag-select-bottom');
  550. if (d) {
  551. d.obj = this;
  552. d.onchange = function () {
  553. this.obj._pageChange(parseInt(this.value));
  554. }
  555. }
  556.  
  557.  
  558. var d = document.getElementById('bt-next-bottom');
  559. if (d) {
  560. d.obj = this;
  561. d.onclick = function () {
  562. this.obj._next();
  563. }
  564. }
  565. var d = document.getElementById('bt-next-top');
  566. if (d) {
  567. d.obj = this;
  568. d.onclick = function () {
  569. this.obj._next();
  570. }
  571. }
  572.  
  573.  
  574. var d = document.getElementById('bt-last-bottom');
  575. if (d) {
  576. d.obj = this;
  577. d.onclick = function () {
  578. this.obj._last();
  579. }
  580. }
  581. var d = document.getElementById('bt-last-top');
  582. if (d) {
  583. d.obj = this;
  584. d.onclick = function () {
  585. this.obj._last();
  586. }
  587. }
  588.  
  589. var d = document.getElementById('bt-warning-top');
  590. if (d) {
  591. d.obj = this;
  592. d.onclick = function () {
  593. this.obj._initFormWarning();
  594. }
  595. }
  596. var d = document.getElementById('bt-warning-bottom');
  597. if (d) {
  598. d.obj = this;
  599. d.onclick = function () {
  600. this.obj._initFormWarning();
  601. }
  602. }
  603.  
  604.  
  605. var user = new sliceUser();
  606. if (!user.isLogged()) {
  607. return;
  608. }
  609. var div = document.getElementById('chapter_edit_bt');
  610. if (!div) {
  611. return;
  612. }
  613. if (!user.isAdmin()) {
  614. return;
  615. }
  616. var s = "";
  617. //s += '<div style="margin:15px 0px; text-align: right;">';
  618. s += ' | <a href="javascript:void(0);" id="btEdit">Editar</a> | ';
  619. s += '<a href="javascript:void(0);" id="btRevise">Revisar</a>';
  620. //s += '</div>';
  621.  
  622.  
  623. new sliceContainer('chapter_edit_bt').write(s);
  624. new sliceContainer('chapter_edit_bt').show();
  625.  
  626. var d = document.getElementById('btEdit');
  627. if (d) {
  628. d.obj = this;
  629. d.onclick = function () {
  630. window.location = 'http://lermangas.com/sys_admin/editar-capitulo/' + this.obj.getId() + '/';
  631. }
  632. }
  633. var d = document.getElementById('btRevise');
  634. if (d) {
  635. d.obj = this;
  636. d.onclick = function () {
  637. window.location = 'http://lermangas.com/sys_admin/revisar-capitulo/' + this.obj.getId() + '/';
  638. }
  639. }
  640.  
  641. };
  642.  
  643.  
  644. this.setChapNext = function (i) {
  645. this._chapNext = i;
  646. this._store();
  647. return this;
  648. };
  649. this.getChapNext = function () {
  650. return this._chapNext;
  651. };
  652. this.setChapLast = function (i) {
  653. this._chapLast = i;
  654. this._store();
  655. return this;
  656. };
  657. this.getChapLast = function () {
  658. return this._chapLast;
  659. };
  660.  
  661. this.setChap = function (i) {
  662. this._chap = i;
  663. this._store();
  664. return this;
  665. };
  666. this.getChap = function () {
  667. return this._chap;
  668. };
  669.  
  670. this.setMangaUrl = function (i) {
  671. this._mangaUrl = i;
  672. this._store();
  673. return this;
  674. };
  675. this.getMangaUrl = function () {
  676. return this._mangaUrl;
  677. };
  678.  
  679. this.setTotalPag = function (i) {
  680. this._totalPag = i;
  681. this._store();
  682. return this;
  683. };
  684. this.getTotalPag = function () {
  685. return this._totalPag;
  686. };
  687.  
  688. this.setPageView = function (i) {
  689. this._pageView = i;
  690. this._store();
  691. return this;
  692. };
  693. this.getPageView = function () {
  694. return this._pageView;
  695. };
  696.  
  697.  
  698. //#endregion
  699. //#region construtor
  700. this._load();
  701.  
  702. this._store();
  703. //#endregion
  704. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement