diff --git a/css/ui/views.css b/css/ui/views.css index aa0c4177bd..af43efcd83 100644 --- a/css/ui/views.css +++ b/css/ui/views.css @@ -35,3 +35,15 @@ div.appframe-toolbar { border-bottom: 1px solid #ccc; } +div.appframe-toolbar .label { + margin: 2px 2px; +} + +div.appframe-toolbar input, div.appframe-toolbar select { + font-size: 80%; + margin: 2px 2px; +} +div.appframe-toolbar button { + padding: 3px 7px !important; +} + diff --git a/js/core.min.js b/js/core.min.js index 04ef28c232..fe5fb2a061 100644 --- a/js/core.min.js +++ b/js/core.min.js @@ -57,7 +57,7 @@ $(ele).css('-box-shadow','0px 0px '+spread+'px rgba(0,0,0,0.3);')};(function($){ this.selectedIndex=0;return $(this);} $.fn.set_working=function(){var ele=this.get(0);$(ele).attr('disabled','disabled');if(ele.loading_img){$(ele.loading_img).toggle(true);}else{ele.loading_img=$('').insertAfter(ele);}} -$.fn.done_working=function(){var ele=this.get(0);$(ele).attr('disabled',null);if(ele.loading_img){$(ele.loading_img).toggle(false);};}})(jQuery); +$.fn.done_working=function(){var ele=this.get(0);$(ele).attr('disabled',null);if(ele.loading_img){$(ele.loading_img).toggle(false);};}})(jQuery);wn.to_csv=function(data){var res=[];$.each(data,function(i,row){row=$.map(row,function(col){return typeof(col)==="string"?('"'+col.replace(/"/g,'\"')+'"'):col;});res.push(row.join(","));});return res.join("\n");} /* * lib/js/wn/model.js */ @@ -234,8 +234,9 @@ $(page).bind('show',onshow);if(onshow) $(page).bind('hide',onhide);page.label=label;wn.pages[label]=page;return page;},change_to:function(label){if(this.page&&this.page.label==label){return;} var me=this;if(label.tagName){var page=label;}else{var page=wn.pages[label];} if(!page){console.log('Page not found '+label);return;} -if(this.page){$(this.page).toggle(false);$(this.page).trigger('hide');} -this.page=page;$(this.page).fadeIn();this.page._route=window.location.hash;document.title=this.page.label;$(this.page).trigger('show');scroll(0,0);return this.page;}});wn.views.add_module_btn=function(parent,module){$(parent).append(repl('\ %(module)s Home\ ',{module:module,module_small:module.toLowerCase()}));} @@ -271,8 +272,7 @@ msgprint(r.server_messages);} if(r.exc){r.exc=JSON.parse(r.exc);if(r.exc instanceof Array){$.each(r.exc,function(i,v){if(v)console.log(v);})}else{console.log(r.exc);}};if(r['403']){wn.container.change_to('403');} if(r.docs){LocalDB.sync(r.docs);}} wn.request.call=function(opts){wn.request.prepare(opts);var ajax_args={url:opts.url||wn.request.url,data:opts.args,type:opts.type||'POST',dataType:opts.dataType||'json',success:function(r,xhr){wn.request.cleanup(opts,r);opts.success&&opts.success(r,xhr.responseText);},error:function(xhr,textStatus){wn.request.cleanup(opts,{});show_alert('Unable to complete request: '+textStatus) -opts.error&&opts.error(xhr)}};if(opts.progress_bar){var interval=null;$.extend(ajax_args,{xhr:function(){var xhr=jQuery.ajaxSettings.xhr();interval=setInterval(function(){if(xhr.readyState>2){var total=parseInt(xhr.getResponseHeader('Original-Length')||0)||parseInt(xhr.getResponseHeader('Content-Length'));var completed=parseInt(xhr.responseText.length);var percent=(100.0/total*completed).toFixed(2) -opts.progress_bar.css('width',(percent<10?10:percent)+'%');}},50);wn.last_xhr=xhr;return xhr;},complete:function(){opts.progress_bar.css('width','100%');clearInterval(interval);}})} +opts.error&&opts.error(xhr)}};if(opts.progress_bar){var interval=null;$.extend(ajax_args,{xhr:function(){var xhr=jQuery.ajaxSettings.xhr();interval=setInterval(function(){if(xhr.readyState>2){var total=parseInt(xhr.getResponseHeader('Original-Length')||0)||parseInt(xhr.getResponseHeader('Content-Length'));var completed=parseInt(xhr.responseText.length);var percent=(100.0/total*completed).toFixed(2);opts.progress_bar.css('width',(percent<10?10:percent)+'%');}},50);wn.last_xhr=xhr;return xhr;},complete:function(){opts.progress_bar.css('width','100%');clearInterval(interval);}})} $.ajax(ajax_args);} wn.call=function(opts){var args=$.extend({},opts.args) if(opts.module&&opts.page){args.cmd=opts.module+'.page.'+opts.page+'.'+opts.page+'.'+opts.method}else if(opts.method){args.cmd=opts.method;} diff --git a/js/legacy/utils/msgprint.js b/js/legacy/utils/msgprint.js index f5b0f912bd..089273755a 100644 --- a/js/legacy/utils/msgprint.js +++ b/js/legacy/utils/msgprint.js @@ -58,6 +58,7 @@ function msgprint(msg, title) { msg_dialog.msg_area.append(msg); msg_dialog.show(); + return msg_dialog; } // Floating Message diff --git a/js/lib/downloadify/download.png b/js/lib/downloadify/download.png new file mode 100644 index 0000000000..d2fabbf5a2 Binary files /dev/null and b/js/lib/downloadify/download.png differ diff --git a/js/lib/downloadify/downloadify.min.js b/js/lib/downloadify/downloadify.min.js new file mode 100644 index 0000000000..faf490c087 --- /dev/null +++ b/js/lib/downloadify/downloadify.min.js @@ -0,0 +1,3 @@ +/* Downloadify 0.2 (c) 2009 by Douglas Neiner. Licensed under the MIT license */ +/* See http://github.com/dcneiner/Downloadify for license and more info */ +(function(){Downloadify=window.Downloadify={queue:{},uid:new Date().getTime(),getTextForSave:function(a){var b=Downloadify.queue[a];if(b)return b.getData();return""},getFileNameForSave:function(a){var b=Downloadify.queue[a];if(b)return b.getFilename();return""},getDataTypeForSave:function(a){var b=Downloadify.queue[a];if(b)return b.getDataType();return""},saveComplete:function(a){var b=Downloadify.queue[a];if(b)b.complete();return true},saveCancel:function(a){var b=Downloadify.queue[a];if(b)b.cancel();return true},saveError:function(a){var b=Downloadify.queue[a];if(b)b.error();return true},addToQueue:function(a){Downloadify.queue[a.queue_name]=a},getUID:function(a){if(a.id=="")a.id='downloadify_'+Downloadify.uid++;return a.id}};Downloadify.create=function(a,b){var c=(typeof(a)=="string"?document.getElementById(a):a);return new Downloadify.Container(c,b)};Downloadify.Container=function(d,e){var f=this;f.el=d;f.enabled=true;f.dataCallback=null;f.filenameCallback=null;f.data=null;f.filename=null;var g=function(){f.options=e;if(!f.options.append)f.el.innerHTML="";f.flashContainer=document.createElement('span');f.el.appendChild(f.flashContainer);f.queue_name=Downloadify.getUID(f.flashContainer);if(typeof(f.options.filename)==="function")f.filenameCallback=f.options.filename;else if(f.options.filename)f.filename=f.options.filename;if(typeof(f.options.data)==="function")f.dataCallback=f.options.data;else if(f.options.data)f.data=f.options.data;var a={queue_name:f.queue_name,width:f.options.width,height:f.options.height};var b={allowScriptAccess:'always'};var c={id:f.flashContainer.id,name:f.flashContainer.id};if(f.options.enabled===false)f.enabled=false;if(f.options.transparent===true)b.wmode="transparent";if(f.options.downloadImage)a.downloadImage=f.options.downloadImage;swfobject.embedSWF(f.options.swf,f.flashContainer.id,f.options.width,f.options.height,"10",null,a,b,c);Downloadify.addToQueue(f)};f.enable=function(){var a=document.getElementById(f.flashContainer.id);a.setEnabled(true);f.enabled=true};f.disable=function(){var a=document.getElementById(f.flashContainer.id);a.setEnabled(false);f.enabled=false};f.getData=function(){if(!f.enabled)return"";if(f.dataCallback)return f.dataCallback();else if(f.data)return f.data;else return""};f.getFilename=function(){if(f.filenameCallback)return f.filenameCallback();else if(f.filename)return f.filename;else return""};f.getDataType=function(){if(f.options.dataType)return f.options.dataType;return"string"};f.complete=function(){if(typeof(f.options.onComplete)==="function")f.options.onComplete()};f.cancel=function(){if(typeof(f.options.onCancel)==="function")f.options.onCancel()};f.error=function(){if(typeof(f.options.onError)==="function")f.options.onError()};g()};Downloadify.defaultOptions={swf:'media/downloadify.swf',downloadImage:'images/download.png',width:100,height:30,transparent:true,append:false,dataType:"string"}})();if(typeof(jQuery)!="undefined"){(function($){$.fn.downloadify=function(b){return this.each(function(){b=$.extend({},Downloadify.defaultOptions,b);var a=Downloadify.create(this,b);$(this).data('Downloadify',a)})}})(jQuery)};if(typeof(MooTools)!='undefined'){Element.implement({downloadify:function(a){a=$merge(Downloadify.defaultOptions,a);return this.store('Downloadify',Downloadify.create(this,a))}})}; \ No newline at end of file diff --git a/js/lib/downloadify/downloadify.swf b/js/lib/downloadify/downloadify.swf new file mode 100644 index 0000000000..2a2f01c446 Binary files /dev/null and b/js/lib/downloadify/downloadify.swf differ diff --git a/js/lib/downloadify/swfobject.js b/js/lib/downloadify/swfobject.js new file mode 100644 index 0000000000..8eafe9dd83 --- /dev/null +++ b/js/lib/downloadify/swfobject.js @@ -0,0 +1,4 @@ +/* SWFObject v2.2 + is released under the MIT License +*/ +var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y0){for(var af=0;af0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad'}}aa.outerHTML='"+af+"";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab"+label+" ").appendTo(this.toolbar); + return $(""+label+" ").appendTo(this.toolbar); }, add_select: function(label, options) { this.add_toolbar(); - return $("").add_options(options).appendTo(this.toolbar); }, + add_data: function(label) { + this.add_toolbar(); + return $("") + .appendTo(this.toolbar); + }, add_date: function(label, date) { this.add_toolbar(); - return $("").datepicker({ + return $("").datepicker({ dateFormat: sys_defaults.date_format.replace("yyyy", "yy"), changeYear: true, }).val(dateutil.str_to_user(date) || "").appendTo(this.toolbar); diff --git a/js/wn/views/container.js b/js/wn/views/container.js index 15bb4bd573..c63d49b1c2 100644 --- a/js/wn/views/container.js +++ b/js/wn/views/container.js @@ -25,6 +25,7 @@ wn.views.Container = Class.extend({ change_to: function(label) { if(this.page && this.page.label == label) { // don't trigger double events + //$(this.page).trigger('show'); return; } @@ -41,14 +42,16 @@ wn.views.Container = Class.extend({ } // hide current - if(this.page) { + if(this.page && this.page != page) { $(this.page).toggle(false); $(this.page).trigger('hide'); } // show new - this.page = page; - $(this.page).fadeIn(); + if(!this.page || this.page != page) { + this.page = page; + $(this.page).fadeIn(); + } this.page._route = window.location.hash; document.title = this.page.label; $(this.page).trigger('show'); diff --git a/js/wn/views/grid_report.js b/js/wn/views/grid_report.js index 4b91c23aa1..95c9a1e2e5 100644 --- a/js/wn/views/grid_report.js +++ b/js/wn/views/grid_report.js @@ -99,6 +99,36 @@ wn.views.GridReport = Class.extend({
') .appendTo(this.wrapper); }, + make_grid_wrapper: function() { + $('
\ + Print \ + | \ + Export \ +
').appendTo(this.wrapper); + + this.wrapper.find(".grid-report-export").click(function() { return me.export(); }); + + this.grid_wrapper = $("
") + .appendTo(this.wrapper); + this.id = wn.dom.set_unique_id(this.grid_wrapper.get(0)); + + var me = this; + // bind show event to reset cur_report_grid + // and refresh filters from url + // this must be called after init + // because "wn.container.page" will only be set + // once "load" event is over. + + $(wn.container.page).bind('show', function() { + // reapply filters on show + wn.cur_grid_report = me; + me.apply_filters_from_route(); + me.refresh(); + }); + + this.apply_filters_from_route(); + }, load_filters: function(callback) { // override callback(); @@ -109,13 +139,21 @@ wn.views.GridReport = Class.extend({ v.fieldname = v.fieldname || v.label.replace(/ /g, '_').toLowerCase(); var input = null; if(v.fieldtype=='Select') { - input = me.appframe.add_select(v.label, ["Select "+v.options]); + input = me.appframe.add_select(v.label, [v.default_value]); } else if(v.fieldtype=='Button') { input = me.appframe.add_button(v.label); + if(v.icon) { + $('').prependTo(input); + } } else if(v.fieldtype=='Date') { input = me.appframe.add_date(v.label); } else if(v.fieldtype=='Label') { input = me.appframe.add_label(v.label); + } else if(v.fieldtype=='Data') { + input = me.appframe.add_data(v.label); + } + if(v.cssClass) { + input && input.addClass(v.cssClass); } input && (input.get(0).opts = v); me.filter_inputs[v.fieldname] = input; @@ -131,15 +169,35 @@ wn.views.GridReport = Class.extend({ wn.dom.set_style('.slick-cell { font-size: 12px; }'); }, refresh: function() { - this.prepare_data(); this.render(); }, + apply_filters_from_route: function() { + var hash = window.location.hash; + var me = this; + if(hash.indexOf('/') != -1) { + $.each(hash.split('/').splice(1).join('/').split('&'), function(i, f) { + var f = f.split("="); + me.filter_inputs[f[0]].val(decodeURIComponent(f[1])); + }); + } + }, + set_route: function() { + wn.set_route(wn.container.page.page_name, $.map(this.filter_inputs, function(v) { + var val = v.val(); + var opts = v.get(0).opts; + if(val && val != opts.default_value) + return encodeURIComponent(opts.fieldname) + + '=' + encodeURIComponent(val); + }).join('&')) + }, render: function() { // new slick grid this.waiting.toggle(false); - this.grid_wrapper = $("
") - .appendTo(this.wrapper); - this.id = wn.dom.set_unique_id(this.grid_wrapper.get(0)); + + if(!this.grid_wrapper) this.make_grid_wrapper(); + + this.apply_link_formatters(); + this.prepare_data(); this.grid = new Slick.Grid("#"+this.id, this.dataView, this.columns, this.options); @@ -162,11 +220,58 @@ wn.views.GridReport = Class.extend({ this.dataView.setFilter(this.dataview_filter); this.dataView.endUpdate(); }, + export: function() { + var me = this; + var res = [$.map(this.columns, function(v) { return v.name; })]; + var col_map = $.map(this.columns, function(v) { return v.field; }); + + for (var i=0, len=this.dataView.getLength(); iYou must have Flash 10 installed to download this file.

'); + + Downloadify.create(id ,{ + filename: function(){ + return me.title + '.csv'; + }, + data: function(){ + return wn.to_csv(res); + }, + swf: 'js/lib/downloadify/downloadify.swf', + downloadImage: 'js/lib/downloadify/download.png', + onComplete: function(){ msgobj.hide(); }, + onCancel: function(){ msgobj.hide(); }, + onError: function(){ msgobj.hide(); }, + width: 100, + height: 30, + transparent: true, + append: false + }); + + return false; + }, options: { editable: false, enableColumnReorder: false }, dataview_filter: function(item) { + var filters = wn.cur_grid_report.filter_inputs; + for (i in filters) { + var filter = filters[i].get(0); + if(filter.opts.filter && !filter.opts.filter($(filter).val(), item, filter.opts)) { + return false; + } + } return true; }, date_formatter: function(row, cell, value, columnDef, dataContext) { @@ -174,5 +279,42 @@ wn.views.GridReport = Class.extend({ }, currency_formatter: function(row, cell, value, columnDef, dataContext) { return "
" + fmt_money(value) + "
"; + }, + text_formatter: function(row, cell, value, columnDef, dataContext) { + return "" + value + "
"; + }, + apply_link_formatters: function() { + var me = this; + $.each(this.columns, function(i, col) { + if(col.link_formatter) { + col.formatter = function(row, cell, value, columnDef, dataContext) { + // added link and open button to links + // link_formatter must have + // filter_input, open_btn (true / false), doctype (will be eval'd) + + // make link to add a filter + var link_formatter = wn.cur_grid_report.columns[cell].link_formatter; + var html = repl('\ + %(value)s', { + value: value, + col_name: link_formatter.filter_input, + page_name: wn.container.page.page_name + }) + + // make icon to open form + if(link_formatter.open_btn) { + html += repl(' \ + ', { + value: value, + doctype: eval(link_formatter.doctype) + }); + } + return html; + } + } + }) } }) \ No newline at end of file