From dc1daf2c3135f976c8eb9fdd334700f7fea046b7 Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Sat, 25 Nov 2017 00:17:46 -0600 Subject: [PATCH] Agregar plantilla donataria --- source/app/controllers/util.py | 22 +++++++- source/static/js/controller/admin.js | 82 ++++++++++++++++++++++++++++ source/static/js/ui/admin.js | 5 ++ 3 files changed, 107 insertions(+), 2 deletions(-) diff --git a/source/app/controllers/util.py b/source/app/controllers/util.py index 438d082..8f009be 100644 --- a/source/app/controllers/util.py +++ b/source/app/controllers/util.py @@ -1183,6 +1183,15 @@ def upload_file(rfc, opt, file_obj): tmp = file_obj.filename.split('.') name = '{}.{}'.format(rfc.lower(), tmp[-1].lower()) path = _join(PATH_MEDIA, 'logos', name) + elif opt == 'txt_plantilla_factura_32': + tmp = file_obj.filename.split('.') + ext = tmp[-1].lower() + if ext != 'ods': + msg = 'Extensión de archivo incorrecta, selecciona un archivo ODS' + return {'status': 'server', 'name': msg, 'ok': False} + + name = '{}_3.2.ods'.format(rfc.lower()) + path = _join(PATH_MEDIA, 'templates', name) elif opt == 'txt_plantilla_factura_33': tmp = file_obj.filename.split('.') ext = tmp[-1].lower() @@ -1192,14 +1201,23 @@ def upload_file(rfc, opt, file_obj): name = '{}_3.3.ods'.format(rfc.lower()) path = _join(PATH_MEDIA, 'templates', name) - elif opt == 'txt_plantilla_factura_32': + elif opt == 'txt_plantilla_factura_33j': + tmp = file_obj.filename.split('.') + ext = tmp[-1].lower() + if ext != 'json': + msg = 'Extensión de archivo incorrecta, selecciona un archivo JSON' + return {'status': 'server', 'name': msg, 'ok': False} + + name = '{}_3.3.json'.format(rfc.lower()) + path = _join(PATH_MEDIA, 'templates', name) + elif opt == 'txt_plantilla_donataria': tmp = file_obj.filename.split('.') ext = tmp[-1].lower() if ext != 'ods': msg = 'Extensión de archivo incorrecta, selecciona un archivo ODS' return {'status': 'server', 'name': msg, 'ok': False} - name = '{}_3.2.ods'.format(rfc.lower()) + name = '{}_3.3_donataria.ods'.format(rfc.lower()) path = _join(PATH_MEDIA, 'templates', name) if save_file(path, file_obj.file.read()): diff --git a/source/static/js/controller/admin.js b/source/static/js/controller/admin.js index 3a75a1a..e8be6ea 100644 --- a/source/static/js/controller/admin.js +++ b/source/static/js/controller/admin.js @@ -39,6 +39,8 @@ var controllers = { tb_options.attachEvent('onChange', tab_options_change) $$('txt_plantilla_factura_32').attachEvent('onItemClick', txt_plantilla_factura_32_click) $$('txt_plantilla_factura_33').attachEvent('onItemClick', txt_plantilla_factura_33_click) + $$('txt_plantilla_factura_33j').attachEvent('onItemClick', txt_plantilla_factura_33j_click) + $$('txt_plantilla_donataria').attachEvent('onItemClick', txt_plantilla_donataria_click) $$('chk_config_anticipo').attachEvent('onItemClick', chk_config_item_click) $$('chk_config_ine').attachEvent('onItemClick', chk_config_item_click) } @@ -292,6 +294,10 @@ function get_config_values(opt){ return } + if(opt == 'templates'){ + show('txt_plantilla_donataria', $$('chk_ong').getValue()) + } + webix.ajax().get('/config', {'fields': opt}, { error: function(text, data, xhr) { msg = 'Error al consultar' @@ -808,6 +814,82 @@ function txt_plantilla_factura_32_click(e){ } +function txt_plantilla_factura_33j_click(e){ + + var body_elements = [ + {cols: [{width: 100}, {view: 'uploader', id: 'up_template', autosend: true, link: 'lst_files', + value: 'Seleccionar archivo', upload: '/files/txt_plantilla_factura_33j', + width: 200}, {width: 100}]}, + {view: 'list', id: 'lst_files', type: 'uploader', autoheight:true, + borderless: true}, + {}, + {cols: [{}, {view: 'button', label: 'Cerrar', autowidth: true, + click:("$$('win_template').close();")}, {}]} + ] + + var w = webix.ui({ + view: 'window', + id: 'win_template', + modal: true, + position: 'center', + head: 'Subir Plantilla 3.3 JSON', + body: { + view: 'form', + elements: body_elements, + } + }) + + w.show() + + $$('up_template').attachEvent('onUploadComplete', function(response){ + if(response.ok){ + $$('txt_plantilla_factura_33j').setValue(response.name) + msg_sucess('Plantilla cargada correctamente') + }else{ + msg_error(response.name) + } + }) +} + + +function txt_plantilla_donataria_click(e){ + + var body_elements = [ + {cols: [{width: 100}, {view: 'uploader', id: 'up_template', autosend: true, link: 'lst_files', + value: 'Seleccionar archivo', upload: '/files/txt_plantilla_donataria', + width: 200}, {width: 100}]}, + {view: 'list', id: 'lst_files', type: 'uploader', autoheight:true, + borderless: true}, + {}, + {cols: [{}, {view: 'button', label: 'Cerrar', autowidth: true, + click:("$$('win_template').close();")}, {}]} + ] + + var w = webix.ui({ + view: 'window', + id: 'win_template', + modal: true, + position: 'center', + head: 'Subir Plantilla Donataria', + body: { + view: 'form', + elements: body_elements, + } + }) + + w.show() + + $$('up_template').attachEvent('onUploadComplete', function(response){ + if(response.ok){ + $$('txt_plantilla_donataria').setValue(response.name) + msg_sucess('Plantilla cargada correctamente') + }else{ + msg_error(response.name) + } + }) +} + + function tab_options_change(nv, ov){ var cv = { Plantillas: 'templates', diff --git a/source/static/js/ui/admin.js b/source/static/js/ui/admin.js index 3ec846f..ff7491b 100644 --- a/source/static/js/ui/admin.js +++ b/source/static/js/ui/admin.js @@ -427,6 +427,11 @@ var options_templates = [ {view: 'search', id: 'txt_plantilla_factura_33j', name: 'plantilla_factura_33j', label: 'Plantilla Factura v3.3 (JSON): ', labelPosition: 'top', icon: 'file'}, {}]}, + {maxHeight: 20}, + {cols: [{maxWidth: 15}, + {view: 'search', id: 'txt_plantilla_donataria', name: 'plantilla_donataria', + label: 'Plantilla Donataria (solo ONGs): ', labelPosition: 'top', + icon: 'file'}, {}]}, {}]