/** * @package DSTech * * Camada - JavaScript/Geral * Diretório Pai - js/ * Arquivo - mensagens.js * * */ var DSMensagem = (function() { "use strict"; var DSMensagem = {}; /** * Legenda * t : success|info|warning|danger Tipo da mensagen * i : check|info-circle|warning|times-circle Icone da mensagen * b : body Corpo da mensagem * a : ask 1|0 Se é uma pergunta */ DSMensagem.list = function(code) { var list = { 0: { b: 'Codigo não reconhecido! #' + code, t: 'i', tm: false }, 1: { b: 'Logando, por favor aguarde...', t: 's' }, 2: { b: 'Usuário ou Senha inválidos.', t: 'd' }, 3: { b: 'Favor preencher o(s) campo(s) obrigatório(s).', t: 'd', i: 'warning', tm: 0 }, 4: { b: 'OK! Informações armazenadas com sucesso.', t: 's' }, 5: { b: 'Falha inesperada. Tente novamente.', t: 'd', i: 'warning' }, 6: { b: 'Sua mensagem foi enviada com sucesso. Aguarde o nosso retorno.', t: 's' }, 7: { b: 'Falha ao enviar mensagem. Tente novamente.', t: 'd', i: 'warning', tm: 0 }, 9: { b: 'Você esqueceu de confirmar o CAPTCHA.', t: 'd', i: 'warning', tm: 0 }, 10: { b: 'CPF informado inválido.', t: 'd', i: 'warning', tm: 0 }, 11: { b: 'CNPJ informado inválido.', t: 'd', i: 'warning', tm: 0 }, 12: { b: 'CPF ou CNPJ inválido.', t: 'd', i: 'warning', tm: 0 }, 13: { b: 'Pedido realizado com sucesso. Aguarde o retorno de nossa equipe.', t: 's' }, 14: { b: 'ENCONTRADO! Cliente ativo DSTech.', t: 's' }, 15: { b: 'NÃO LOCALIZADO!', t: 'd', i: 'warning', tm: 0 }, }; return list[code] ? list[code] : list[0]; }; DSMensagem.types = function(type) { // c=class, t=icon, t=title return { s: { c: 'success', i: 'check', t: 'Ok!' }, w: { c: 'warning', i: 'exclamation-triangle', t: 'Ops!' }, d: { c: 'danger', i: 'exclamation-circle', t: 'Ops!' }, i: { c: 'info', i: 'question-circle', t: 'Ops!' } }[type]; }; DSMensagem.timer = function(body) { var strLen = body.length; var timer = (strLen / 55) * 2000; return timer; }; DSMensagem.show = function(code, is_modal, action, paramns, custom_message) { if (typeof action == 'undefined') action = 'excluir'; var str_paramns = ''; if (typeof(paramns) == 'object') { $.each(paramns, function(key, value) { str_paramns += ' data-' + key + '="' + value + '" '; }); }; var find = DSMensagem.list(code, custom_message) , type = DSMensagem.types(find.t) , tm = DSMensagem.timer(find.b) , el = $('.new-msg' + (is_modal ? '' : '')); var cm = custom_message ? custom_message : ''; var m = { class: type.c, icon: type.i, title: type.t, body: find.b + cm, focus: find.f, ask: false, timer: true }; if (find.a) m.ask = true; if (find.tm == 0) m.timer = false; var some_html = '
'; some_html += '
'; some_html += '
'; some_html += '

' + m.title + '

'; some_html += '

' + m.body + '

'; some_html += '
'; var html = '
'; html += some_html; if (m.ask) { html += '
'; html += ''; html += ''; html += '
'; } else { html += '
'; html += ''; html += '
'; } html += '
'; html += '
'; el.finish().html('').fadeIn(0).html(html); if (type.c == 'success') { el.delay(tm).fadeOut('fast'); } } DSMensagem.alert = function(code,obj) { var find = DSMensagem.list(code, false), type = DSMensagem.types(find.t), tm = DSMensagem.timer(find.b); var objj = obj; var m = { class: type.c, icon: type.i, title: type.t, body: find.b, ask: false, timer: find.tm }; $("#alertdiv").remove(); if(objj != undefined) { $('.'+objj).append('
× ' + m.body + '
'); } else { $('.form-msg').append('
×' + m.body + '
'); } if (m.timer) { setTimeout(function() { $("#alertdiv").remove(); }, DSMensagem.timer(m.body)); }; } DSMensagem.remove = function(is_modal) { var el = $('.mensagem' + (is_modal ? '' : '')); el.finish().html('').fadeOut(500); }; return { show: DSMensagem.show, alert: DSMensagem.alert, remove: DSMensagem.remove, get: DSMensagem.list, timer: DSMensagem.timer }; }()); function chamaMsg(code, is_modal, action, paramn, custom_message) { console.log('MENSAGEM: ', code, DSMensagem.get(code).b); DSMensagem.show(code, is_modal, action, paramn, custom_message); $('.msg-modal').find('button:first').focus(); } function chamaMsgAlert(code) { DSMensagem.show(code, true, false, false, false); } function show_alert(code, obj) { DSMensagem.alert(code,obj); } function remove_alert() { $('.form-msgModal').html(''); } function removeMsg(is_modal) { DSMensagem.remove(is_modal); }