From 6f30d42d4064e9dff18e3282bd1787dd8d04a47e Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Sat, 11 Nov 2017 11:40:55 -0600 Subject: [PATCH] Cargar plantillas ODS --- source/app/controllers/util.py | 9 ++++++ source/static/js/controller/admin.js | 41 +++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/source/app/controllers/util.py b/source/app/controllers/util.py index 7e16b57..616dfbb 100644 --- a/source/app/controllers/util.py +++ b/source/app/controllers/util.py @@ -1121,6 +1121,15 @@ 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': + 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) if save_file(path, file_obj.file.read()): return {'status': 'server', 'name': file_obj.filename, 'ok': True} diff --git a/source/static/js/controller/admin.js b/source/static/js/controller/admin.js index a89afa3..408e280 100644 --- a/source/static/js/controller/admin.js +++ b/source/static/js/controller/admin.js @@ -29,6 +29,7 @@ var controllers = { //~ Opciones tb_options = $$('tab_options').getTabbar() 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) } } @@ -686,7 +687,7 @@ function txt_plantilla_factura_33_click(e){ id: 'win_template', modal: true, position: 'center', - head: 'Subir Plantilla', + head: 'Subir Plantilla 3.3 ODT', body: { view: 'form', elements: body_elements, @@ -706,6 +707,44 @@ function txt_plantilla_factura_33_click(e){ } +function txt_plantilla_factura_32_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_32', + 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.2 ODT', + body: { + view: 'form', + elements: body_elements, + } + }) + + w.show() + + $$('up_template').attachEvent('onUploadComplete', function(response){ + if(response.ok){ + $$('txt_plantilla_factura_32').setValue(response.name) + msg_sucess('Plantilla cargada correctamente') + }else{ + msg_error(response.name) + } + }) +} + + function tab_options_change(nv, ov){ var cv = { Plantillas: 'templates',