function subscriptorList() { ajax('subscriptorList', { page: page, order: order, dir: dir, keyword: keyword, limit: limit }).done(function(result) { if (result.error == 0) { row = ''; $.each(result.data, function(cs, value) { row += ''; row += '' + value.subscriptorid + ''; row += '' + value.sub_source + ''; if(value.sub_disabled==0)row += 'ACTIVO'; else row += 'DESHABILITADO'; row += '' + value.sub_name + ''; row += '' + value.sub_email + ''; row += '' + value.sub_ts + ''; row += ''; }); $('#ctr-table-users').html(row); $('#ctr-totalPages').html(result.totalPages); $('#ctr-totalRows').html(result.totalItems); pagination(result.page,result.totalPages,function(e){ $('#ctr-pagination').html(e); }) } else { alert(result.message); } }) } function _userModal(itemid, callback) { fields1 = ['use_detail','use_name','use_email','use_phone']; //Con espacios fields2 = ['userid','use_disabled']; //Con ceros fields3 = []; //Checkbox fields4 = []; //Select document.querySelectorAll('.ctrl-items').forEach(function(a) { a.remove(); //Borramos todos los items que pudiera haber }) if (itemid == 0) { $.each(fields1, function(cs, value) { $('#' + value).val(''); }); $.each(fields2, function(cs, value) { $('#' + value).val(0); }); $.each(fields3, function(cs, value) { $('#' + value).prop("checked", false); }); $.each(fields4, function(cs, value) { $('#' + value + ' option:selected').prop("selected", false); }); $("#ctr-modal-title").html("Nueva entrada"); } else { $("#ctr-modal-title").html('ENTRADA ID#' + itemid); $.each(fields1, function(cs, value) { $('#' + value).val(item[value]); }); $.each(fields2, function(cs, value) { $('#' + value).val(item[value]); }); $.each(fields3, function(cs, value) { if (item[value] == 1) $('#' + value).prop("checked", true); else $('#' + value).prop("checked", false); }); $.each(fields4, function(cs, value) { if (item[value] != '') $('#' + value + ' option[value=' + item[value] + ']').prop("selected", true); }); //displayType(); } callback() // $('#tab-task li:first-child a').tab('show') //$('#tab-task a[href="#nav-pills-tab-1"]').tab('show') } function ajax(service, postvars) { //postvars.token = token; //Añado el token al postvars para enviarlo al servicio return $.ajax({ type: "POST", headers: {token:token}, url: "api/?service=" + service, dataType: "json", data: postvars, }).done(function(resp) { // console.log(resp); return resp; }).fail(function() { alert("No se puede contactar con el service"); }); }; function contractList() { ajax('contractList', { context: context, page: page, order: order, dir: dir, keyword: keyword, limit: limit }).done(function(result) { if (result.error == 0) { row = ''; $.each(result.data, function(cs, value) { row += ''; row += '' + value.contractid + ''; row += '' + value.date + ''; row += '' + value.use_name + ''; row += '' + value.con_name + ''; row += '' + value.tem_name + ''; row += '' + value.cot_name + ''; if(value.cot_statusid==0)row += '
BORRADOR
'; if(value.cot_statusid==1)row += '
PENDIENTE
'; if(value.cot_statusid==2)row += '
APROBADO
'; if(value.cot_statusid==3)row += '
RECHAZADO
'; if(value.cot_statusid==4)row += '
ABANDONADO
'; row += ''; }); $('#ctr-table-'+context).html(row); $('#ctr-totalPages').html(result.totalPages); $('#ctr-totalRows').html(result.totalItems); pagination(result.page,result.totalPages,function(e){ $('#ctr-pagination').html(e); }) } else { alert(result.message); } }) } function emailList() { ajax('emailList', { page: page, order: order, dir: dir, keyword: keyword, limit: limit }).done(function(result) { if (result.error == 0) { row = ''; $.each(result.data, function(cs, value) { row += ''; row += '' + value.emailid + ''; row += '' + value.ema_subject + ''; row += '' + value.ema_name + ''; row += '' + value.ema_to + ''; if(value.ema_result=='checkbox')row += ''; else row += '' + value.ema_result + ''; row += '' + value.ema_open + ''; row += ''; row += ''; }); $('#ctr-table-users').html(row); $('#ctr-totalPages').html(result.totalPages); $('#ctr-totalRows').html(result.totalItems); pagination(result.page,result.totalPages,function(e){ $('#ctr-pagination').html(e); }) } else { alert(result.message); } }) } function formSend(form, resource, callback) { if(typeof token === 'undefined')token="notoken" var r = $.Deferred(); //para callback var f = $(this); var formData = new FormData(document.getElementById(form)); formData.append("dato", "valor"); $.ajax({ url: "api/?service=" + resource + "&token=" + token, type: "post", dataType: "json", data: formData, cache: false, contentType: false, processData: false }).done(function(res) { callback(res); }); } function isFunction(fname) { return (typeof window[fname] === 'function'); } function itemDelete(context,contextid,callback){ ajax('itemDelete', { item:context, itemid:contextid }).done(function (result) { if (result.error == 0) { callback() } else { alert(result.message); } }) } function itemGet(context, contextid, callback) { ajax('itemGet', { item: context, itemid: contextid }).done(function(result) { if (result.error == 0) { item=result.data callback() } else { alert(result.message); } }) } function itemList(context){ if (isFunction(context + 'List')) { eval(context + 'List' + "()"); }else{ //Si no existe la funcion hacemos algo muy basico ajax('itemList', { context: context, page: page, order: order, dir: dir, keyword: keyword, limit: limit }).done(function(result) { if (result.error == 0) { row = ''; $.each(result.data, function(cs, value) { row += ''; row += '' + value[context+'id'] + ''; }); $('#ctr-table-'+context).html(row); $('#ctr-totalPages').html(result.totalPages); $('#ctr-totalRows').html(result.totalItems); pagination(result.page,result.totalPages,function(e){ $('#ctr-pagination').html(e); }) } else { alert(result.message); } }) } } function itemModal(itemid,callback){ eval(context + 'Modal' + "(itemid,callback,function(e){callback()})"); } function pagination1(current,total,callback){ html = '' callback(html); } function pagination(page,total,callback){ page=parseInt(page) pageP=page-1 pageN=page+1 html = '' callback(html); } function pagination2(page,totalPages,callback){ pageP=page-1 pageN=page+1 html = '' callback(html); } function paramModal(itemid, callback) { fields1 = ['par_key','par_value','par_detail','par_html1']; //Con espacios fields2 = []; //Con ceros fields3 = []; //Checkbox fields4 = []; //Select $('#itemid').val(itemid); $('#par_value').summernote('destroy'); if (itemid == 0) { $.each(fields1, function(cs, value) { $('#' + value).val(''); }); $.each(fields2, function(cs, value) { $('#' + value).val(0); }); $.each(fields3, function(cs, value) { $('#' + value).prop("checked", false); }); $.each(fields4, function(cs, value) { $('#' + value + ' option:selected').prop("selected", false); }); } else { $.each(fields1, function(cs, value) { $('#' + value).val(item[value]); }); $.each(fields2, function(cs, value) { $('#' + value).val(item[value]); }); $.each(fields3, function(cs, value) { if (item[value] == 1) $('#' + value).prop("checked", true); else $('#' + value).prop("checked", false); }); $.each(fields4, function(cs, value) { if (item[value] != '') $('#' + value + ' option[value=' + item[value] + ']').prop("selected", true); }); //displayType(); } $('#par_valuex').summernote({ placeholder: '', tabsize: 2, height: 300 }); callback() // $('#tab-task li:first-child a').tab('show') //$('#tab-task a[href="#nav-pills-tab-1"]').tab('show') } function paramOption(options){ if(!Array.isArray(options))options=[]; $('select[options]').each(function() { var key = $(this).attr("options"); if(!options.includes(key)) options.push(key); }); ajax('optionsList',{keys: options}).done(function(result) { if(result.error == 0){ selectOptions = result.data; //Global para selects dinamicos, ver fileAdd options.forEach(function(value) { //Buscamos los id's cuyas claves estan en el paramkey $('select[options='+value+']').each(function() { selector =$(this); if(!result['data'][value][0])selector.append(''); $.each( result['data'][value], function (cs,value) { selector.append(''); }) }); }) } }) } function paramList() { ajax('paramList', { page: page, order: order, dir: dir, keyword: keyword, limit: limit }).done(function(result) { if (result.error == 0) { row = ''; $.each(result.data, function(cs, value) { row += ''; row += '' + value.paramid + ''; row += '' + value.par_key + ''; row += '' + value.par_detail + ''; row += '' + value.par_value + ''; row += ''; }); $('#ctr-table-users').html(row); $('#ctr-totalPages').html(result.totalPages); $('#ctr-totalRows').html(result.totalItems); pagination(result.page,result.totalPages,function(e){ $('#ctr-pagination').html(e); }) } else { alert(result.message); } }) } function storyList() { ajax('storyList', { page: page, order: order, dir: dir, keyword: keyword, limit: limit }).done(function(result) { if (result.error == 0) { row = ''; $.each(result.data, function(cs, value) { if(value.sto_disabled==1)row += ''; else row += ''; row += '' + value.storyid + ''; row += '' + value.sto_source + ''; if(value.sto_disabled==0)row += 'ACTIVA'; else row += 'DESHABILITADA'; row += '' + value.sto_name + ''; row += '' + value.sto_ts + ''; row += ''; }); $('#ctr-table-users').html(row); $('#ctr-totalPages').html(result.totalPages); $('#ctr-totalRows').html(result.totalItems); pagination(result.page,result.totalPages,function(e){ $('#ctr-pagination').html(e); }) } else { alert(result.message); } }) } function storyModal(itemid, callback) { fields1 = ['sto_name','sto_detail','sto_source']; //Con espacios fields2 = ['storyid','sto_disabled']; //Con ceros fields3 = []; //Checkbox fields4 = []; //Select fields5 = ['sto_fileid']; //Files //Publicaciones $("#ctrl-table-publication").html(''); $.each(fields5, function(cs, value) { $('#' + value).val(''); }); if (itemid == 0) { $.each(fields1, function(cs, value) { $('#' + value).val(''); }); $.each(fields2, function(cs, value) { $('#' + value).val(0); }); $.each(fields3, function(cs, value) { $('#' + value).prop("checked", false); }); $.each(fields4, function(cs, value) { $('#' + value + ' option:selected').prop("selected", false); }); $("#ctr-modal-story-label").html("Nueva historia"); $("#ctr-thumb").attr("src",""); } else { $("#ctr-modal-story-label").html(itemid+'- '+item.sto_name); $("#ctr-thumb").attr("src","api/?service=fileView&id="+item.fil_sha1); //Publicaciones html=''; $.each(item.publications, function(cs, value) { html+='' html+=''+value.pub_name+'' html+='
' html+='' }) html+='
' $("#ctrl-table-publication").html(html); $.each(fields1, function(cs, value) { $('#' + value).val(item[value]); }); $.each(fields2, function(cs, value) { $('#' + value).val(item[value]); }); $.each(fields3, function(cs, value) { if (item[value] == 1) $('#' + value).prop("checked", true); else $('#' + value).prop("checked", false); }); $.each(fields4, function(cs, value) { if (item[value] != '') $('#' + value + ' option[value=' + item[value] + ']').prop("selected", true); }); //displayType(); } callback() // $('#tab-task li:first-child a').tab('show') //$('#tab-task a[href="#nav-pills-tab-1"]').tab('show') } function subscriptorList() { ajax('subscriptorList', { page: page, order: order, dir: dir, keyword: keyword, limit: limit }).done(function(result) { if (result.error == 0) { row = ''; $.each(result.data, function(cs, value) { if(value.sub_disabled==2)row += ''; else row += ''; row += '' + value.subscriptorid + ''; row += '' + value.sub_source + ''; if(value.sub_disabled==0)row += 'ACTIVO'; if(value.sub_disabled==1) row += 'NO CONFIRMADO'; if(value.sub_disabled==2) row += 'DESHABILITADO'; row += '' + value.sub_name + ''; row += '' + value.sub_email + ''; row += '' + value.sub_ts + ''; row += '' + value.sub_last + ''; row += ''; }); $('#ctr-table-users').html(row); $('#ctr-totalPages').html(result.totalPages); $('#ctr-totalRows').html(result.totalItems); pagination(result.page,result.totalPages,function(e){ $('#ctr-pagination').html(e); }) } else { alert(result.message); } }) } function subscriptorModal(itemid, callback) { fields1 = ['sub_name','sub_email','sub_phone','sub_detail','sub_source','sub_country']; //Con espacios fields2 = ['subscriptorid','sub_disabled']; //Con ceros fields3 = []; //Checkbox fields4 = []; //Select fields5 = ['sub_day']; //Radio $('input:radio').prop('checked', false); $('#stories').empty(); if (itemid == 0) { $.each(fields1, function(cs, value) { $('#' + value).val(''); }); $.each(fields2, function(cs, value) { $('#' + value).val(0); }); $.each(fields3, function(cs, value) { $('#' + value).prop("checked", false); }); $.each(fields4, function(cs, value) { $('#' + value + ' option:selected').prop("selected", false); }); $("#ctr-modal-subscriptor-label").html("Nuevo usuario"); } else { $("#ctr-modal-subscriptor-label").html(itemid+'- '+item.sub_name); $.each(fields1, function(cs, value) { $('#' + value).val(item[value]); }); $.each(fields2, function(cs, value) { $('#' + value).val(item[value]); }); $.each(fields3, function(cs, value) { if (item[value] == 1) $('#' + value).prop("checked", true); else $('#' + value).prop("checked", false); }); $.each(fields4, function(cs, value) { if (item[value] != '') $('#' + value + ' option[value=' + item[value] + ']').prop("selected", true); }); //displayType(); $.each(fields5, function(cs, value) { $('input:radio[name='+value+']').filter('[value='+item[value]+']').prop('checked', true); }) $.each(item['stories'], function(cs, value) { $("#stories").append(new Option(value.sto_name, value.storyid)); if(value.sus_subscriptorid==itemid) $("#stories option[value='"+value.storyid+"']").prop('selected',true); }) } callback() // $('#tab-task li:first-child a').tab('show') //$('#tab-task a[href="#nav-pills-tab-1"]').tab('show') //$("#selectList").append(new Option("option text", "value")); } function talert(message){ $("#ctrl-alert").html(message) $("#ctrl-alert").show() } function templateList() { ajax('itemList', { context: context, page: page, order: order, dir: dir, keyword: keyword, limit: limit }).done(function(result) { if (result.error == 0) { row = ''; $.each(result.data, function(cs, value) { row += ''; row += '' + value.templateid + ''; row += '' + value.tem_group + ''; row += '' + value.tem_name + ''; row += ''; }); $('#ctr-table-users').html(row); $('#ctr-totalPages').html(result.totalPages); $('#ctr-totalRows').html(result.totalItems); pagination(result.page,result.totalPages,function(e){ $('#ctr-pagination').html(e); }) } else { alert(result.message); } }) } function userList() { ajax('userList', { page: page, order: order, dir: dir, keyword: keyword, limit: limit }).done(function(result) { if (result.error == 0) { row = ''; $.each(result.data, function(cs, value) { row += ''; row += '' + value.userid + ''; if(value.use_disabled==0)row += 'ACTIVO'; else row += 'DESHABILITADO'; row += '' + value.use_name + ''; row += '' + value.use_email + ''; row += '' + value.use_ts + ''; row += ''; }); $('#ctr-table-users').html(row); $('#ctr-totalPages').html(result.totalPages); $('#ctr-totalRows').html(result.totalItems); pagination(result.page,result.totalPages,function(e){ $('#ctr-pagination').html(e); }) } else { alert(result.message); } }) } function userModal(itemid, callback) { fields1 = ['use_detail','use_name','use_email','use_phone']; //Con espacios fields2 = ['userid','use_disabled']; //Con ceros fields3 = []; //Checkbox fields4 = []; //Select if (itemid == 0) { $.each(fields1, function(cs, value) { $('#' + value).val(''); }); $.each(fields2, function(cs, value) { $('#' + value).val(0); }); $.each(fields3, function(cs, value) { $('#' + value).prop("checked", false); }); $.each(fields4, function(cs, value) { $('#' + value + ' option:selected').prop("selected", false); }); $("#ctr-modal-user-label").html("Nuevo usuario"); } else { $("#ctr-modal-user-label").html(itemid+'- '+item.use_name); $.each(fields1, function(cs, value) { $('#' + value).val(item[value]); }); $.each(fields2, function(cs, value) { $('#' + value).val(item[value]); }); $.each(fields3, function(cs, value) { if (item[value] == 1) $('#' + value).prop("checked", true); else $('#' + value).prop("checked", false); }); $.each(fields4, function(cs, value) { if (item[value] != '') $('#' + value + ' option[value=' + item[value] + ']').prop("selected", true); }); //displayType(); } callback() // $('#tab-task li:first-child a').tab('show') //$('#tab-task a[href="#nav-pills-tab-1"]').tab('show') } function xalert(message,type=1){ if ($(".xalert")[0]){ if(type==0)$(".xalert").html('
'+message+'
'); if(type==1)$(".xalert").html('
'+message+'
'); if(type==2)$(".xalert").html('
'+message+'
'); $(".xalert").show(); }else alert(message) }