X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=js%2Fkivi.ActionBar.js;h=d732783099dd0eb1b4dc45dd21791af183754ff3;hb=31f989254ce9f2ab881af7aee5d07dd63df0e004;hp=5bffa3c5ffda251be551cc430d760975209d9b13;hpb=9c337bc888d3212a029280d3c37e51a596659c81;p=kivitendo-erp.git diff --git a/js/kivi.ActionBar.js b/js/kivi.ActionBar.js index 5bffa3c5f..d73278309 100644 --- a/js/kivi.ActionBar.js +++ b/js/kivi.ActionBar.js @@ -7,24 +7,31 @@ namespace('kivi', function(k){ disabled: 'layout-actionbar-action-disabled', action: 'layout-actionbar-action', combobox: 'layout-actionbar-combobox', - } + }; k.ActionBarCombobox = function(e) { - this.combobox = e; - this.head = e.childNodes[0]; - this.toggle = this.head.childNodes[1]; - this.list = e.childNodes[0]; + this.combobox = e; + this.head = e.childNodes[0]; + this.topAction = this.head.childNodes[0]; + this.toggle = this.head.childNodes[1]; + this.list = e.childNodes[0]; this.init(); - } + }; k.ActionBarCombobox.prototype = { init: function() { - var obj = this; - $(obj.toggle).on('click', function(event){ + var obj = this; + var toggler = function(event){ $('div.' + CLASSES.combobox + '[id!=' + obj.combobox.id + ']').removeClass(CLASSES.active); $(obj.combobox).toggleClass(CLASSES.active); event.stopPropagation(); - }); + }; + + $(obj.toggle).on('click', toggler); + + var data = $(this.topAction).data('action') || {}; + if (!data.call && !data.submit) + $(this.topAction).on('click', toggler); } }; @@ -41,26 +48,22 @@ namespace('kivi', function(k){ target = 'document'; } - var normalized = $.map(keystring.split('+'), function(val, i) { + var normalized = $.map(String.prototype.split.call(keystring, '+'), function(val, i) { switch (val) { case 'ctrl': case 'alt': return val; case 'enter': return 13; default: if (val.length == 1) { - return val.charChodeAt(0) - } else if (typeof val === 'number') { - return val + return val.charChodeAt(0); } else if (val % 1 === 0) { - return val % 1; + return val; } else { console.log('can not normalize access key token: ' + val); } } }).join('+'); - console.log(normalized) - if (!(target in this.actions)) this.actions[target] = {}; this.actions[target][normalized] = action; @@ -83,9 +86,12 @@ namespace('kivi', function(k){ accesskey += e.which; // special case. HTML elements that make legitimate use of enter will also trigger the enter accesskey. - // so. if accesskey is '13' and the event source is one of these (currently only textarea) ignore it. + // so. if accesskey is '13' and the event source is one of these (currently only textareas & combo boxes) ignore it. // higher level widgets will usually prevent their key events from bubbling if used. - if (accesskey == 13 && e.target.tagName == 'TEXTAREA') return true; + if ( (accesskey == 13) + && ( (e.target.tagName == 'TEXTAREA') + || (e.target.tagName == 'SELECT'))) + return true; if ((target in k.ActionBarAccesskeys.actions) && (accesskey in k.ActionBarAccesskeys.actions[target])) { e.stopPropagation(); @@ -104,8 +110,10 @@ namespace('kivi', function(k){ var data = $(e).data('action'); if (undefined === data) return; - if (data.disabled) { + if (data.disabled && (data.disabled != '0')) { $(e).addClass(CLASSES.disabled); + if (data.disabled != '1') + data.tooltip = data.disabled; } if (data.accesskey) { @@ -121,7 +129,7 @@ namespace('kivi', function(k){ $(e).tooltipster({ content: data.tooltip, theme: 'tooltipster-light' }); } - if (data.call || data.submit) { + if (data.call || data.submit || data.link) { $(e).click(function(event) { var $hidden, key, func, check; if ($(e).hasClass(CLASSES.disabled)) { @@ -131,30 +139,42 @@ namespace('kivi', function(k){ if (data.checks) { for (var i=0; i < data.checks.length; i++) { check = data.checks[i]; - func = kivi.get_function_by_name(check); - if (!func) console.log('Cannot find check function: ' + check); - if (!func()) return; + if (check.constructor !== Array) + check = [ check ]; + func = kivi.get_function_by_name(check[0]); + if (!func) + console.log('Cannot find check function: ' + check); + if (!func.apply(document, check.slice(1))) + return; } } if (data.confirm && !confirm(data.confirm)) return; if (data.call) { func = kivi.get_function_by_name(data.call[0]); - func.apply(document, data.call.slice(1)) + func.apply(document, data.call.slice(1)); } if (data.submit) { var form = data.submit[0]; var params = data.submit[1]; for (key in params) { - $hidden = $('') - $hidden.attr('name', key) - $hidden.attr('value', params[key]) - $(form).append($hidden) + $('[name=' + key + ']').remove(); + $hidden = $(''); + $hidden.attr('name', key); + $hidden.attr('value', params[key]); + $(form).append($hidden); } $(form).submit(); } + if (data.link) { + window.location.href = data.link; + } + if ((data.only_once !== undefined) && (data.only_once !== 0)) { + $(e).addClass(CLASSES.disabled); + $(e).tooltipster({ content: kivi.t8("The action can only be executed once."), theme: 'tooltipster-light' }); + } }); } - } + }; }); $(function(){