Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sliceChapter() {
- //#region proprieades privadas
- this._id = null;
- this._userId = null;
- this._status = slice.list.interation.status.None; //define se esta sendo enviado
- this._idChapter = 0;
- this._mangaUrl = "";
- this._chap = "";
- this._chapLast = "";
- this._chapNext = "";
- this._viewType = 0; /// 0 > uma imagem por pagina, 1 > todas imagens por pagina (lista)
- this._totalPag = 0;
- this._pageView = 1;
- this._lightShow = false;
- this._setStatus = function (status) {
- this._status = status;
- return this;
- };
- this._getStatus = function () {
- return this._status;
- };
- this._store = function () {
- window._sliceChapter = this;
- var o = new Object();
- o = {
- view_type: this._getViewType(),
- light_show: this._isLightShow()
- }
- var storage = new sliceStorage(slice.list.storage.method.Local);
- storage.setField('sliceChapter', o);
- };
- this._load = function () {
- var storage = new sliceStorage(slice.list.storage.method.Local);
- if (storage.issetField('sliceChapter')) {
- var st = storage.getField('sliceChapter');
- this._setViewType(st.view_type);
- this._setLightShow(st.light_show);
- }
- var o = window._sliceChapter;
- if (!o) {
- return;
- }
- this.setIdChapter(o.getIdChapter());
- this.setId(o.getId());
- this.setUserId(o.getUserId());
- this._setStatus(o._getStatus());
- this._setViewType(o._getViewType());
- this.setTotalPag(o.getTotalPag());
- this._setLightShow(o._isLightShow());
- };
- this._setViewType = function (i) {
- this._viewType = i;
- this._store();
- return this;
- };
- this._getViewType = function () {
- return this._viewType;
- };
- this._setLightShow = function (i) {
- this._lightShow = i;
- this._store();
- return this;
- };
- this._isLightShow = function () {
- return this._lightShow;
- };
- this._lightChange = function () {
- var d = document.getElementById('chapter-overley');
- if (!d) {
- return;
- }
- if (d.style.display == "none") {
- d.style.display = "block";
- this._setLightShow(true);
- return;
- }
- d.style.display = "none";
- this._setLightShow(false);
- }
- this._changeView = function () {
- var d = null;
- /// 0 > uma imagem por pagina, 1 > todas imagens por pagina (lista)
- var vType = (this._getViewType() == 1 ? 0 : 1);
- var display = "block";
- this._setViewType(vType);
- for (var n = 0; n <= this.getTotalPag(); n++) {
- d = document.getElementById('page_view_' + n);
- if (d) {
- display = "none";
- if (vType == 1) {
- display = "block";
- }
- if (n <= 1) {
- display = "block";
- }
- d.style.display = display;
- }
- };
- }
- this._pageChange = function (page) {
- this._load();
- if (page > this.getTotalPag()) {
- ///console.log('chegou ao fim. ' + this.getChapNext());
- window.location = this.getChapNext();
- return;
- }
- if (page <= 0) {
- ///console.log('volta o cap. ' + this.getChapLast());
- window.location = this.getChapLast();
- return;
- }
- /// 0 > uma imagem por pagina, 1 > todas imagens por pagina (lista)
- if (this._getViewType() == 1) {
- var d = document.getElementById('page_view_' + page);
- if (d) {
- ///joga encima do div
- this.setPageView(page);
- this._pageSelectChange();
- d.scrollIntoView();
- }
- return;
- }
- for (var n = 0; n <= this.getTotalPag(); n++) {
- var d = document.getElementById('page_view_' + n);
- if (d) {
- d.style.display = "none";
- }
- };
- var d = document.getElementById('page_view_' + page);
- if (d) {
- this.setPageView(page);
- this._pageSelectChange();
- d.style.display = "block";
- //d.scrollIntoView();
- }
- var d = document.getElementById('chapter-view-controls-top');
- if (d) {
- d.scrollIntoView();
- }
- }
- this._pageSelectChange = function () {
- var d = document.getElementById('pag-select-top');
- if (d) {
- d.value = this.getPageView();
- }
- var d = document.getElementById('pag-select-bottom');
- if (d) {
- d.value = this.getPageView();
- }
- new sliceContainer('page-count-view').write(this.getPageView());
- }
- this._next = function () {
- this._pageChange(this.getPageView() + 1);
- }
- this._last = function () {
- this._pageChange(this.getPageView() - 1);
- }
- this._rand = function (min, max) {
- return Math.floor(Math.random() * (max - min + 1) + min);
- }
- this._initFormWarning = function () {
- var s = "";
- //s += '<div class="modal-form-title">Informar erros no capítulo</div>';
- s += '<div class="modal-form-content">';
- s += '<div class="modal-form-line"><div class="input-field col s12">';
- s += '<input id="name" type="text" class="validate">';
- s += '<label for="name" data-error="Informe seu nome" data-success="OK">Informe seu nome</label>';
- s += '</div>';
- s += '<div class="input-field col s12">';
- s += '<input id="email" type="email" class="validate">';
- s += '<label for="email" data-error="Email inválido" data-success="OK">Informe seu e-mail</label>';
- s += '</div>';
- s += '<div class="input-field col s12">';
- s += '<select id="erro_type" class="browser-default">';
- s += '<option value="0" disabled selected>Qual erro você encontrou?</option>';
- s += '<option value="1">As imagens das páginas não aparecem</option>';
- s += '<option value="2">Algumas páginas estão quebradas</option>';
- s += '<option value="3">Imagens do capítulo errado</option>';
- s += '<option value="4">Imagens embaralhadas (fora da ordem)</option>';
- s += '<option value="5">Faltam páginas no capítulo</option>';
- s += '<option value="6">Capítulo de um mangá diferente do informado</option>';
- s += '<option value="7">Imagens que não condizem com o capítulo ou ao mangá</option>';
- s += '</select>';
- s += '</div>';
- s += '<div class="modal-form-line col s12">';
- s += '<div class="form-check-box">';
- s += '<div class="form-check-box-title">Informe corretamente a <strong>SOMA</strong> dos valores</div>';
- s += '<div class="input-field col s12">';
- s += '<div class="input-field input-field-med">'; //col s4 m4 l4
- s += '<input disabled value="' + this._rand(1, 20) + '" id="value_check_1" type="text" class="validate">';
- //s += '<label for="value_check_1">Valor 1</label>';
- s += '</div>';
- s += '<div class="input-field input-field-med">'; //col s4 m4 l4
- s += '<input disabled value="'+this._rand(1,20)+'" id="value_check_2" type="text" class="validate">';
- //s += '<label for="value_check_2">Valor 2</label>';
- s += '</div>';
- s += '<div class="input-field input-field-med">'; //col s4 m4 l4
- s += '<input id="value_check" type="text" class="validate">';
- s += '<label for="value_check">Resultado?</label>';
- s += '</div>';
- s += '</div>';
- s += '</div>';
- s += '</div>';
- s += '</div>'; //modal-form-content
- new sliceBox().setViewClose(true).setWidth(600).setHeight(200).setForm('form_warning')
- .setTitle('Informar erros no capítulo')
- .setContent(s)
- .appendButton('Enviar', slice.list.box.button.Button, function () { new sliceChapter()._sendWarning(); })
- .appendButton('Cancelar', slice.list.box.button.Close)
- .show();
- }
- this._sendWarning = function () {
- var ed1 = document.getElementById('name');
- if (!ed1) {
- return;
- }
- var ed2 = document.getElementById('email');
- if (!ed2) {
- return;
- }
- var ed3 = document.getElementById('erro_type');
- if (!ed3) {
- return;
- }
- var ed4 = document.getElementById('value_check_1');
- if (!ed4) {
- return;
- }
- var ed5 = document.getElementById('value_check_2');
- if (!ed5) {
- return;
- }
- var ed6 = document.getElementById('value_check');
- if (!ed6) {
- return;
- }
- if (ed1.value.length <= 3) {
- new sliceLoader().show("Informe seu nome corretamente", slice.list.loader.type.Info, 5);
- ed1.focus();
- return;
- }
- if (ed2.value.length <= 3) {
- new sliceLoader().show("Informe seu email corretamente", slice.list.loader.type.Info, 5);
- ed2.focus();
- return;
- }
- if (ed3.value <= 0) {
- new sliceLoader().show("Informe qual foi o erro encontrato", slice.list.loader.type.Info, 5);
- return;
- }
- var vCheck = parseInt(ed4.value) + parseInt(ed5.value);
- if (vCheck != parseInt(ed6.value)) {
- //console.log(parseInt(ed3.value) + " - " + parseInt(ed4.value) + " - " + vCheck + " - " + parseInt(ed5.value));
- new sliceLoader().show("Confirme corretamente a conta", slice.list.loader.type.Info, 5);
- ed5.focus();
- return;
- }
- console.log('enviando');
- var o = new sliceRequest(slice.list.request.method.Post, 'sys/send/chapter/warning');
- ///o.addPostVar('id', this.getId())
- o.addPostVar('name', new sliceString(ed1.value).replaceWordChars())
- .addPostVar('email', new sliceString(ed2.value).replaceWordChars())
- .addPostVar('erro_type', ed3.value)
- .addPostVar('id_chapter', this.getIdChapter())
- ;
- o.obj = this;
- o.onSubmit = function () {
- this.obj._setStatus(slice.list.interation.status.Sending)._store();
- new sliceLoader().show("Enviando, aguarde um momento", slice.list.loader.type.Progress);
- };
- o.onReady = function () {
- this.obj._setStatus(slice.list.interation.status.None)._store();
- if (!this.isValidResponse()) {
- new sliceLoader().show(this.getErrorDescription(), slice.list.loader.type.Info, 5);
- return;
- }
- new sliceLoader().show("Obrigado por nos avisar. Logo iremos analisar a mensagem e resolver os problemas encontrados", slice.list.loader.type.Info, 5);
- new sliceBox().close();
- };
- o.send();
- }
- this._keyDown = function (key) {
- var d = document.getElementById('sliceBox');
- if (d) {
- return;
- }
- //detecta se a seta foi pressionada
- switch (key.keyCode) {
- case 39:
- case 68:
- //right
- this._next();
- break;
- case 37:
- case 65:
- //left
- this._last();
- break;
- }
- };
- this._initImages = function () {
- this.showProgress();
- var jsonCode = new sliceContainer('js_co_chap_imgs').read();
- if (jsonCode.length < 0) {
- new sliceLoader().show("As imagens não foram carregadas corretamente :( ", slice.list.loader.type.Info, 5);
- return;
- }
- jsonCode = jsonCode.slice(0, -2);
- var objJ = JSON.parse(window.atob(jsonCode));
- for (var n = 0; n != objJ.length; n++) {
- var d = document.getElementById('page_view_src_' + objJ[n].page);
- if (d) {
- var image = new Image();
- image.obj = d;
- image.onload = function () {
- this.obj.src = this.src;
- };
- image.src = objJ[n].image;
- ///d.src = objJ[n].image;
- d.obj = this;
- d.onclick = function () {
- this.obj._next();
- }
- }
- };
- new sliceContainer('js_co_chap_imgs').remove();
- this.hideProgress();
- }
- this.showProgress = function () {
- new sliceContainer('progress_top').show();
- new sliceContainer('progress_bottom').show();
- }
- this.hideProgress = function () {
- new sliceContainer('progress_top').hide();
- new sliceContainer('progress_bottom').hide();
- }
- this._initSaveState = function () {
- ///exibe o box de visualizacao
- if (this._isLightShow()) {
- var d = document.getElementById('chapter-overley');
- if (d) {
- d.style.display = "block";
- }
- }
- ////muda a visualizaçao
- if (this._getViewType() == 1) {
- for (var n = 0; n <= this.getTotalPag(); n++) {
- d = document.getElementById('page_view_' + n);
- if (d) {
- d.style.display = "block";
- }
- }
- }
- }
- //#endregion
- //#region propriedades públicas
- this.setId = function (i) {
- this._id = i;
- this._store();
- return this;
- };
- this.getId = function () {
- return this._id;
- };
- this.setIdChapter = function (i) {
- this._idChapter = i;
- this._store();
- return this;
- };
- this.getIdChapter = function () {
- return this._idChapter;
- };
- this.setUserId = function (i) {
- this._userId = i;
- this._store();
- return this;
- };
- this.getUserId = function () {
- return this._userId;
- };
- this.addView = function () {
- if (this.getId() <= 0) {
- return;
- }
- var o = new sliceRequest(slice.list.request.method.Get, 'sys/chapter/add/view/' + this.getId());
- o.obj = this;
- o.onSubmit = function () {
- //this.obj._setStatus(slice.list.interation.status.Sending)._store();
- };
- o.onReady = function () {
- //this.obj._setStatus(slice.list.interation.status.None)._store();
- if (!this.isValidResponse()) {
- //new sliceLoader().show(this.getErrorDescription(), slice.list.loader.type.Info, 5);
- return;
- }
- };
- o.send();
- return;
- };
- this.init = function () {
- setTimeout('new sliceChapter().addView();', (10 * 1000));
- document.obj = this;
- document.onkeydown = function (event) { this.obj._keyDown(event); };
- this._initImages();
- this._initSaveState();
- var d = document.getElementById('chapter-select-top');
- if (d) {
- d.value = this.getChap();
- d.obj = this;
- d.onchange = function () {
- window.location = this.obj.getMangaUrl() + "capitulo-" + this.value + '/';
- ////console.log(this.obj.getMangaUrl() + "capitulo-" + this.value + '/');
- }
- }
- var d = document.getElementById('chapter-select-bottom');
- if (d) {
- d.value = this.getChap();
- d.obj = this;
- d.onchange = function () {
- window.location = this.obj.getMangaUrl() + "capitulo-" + this.value + '/';
- ////console.log(this.obj.getMangaUrl() +"capitulo-"+ this.value + '/');
- }
- }
- var d = document.getElementById('bt-light-bottom');
- if (d) {
- d.obj = this;
- d.onclick = function () {
- this.obj._lightChange();
- }
- }
- var d = document.getElementById('bt-light-top');
- if (d) {
- d.obj = this;
- d.onclick = function () {
- this.obj._lightChange();
- }
- }
- var d = document.getElementById('bt-view-bottom');
- if (d) {
- d.obj = this;
- d.onclick = function () {
- this.obj._changeView();
- }
- }
- var d = document.getElementById('bt-view-top');
- if (d) {
- d.obj = this;
- d.onclick = function () {
- this.obj._changeView();
- }
- }
- var d = document.getElementById('pag-select-top');
- if (d) {
- d.obj = this;
- d.onchange = function () {
- this.obj._pageChange(parseInt(this.value));
- }
- }
- var d = document.getElementById('pag-select-bottom');
- if (d) {
- d.obj = this;
- d.onchange = function () {
- this.obj._pageChange(parseInt(this.value));
- }
- }
- var d = document.getElementById('bt-next-bottom');
- if (d) {
- d.obj = this;
- d.onclick = function () {
- this.obj._next();
- }
- }
- var d = document.getElementById('bt-next-top');
- if (d) {
- d.obj = this;
- d.onclick = function () {
- this.obj._next();
- }
- }
- var d = document.getElementById('bt-last-bottom');
- if (d) {
- d.obj = this;
- d.onclick = function () {
- this.obj._last();
- }
- }
- var d = document.getElementById('bt-last-top');
- if (d) {
- d.obj = this;
- d.onclick = function () {
- this.obj._last();
- }
- }
- var d = document.getElementById('bt-warning-top');
- if (d) {
- d.obj = this;
- d.onclick = function () {
- this.obj._initFormWarning();
- }
- }
- var d = document.getElementById('bt-warning-bottom');
- if (d) {
- d.obj = this;
- d.onclick = function () {
- this.obj._initFormWarning();
- }
- }
- var user = new sliceUser();
- if (!user.isLogged()) {
- return;
- }
- var div = document.getElementById('chapter_edit_bt');
- if (!div) {
- return;
- }
- if (!user.isAdmin()) {
- return;
- }
- var s = "";
- //s += '<div style="margin:15px 0px; text-align: right;">';
- s += ' | <a href="javascript:void(0);" id="btEdit">Editar</a> | ';
- s += '<a href="javascript:void(0);" id="btRevise">Revisar</a>';
- //s += '</div>';
- new sliceContainer('chapter_edit_bt').write(s);
- new sliceContainer('chapter_edit_bt').show();
- var d = document.getElementById('btEdit');
- if (d) {
- d.obj = this;
- d.onclick = function () {
- window.location = 'http://lermangas.com/sys_admin/editar-capitulo/' + this.obj.getId() + '/';
- }
- }
- var d = document.getElementById('btRevise');
- if (d) {
- d.obj = this;
- d.onclick = function () {
- window.location = 'http://lermangas.com/sys_admin/revisar-capitulo/' + this.obj.getId() + '/';
- }
- }
- };
- this.setChapNext = function (i) {
- this._chapNext = i;
- this._store();
- return this;
- };
- this.getChapNext = function () {
- return this._chapNext;
- };
- this.setChapLast = function (i) {
- this._chapLast = i;
- this._store();
- return this;
- };
- this.getChapLast = function () {
- return this._chapLast;
- };
- this.setChap = function (i) {
- this._chap = i;
- this._store();
- return this;
- };
- this.getChap = function () {
- return this._chap;
- };
- this.setMangaUrl = function (i) {
- this._mangaUrl = i;
- this._store();
- return this;
- };
- this.getMangaUrl = function () {
- return this._mangaUrl;
- };
- this.setTotalPag = function (i) {
- this._totalPag = i;
- this._store();
- return this;
- };
- this.getTotalPag = function () {
- return this._totalPag;
- };
- this.setPageView = function (i) {
- this._pageView = i;
- this._store();
- return this;
- };
- this.getPageView = function () {
- return this._pageView;
- };
- //#endregion
- //#region construtor
- this._load();
- this._store();
- //#endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement