1 namespace("kivi.Materialize", function(ns) {
8 ns.build_i18n = function() {
58 today: kivi.t8('Today'),
60 clear: kivi.t8('Clear'),
61 cancel: kivi.t8('Cancel'),
63 // Accessibility labels
64 labelMonthNext: kivi.t8('Next month'),
65 labelMonthPrev: kivi.t8('Previous month')
69 ns.flash = function(text) {
70 M.toast({html: text});
73 ns.reinit_widgets = function() {
74 $('.sidenav').sidenav();
75 $('select').formSelect();
76 $('.datepicker').datepicker({
78 format: kivi.myconfig.dateformat,
83 $('.materialboxed').materialbox();
87 // alternative for kivi.popup_dialog.
88 // opens materialize modal instead.
90 // differences: M.modal can not load external content, so it needs to be fetched manually and inserted into the DOM.
91 ns.popup_dialog = function(params) {
92 params = params || { };
93 let id = params.id || 'jqueryui_popup_dialog';
95 let custom_close = params.dialog ? params.dialog.close : undefined;
96 let dialog_params = $.extend(
97 { // kivitendo default parameters.
98 // unlike classic layout, there is not fixed size, and M.modal is always... modal
99 onCloseStart: custom_close
101 // User supplied options:
102 params.dialog || { },
103 { // Options that must not be changed:
104 // close options already work
111 success: function(data) {
113 params.url = undefined;
114 params.data = undefined;
115 ns.popup_dialog(params);
117 error: function(x, status, error) { console.error(error); },
126 $div.addClass("modal");
127 let $modal_content = $('<div>');
128 $modal_content.addClass('modal-content');
129 $modal_content.html(params.html);
130 $div.append($modal_content);
131 $('body').append($div);
132 kivi.reinit_widgets();
133 dialog_params.onCloseEnd = function() { $div.remove(); };
135 $div.modal(dialog_params);
136 } else if(params.id) {
137 $div = $('#' + params.id);
139 console.error("insufficient parameters to open dialog");
149 * upload file to local storage for later sync
151 * should be used with P.M.file_upload(..., local=>1)
153 ns.LocalFileUpload = function(options) {
154 this.storage_token = options.storage_token; // used in localstorage to retrieve the file
155 this.dom_selector = options.dom_selector; // file inputs to listen on
160 ns.LocalFileUpload.prototype = {
162 $(this.dom_selector).change(this.handle_file_upload);
164 handle_file_upload: function() {
167 load_files: function() {
168 return JSON.parse(localStorage.getImte(this.storage_token));
170 save_files: function() {
171 return JSON.parse(localStorage.getImte(this.storage_token));