X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=js%2Fkivi.Materialize.js;h=3262ffab13f5f4009e897d7ca232a488a7271662;hb=b36fb0f412d2d2b43b8d98d787743cbe1fbf2540;hp=8232d5b9c21de9bb8d226a0cdb934bd97eb38c12;hpb=083f2ba7e28210418de923821d02781996444212;p=kivitendo-erp.git diff --git a/js/kivi.Materialize.js b/js/kivi.Materialize.js index 8232d5b9c..3262ffab1 100644 --- a/js/kivi.Materialize.js +++ b/js/kivi.Materialize.js @@ -3,9 +3,9 @@ namespace("kivi.Materialize", function(ns) { ns.init = function() { ns.reinit_widgets(); - } + }; - ns.build_i18n = function(locale) { + ns.build_i18n = function() { return { months: [ kivi.t8('January'), @@ -63,18 +63,114 @@ namespace("kivi.Materialize", function(ns) { // Accessibility labels labelMonthNext: kivi.t8('Next month'), labelMonthPrev: kivi.t8('Previous month') - } - } + }; + }; + + ns.flash = function(text) { + M.toast({html: text}); + }; ns.reinit_widgets = function() { $('.sidenav').sidenav(); + $('select').formSelect(); $('.datepicker').datepicker({ firstDay: 1, format: kivi.myconfig.dateformat, showClearBtn: true, i18n: ns.build_i18n() }); + $('.modal').modal(); + $('.materialboxed').materialbox(); M.updateTextFields(); - } + }; + + // alternative for kivi.popup_dialog. + // opens materialize modal instead. + // + // differences: M.modal can not load external content, so it needs to be fetched manually and inserted into the DOM. + ns.popup_dialog = function(params) { + params = params || { }; + let id = params.id || 'jqueryui_popup_dialog'; + let $div; + let custom_close = params.dialog ? params.dialog.close : undefined; + let dialog_params = $.extend( + { // kivitendo default parameters. + // unlike classic layout, there is not fixed size, and M.modal is always... modal + onCloseStart: custom_close + }, + // User supplied options: + params.dialog || { }, + { // Options that must not be changed: + // close options already work + }); + + if (params.url) { + $.ajax({ + url: params.url, + data: params.data, + success: function(data) { + params.html = data; + params.url = undefined; + params.data = undefined; + ns.popup_dialog(params); + }, + error: function(x, status, error) { console.error(error); }, + dataType: 'text', + }); + return 1; + } + + if (params.html) { + $div = $('
'); + $div.attr('id', id); + $div.addClass("modal"); + let $modal_content = $('
'); + $modal_content.addClass('modal-content'); + $modal_content.html(params.html); + $div.append($modal_content); + $('body').append($div); + kivi.reinit_widgets(); + dialog_params.onCloseEnd = function() { $div.remove(); }; + + $div.modal(dialog_params); + } else if(params.id) { + $div = $('#' + params.id); + } else { + console.error("insufficient parameters to open dialog"); + return 0; + } + + $div.modal('open'); + + return true; + }; + + /** + * upload file to local storage for later sync + * + * should be used with P.M.file_upload(..., local=>1) + */ + ns.LocalFileUpload = function(options) { + this.storage_token = options.storage_token; // used in localstorage to retrieve the file + this.dom_selector = options.dom_selector; // file inputs to listen on + + this.init(); + }; + + ns.LocalFileUpload.prototype = { + init: function() { + $(this.dom_selector).change(this.handle_file_upload); + }, + handle_file_upload: function() { + + }, + load_files: function() { + return JSON.parse(localStorage.getImte(this.storage_token)); + }, + save_files: function() { + return JSON.parse(localStorage.getImte(this.storage_token)); + }, + + }; });