-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsaiku.min.js
executable file
·336 lines (336 loc) · 178 KB
/
saiku.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
var SplashScreen=Backbone.View.extend({events:{"click .run_query":"run_query","click .run_dashboard":"run_dashboard"},run_query:function(){Saiku.tabs.add(new Workspace);return!1},run_dashboard:function(){(new DashboardModal).render().open();return!1},template:function(){var a=$("\x3cdiv\x3e \x3cdiv id\x3d'splash'\x3e \x3cnav\x3e \x3cul\x3e \x3cli class\x3d'active'\x3e\x3ca class\x3d'welcome' href\x3d'#'\x3eWelcome\x3c/a\x3e\x3c/li\x3e\x3cli\x3e\x3ca class\x3d'features' href\x3d'#'\x3eFeatures\x3c/a\x3e\x3c/li\x3e\x3cli\x3e\x3ca class\x3d'help' href\x3d'#'\x3eGet Help\x3c/a\x3e\x3c/li\x3e\x3cli class\x3d'enterprisetoggle enterprise'\x3e\x3ca class\x3d'enterprise' href\x3d'#'\x3eEnterprise\x3c/a\x3e\x3c/li\x3e\x3c/ul\x3e \x3ch2\x3eExplore Data. Visualise. Act.\x3c/h2\x3e \x3c/nav\x3e \x3csection class\x3d'tabs'\x3e \x3csection style\x3d'margin-top:50px' id\x3d'welcome'\x3e \x3ch1 class\x3d'saikulogo'\x3eSaiku\x3c/h1\x3e \x3cp\x3eSaiku has the power to change the way you think about your business and make decisions. Saiku provides powerful, web based analytics for everyone in your organisation. Quickly and easily analyse data from any data source to discover what is really happening inside and outside your organisation. \x3c/p\x3e\x3ch2\x3eQuick Links\x3c/h2\x3e \x3cul class\x3d'quicklinks'\x3e \x3cli\x3e\x3ca class\x3d'run_query' href\x3d'#'\x3eCreate a new query\x3c/a\x3e\x3c/li\x3e\x3cli\x3e\x3ca href\x3d'http://saiku.meteorite.bi' target\x3d'_blank'\x3eVisit the website\x3c/a\x3e\x3c/li\x3e\x3cli\x3e\x3ca href\x3d'http://jira.meteorite.bi' target\x3d'_blank'\x3eReport a bug\x3c/a\x3e\x3c/li\x3e\x3c/ul\x3e \x3cp class\x3d'fixed'\x3e\x3ca class\x3d'enterprisetoggle button' href\x3d'http://meteorite.bi' target\x3d'_blank'\x3eGet Enterprise\x3c/a\x3e\x3c/p\x3e\x3ch2\x3eNews\x3c/h2\x3e \x3cdiv id\x3d'news'\x3e\x3c/div\x3e\x3c/section\x3e \x3csection style\x3d'display:none !important;margin-top:50px' id\x3d'features'\x3e \x3ch1 class\x3d'saikulogo'\x3eSaiku\x3c/h1\x3e \x3ch2\x3eFeatures\x3c/h2\x3e \x3ch3\x3eWeb Based Analysis\x3c/h3\x3e \x3cp\x3eSaiku provides the user with an entirely browser based experience. We support all modern browsers, and our user interface is 100% HTML and Javascript. \x3cbr/\x3eSaiku uses REST based communications, this allows the development of custom user interfaces and facilitates the easy integration of the Saiku Server into other applications and services.\x3c/p\x3e\x3ch3\x3eStandards Compliant\x3c/h3\x3e \x3cp\x3eSaiku is based upon the Microsoft MDX query language and will work on most JDBC compliant data sources. We also provide a number of connectors to NOSQL data sources.\x3c/p\x3e\x3ch3\x3eDynamic charting\x3c/h3\x3e \x3cp\x3eSaiku uses a flexible charting engine to provide a wide range of charts and graphs. These are all HTML \x26 Javascript only and don't require flash to be installed on the computer.\x3c/p\x3e\x3ch3\x3ePluggable visualisation engine\x3c/h3\x3e \x3cp\x3eSaiku Enterprise boasts a fully pluggable visualisation engine. This allows developers to build third party extensions and plug them into Saiku Enterprise to extend or replace the existing visualisations.\x3c/p\x3e\x3c/section\x3e \x3csection style\x3d'display:none !important;margin-top:50px' id\x3d'help'\x3e \x3ch1 class\x3d'saikulogo'\x3eSaiku\x3c/h1\x3e \x3ch2\x3eHelp\x3c/h2\x3e \x3cp\x3eWe provide Training, Consulting and Support to ensure you get the most from Saiku and your data. Our services cover all aspects of data analysis including data strategy, design, architecture, deployment and application/software support.\x3c/p\x3e\x3ctable style\x3d'margin-bottom:100px;'\x3e \x3ctr\x3e \x3cth\x3eWiki\x3c/th\x3e \x3cth\x3eForums\x3c/th\x3e \x3cth\x3eSupport\x3c/th\x3e \x3c/tr\x3e\x3ctr\x3e \x3ctd\x3eWhy not try our new \x3ca href\x3d'http://wiki.meteorite.bi' target\x3d'_blank'\x3eWiki site\x3c/a\x3e\x3cbr/\x3efor community documentation.\x3c/td\x3e\x3ctd\x3eWe also have our new \x3ca href\x3d'http://forums.meteorite.bi' target\x3d'_blank'\x3eforums\x3c/a\x3e\x3cbr/\x3e for help and support.\x3c/td\x3e\x3ctd\x3eIf you require more, \x3cbr/\x3e\x3ca href\x3d'mailto:[email protected]'\x3econtact us\x3c/a\x3e for support!.\x3c/td\x3e\x3c/tr\x3e\x3c/table\x3e \x3c/section\x3e \x3csection style\x3d'display:none !important;margin-top:50px' id\x3d'enterprise'\x3e \x3ch1 class\x3d'saikulogo'\x3eSaiku\x3c/h1\x3e \x3ch2\x3eEnterprise\x3c/h2\x3e \x3cp\x3eSaiku Enterprise is our fully supported and tested server and Pentaho plugin system. Buy Saiku Enterprise from as little as $15 per user per month and enjoy the addtional features Saiku Enterprise has to offer\x3c/p\x3e\x3cp\x3eTo find out more visit our \x3ca href\x3d'http://meteorite.bi' target\x3d'_blank'\x3esite\x3c/a\x3e or \x3ca href\x3d'mailto:[email protected]'\x3eschedule a call\x3c/a\x3e with one of us and we can show you why you should choose Saiku Enterprise!\x3c/p\x3e\x3c/section\x3e \x3c/section\x3e \x3c/div\x3e\x3c/div\x3e").html()||
"";return _.template(a)({})},setupPage:function(a){a=$(window).height();$("body").height(a);$(".tabs section").each(function(){$(this).height()});a=$("nav li.active a").attr("class");$("#"+a).fadeIn()},render:function(){$(this.el).html(this.template()).appendTo($("body"));(new License).fetch_license("api/license/",function(a){"error"!==a.status&&$(".enterprisetoggle").css("visibility","hidden")});this.getNews();this.setupPage();$("nav li a").click(function(){var a=$(this).attr("class");$("nav li").removeClass("active");
$(this).parent().addClass("active");$(".tabs section").hide();$("#"+a).fadeIn()});return this},remove:function(){$(this.el).remove()},caption:function(a){return"Home"},getNews:function(){var a=this;$.ajax({type:"GET",url:"http://meteorite.bi/news.json",async:!1,contentType:"application/json",dataType:"jsonp",jsonpCallback:"jsonCallback",success:function(b){for(var c=0;c<b.item.length;c++)$(a.el).find("#news").append("\x3ch4 style\x3d'margin-left: 0.5%;color:#6D6E71;'\x3e"+b.item[c].title+"\x3c/h4\x3e\x3cstrong style\x3d'margin-left: 0.5%;color:#6D6E71;'\x3e"+
b.item[c].date+"\x3c/strong\x3e\x3cbr/\x3e\x3cp style\x3d'color:#6D6E71;'\x3e"+b.item[c].body+"\x3c/p\x3e");console.dir(b.item[0].tid)},error:function(a){console.log(a.message)}})}}),SaikuRendererOptions={mode:null,dataMode:null,htmlObject:null,width:null,height:null},SaikuRenderer=function(a,b){this._options=_.extend(SaikuRendererOptions,b);this._hasProcessed=!1;Backbone&&_.extend(this,Backbone.Events);a&&(this._data=a,this.processData(a,b),this._hasProcessed=!0)};
SaikuRenderer.prototype.render=function(a,b){var c=null;Backbone&&this.trigger("render:start",this);this.hasProcessedData()||this.processData(a,b);c=this._render(a,b);Backbone&&this.trigger("render:end",this);return c};SaikuRenderer.prototype.processData=function(a,b){this.trigger("processData:start",this);this._processData(a,b);this.trigger("processData:end",this)};SaikuRenderer.prototype.hasProcessedData=function(){return this._hasProcessed};SaikuRenderer.prototype._render=function(a,b){};
SaikuRenderer.prototype._processData=function(a,b){};var SaikuTableRenderer=_.extend(SaikuRenderer,{key:"table"});
SaikuTableRenderer.prototype._render=function(a,b){var c=this;a&&(this._data=a);b&&(this._options=_.extend({},SaikuRendererOptions,b));if("undefined"!=typeof this._data&&!(null!==this._data&&null!==this._data.error||null===this._data||this._data.cellset&&0===this._data.cellset.length))if(this._options.htmlObject)c._options.hasOwnProperty("batch")&&$(c._options.htmlObject).parent().parent().unbind("scroll"),_.defer(function(a){c._options.hasOwnProperty("batch")&&!c._options.hasOwnProperty("batchSize")&&
(c._options.batchSize=1E3);a=c.internalRender(c._data,c._options);$(c._options.htmlObject).html(a);_.defer(function(a){if(c._options.hasOwnProperty("batch")&&c._options.hasBatchResult){var b=0,d=!1,l=c._options.hasOwnProperty("batchIntervalSize")?c._options.batchIntervalSize:20;a=c._options.hasOwnProperty("batchIntervalTime")?c._options.batchIntervalTime:20;var k=c._options.batchResult.length,h=_.debounce(function(){if(!d&&0<k&&b<k){d=!0;for(var a="",e=b,h=0;b<k&&h<l;h++,b++)a+=c._options.batchResult[b];
b>e&&$(c._options.htmlObject).append($(a));d=!1}b>=k&&$(c._options.htmlObject).parent().parent().unbind("scroll")},a);$(c._options.htmlObject).parent().parent().scroll(function(){h()})}});return a});else return this.internalRender(this._data,c._options)};SaikuTableRenderer.prototype.clear=function(a,b){this._options.htmlObject&&this._options.hasOwnProperty("batch")&&$(this._options.htmlObject).parent().parent().unbind("scroll")};
SaikuTableRenderer.prototype._processData=function(a,b){this._hasProcessed=!0};function genTotalDataCells(a,b,c,d,e){var f="";e=e[ROWS];for(var g=c.length-1;0<=g;g--)if(a==c[g]){for(var l=e[g][d[g]],k=0;k<l.cells.length;k++)f+='\x3ctd class\x3d"data total"\x3e'+l.cells[k][b].value+"\x3c/td\x3e";d[g]++;d[g]<e[g].length&&(c[g]+=e[g][d[g]].width)}return f}
function genTotalHeaderCells(a,b,c,d,e){for(var f="",g=b;0<=g;g--)if(a==c[g]){var l=e[g][d[g]],k;k=0===g&&1==b?"col":g==b?"col_total_corner":g==b-1&&l.captions?"col_total_first":"col_null";for(var h=0;h<l.cells.length;h++){var p="\x26nbsp;";b==e.length-1&&(l.captions&&(p=e[g][d[g]].captions[h]),0===g&&0===d[g]&&(p=l.captions?p+"\x3cspan class\x3d'i18n'\x3e Grand Total\x3c/span\x3e":"\x3cspan class\x3d'i18n'\x3eGrand Total\x3c/span\x3e"));f+='\x3cth class\x3d"'+k+'"\x3e\x3cdiv\x3e'+p+"\x3c/div\x3e\x3c/th\x3e"}d[g]++;
d[g]<e[g].length&&(c[g]+=e[g][d[g]].width)}return f}function totalIntersectionCells(a,b,c,d,e){for(var f="";0<=b;b--)if(a==c[b]){for(var g=e[b][d[b]],l=0;l<g.cells.length;l++)f+='\x3ctd class\x3d"data total"\x3e\x26nbsp;\x3c/td\x3e';d[b]++;d[b]<e[b].length&&(c[b]+=e[b][d[b]].width)}return f}
function genTotalHeaderRowCells(a,b,c,d){for(var e=d[COLUMNS],f=b[COLUMNS],g=c[COLUMNS],l=e.length-2,k="",h=l;0<=h;h--)if(a==f[h]){for(var p=0;p<e[h][g[h]].cells.length;p++){k+="\x3ctr\x3e";for(b=0;b<=l;b++){var m="\x26nbsp;";c=0===h&&0===b?"row":h==b+1?"row_total_corner":h==b&&e[h][g[h]].captions?"row_total_first":h<b+1?"row_total":"row_null";b==l&&(e[h][g[h]].captions&&(m=e[h][g[h]].captions[p]),0===h&&0===g[h]&&(m=e[h][g[h]].captions?m+"\x3cspan class\x3d'i18n'\x3e Grand Total\x3c/span\x3e":"\x3cspan class\x3d'i18n'\x3eGrand Total\x3c/span\x3e"));
k+='\x3cth class\x3d"'+c+'"\x3e\x3cdiv\x3e'+m+"\x3c/div\x3e\x3c/th\x3e"}c={};b={};for(m=0;m<d[ROWS].length;m++)c[m]=0,b[m]=d[ROWS][m][c[m]].width;for(m=0;m<e[h][g[h]].cells[p].length;m++)k+='\x3ctd class\x3d"data total"\x3e'+e[h][g[h]].cells[p][m].value+"\x3c/td\x3e",k+=totalIntersectionCells(m+1,d[ROWS].length-1,b,c,d[ROWS]);k+="\x3c/tr\x3e"}g[h]++;g[h]<e[h].length&&(f[h]+=e[h][g[h]].width)}return k}var ROWS="ROWS",COLUMNS="COLUMNS";
function nextParentsDiffer(a,b,c){for(;0<b--;)if(a[b][c].properties.uniquename!=a[b][c+1].properties.uniquename)return!0;return!1}function topParentsDiffer(a,b,c){for(;0<c--;)if(a[b][c].properties.uniquename!=a[b-1][c].properties.uniquename)return!0;return!1}
SaikuTableRenderer.prototype.internalRender=function(a,b){var c="",d="",e=a.cellset,f=e?e:[],g,l,k,h,p,m=0,z=[],q=null,t=!1,w=[];b&&(q=b.hasOwnProperty("batchSize")?b.batchSize:null);var s={};s[COLUMNS]=a.rowTotalsLists;s[ROWS]=a.colTotalsLists;for(var v={},A={},n=[ROWS,COLUMNS],x,d=0;d<n.length;d++)v[n[d]]=[],A[n[d]]=[];if(s[COLUMNS])for(d=0;d<s[COLUMNS].length;d++)A[COLUMNS][d]=0,v[COLUMNS][d]=s[COLUMNS][d][A[COLUMNS][d]].width;for(var n=0,F=f.length;n<F;n++){var y=n-a.topOffset;g=1;var D=h=l=!1;
if(s[ROWS])for(d=0;d<s[ROWS].length;d++)A[ROWS][d]=0,v[ROWS][d]=s[ROWS][d][A[ROWS][d]].width;for(var d="\x3ctr\x3e",u=0,G=f[n].length;u<G;u++){var E=u-a.leftOffset,r=e[n][u];if("COLUMN_HEADER"===r.type&&"null"===r.value&&(null===k||u<k))d+='\x3cth class\x3d"all_null"\x3e\x3cdiv\x3e\x26nbsp;\x3c/div\x3e\x3c/th\x3e';else if("COLUMN_HEADER"===r.type){null===k&&(k=u);f[n].length==u+1?h=!0:p=e[n][u+1];if(h)"null"==r.value?d+='\x3cth class\x3d"col_null"\x3e\x3cdiv\x3e\x26nbsp;\x3c/div\x3e\x3c/th\x3e':(s[ROWS]&&
(g=s[ROWS][n+1][A[ROWS][n+1]].span),d+='\x3cth class\x3d"col" style\x3d"text-align: center;" colspan\x3d"'+g+'" title\x3d"'+r.value+'"\x3e\x3cdiv rel\x3d"'+n+":"+u+'"\x3e'+r.value+"\x3c/div\x3e\x3c/th\x3e");else{var E=1<u&&1<n&&!l&&u>k?e[n-1][u+1].value!=e[n-1][u].value||e[n-1][u+1].properties.uniquename!=e[n-1][u].properties.uniquename:!1,B=999<g?!0:!1;r.value!=p.value||nextParentsDiffer(e,n,u)||l||E||B?("null"==r.value?d+='\x3cth class\x3d"col_null" colspan\x3d"'+g+'"\x3e\x3cdiv\x3e\x26nbsp;\x3c/div\x3e\x3c/th\x3e':
(s[ROWS]&&(g=s[ROWS][n+1][A[ROWS][n+1]].span),d+='\x3cth class\x3d"col" style\x3d"text-align: center;" colspan\x3d"'+(0===g?1:g)+'" title\x3d"'+r.value+'"\x3e\x3cdiv rel\x3d"'+n+":"+u+'"\x3e'+r.value+"\x3c/div\x3e\x3c/th\x3e"),g=1):g++}s[ROWS]&&(d+=genTotalHeaderCells(u-a.leftOffset+1,n+1,v[ROWS],A[ROWS],s[ROWS]))}else if("ROW_HEADER"===r.type&&"null"===r.value)d+='\x3cth class\x3d"row_null"\x3e\x3cdiv\x3e\x26nbsp;\x3c/div\x3e\x3c/th\x3e';else if("ROW_HEADER"===r.type){m==u?l=!0:p=e[n][u+1];var E=
e[n-1],B=!D&&!l&&(0===u||!topParentsDiffer(e,n,u))&&r.value===E[u].value,D=!B,E=B?"\x3cdiv\x3e\x26nbsp;\x3c/div\x3e":'\x3cdiv rel\x3d"'+n+":"+u+'"\x3e'+r.value+"\x3c/div\x3e",B=B?"row_null":"row",C=0;if(!l&&("undefined"==typeof p||"null"===p.value)){C=1;x=r.properties.dimension;r=r.properties.level;r=x in z?z[x].length-z[x].indexOf(r):1;for(x=u+1;C<r&&x<=m+1&&"null"!==e[n][x];x++)C=x-u;u=u+C-1}d+='\x3cth class\x3d"'+B+'" '+(0<C?' colspan\x3d"'+C+'"':"")+"\x3e"+E+"\x3c/th\x3e"}else if("ROW_HEADER_HEADER"===
r.type)d+='\x3cth class\x3d"row_header"\x3e\x3cdiv\x3e'+r.value+"\x3c/div\x3e\x3c/th\x3e",l=!0,m=u,r.properties.hasOwnProperty("dimension")&&(x=r.properties.dimension,x in z||(z[x]=[]),z[x].push(r.properties.level));else if("DATA_CELL"===r.type){t=!0;B="";x=r.value;C="";if(r.properties.hasOwnProperty("image")){x=r.properties.hasOwnProperty("image_height")?" height\x3d'"+r.properties.image_height+"'":"";var H=r.properties.hasOwnProperty("image_width")?" width\x3d'"+r.properties.image_width+"'":"";
x="\x3cimg "+x+" "+H+" style\x3d'padding-left: 5px' src\x3d'"+r.properties.image+"' border\x3d'0'\x3e"}r.properties.hasOwnProperty("style")&&(B=" style\x3d'background-color: "+r.properties.style+"' ");r.properties.hasOwnProperty("link")&&(x="\x3ca target\x3d'__blank' href\x3d'"+r.properties.link+"'\x3e"+x+"\x3c/a\x3e");r.properties.hasOwnProperty("arrow")&&(C="\x3cimg height\x3d'10' width\x3d'10' style\x3d'padding-left: 5px' src\x3d'./images/arrow-"+r.properties.arrow+".gif' border\x3d'0'\x3e");d+=
'\x3ctd class\x3d"data" '+B+'\x3e\x3cdiv alt\x3d"'+r.properties.raw+'" rel\x3d"'+r.properties.position+'"\x3e'+x+C+"\x3c/div\x3e\x3c/td\x3e";s[ROWS]&&(d+=genTotalDataCells(E+1,y,v[ROWS],A[ROWS],s))}}d+="\x3c/tr\x3e";g="";s[COLUMNS]&&0<=y&&(g+=genTotalHeaderRowCells(y+1,v,A,s));t&&q?n<=q?(c+=d,0<g.length&&(c+=g)):(w.push(d),0<g.length&&w.push(g)):(c+=d,0<g.length&&(c+=g))}b&&(b.batchResult=w,b.hasBatchResult=0<w.length);return"\x3ctable\x3e"+c+"\x3c/table\x3e"};
var SaikuChartRenderer=function(a,b){this.rawdata=a;this.cccOptions={};this.data=null;this.hasRendered=this.hasProcessed=!1;if(!b&&!b.hasOwnProperty("htmlObject"))throw"You need to supply a html object in the options for the SaikuChartRenderer!";this.el=$(b.htmlObject);this.id=_.uniqueId("chart_");$(this.el).html('\x3cdiv class\x3d"canvas_wrapper" style\x3d"display:none;"\x3e\x3cdiv id\x3d"canvas_'+this.id+'"\x3e\x3c/div\x3e\x3c/div\x3e');if(this.zoom=b.zoom){var c=this;$("\x3cspan style\x3d'float:left;' class\x3d'zoombuttons'\x3e\x3ca href\x3d'#' class\x3d'button rerender i18n' title\x3d'Re-render chart'\x3e\x3c/a\x3e\x3ca href\x3d'#' class\x3d'button zoomout i18n' style\x3d'display:none;' title\x3d'Zoom back out'\x3e\x3c/a\x3e\x3c/span\x3e").prependTo($(this.el).find(".canvas_wrapper"));
$(this.el).find(".zoomout").on("click",function(a){a.preventDefault();c.zoomout()});$(this.el).find(".zoomin").on("click",function(a){a.preventDefault();c.zoomin()});$(this.el).find(".rerender").on("click",function(a){a.preventDefault();$(c.el).find(".zoomout").hide();c.switch_chart(c.type)})}b.chartDefinition&&(this.chartDefinition=b.chartDefinition);this.cccOptions.canvas="canvas_"+this.id;this.adjustSizeTo=this.data=null;this.adjustSizeTo=b.adjustSizeTo?b.adjustSizeTo:b.htmlObject;this.rawdata&&
("sunburst"==this.type?this.process_data_tree({data:this.rawdata}):this.process_data_tree({data:this.rawdata},!0,!0));b.mode?this.switch_chart(b.mode):this.switch_chart("stackedBar");this.adjust()};SaikuChartRenderer.prototype.adjust=function(){var a=this,b=_.debounce(function(){a.hasRendered&&$(a.el).is(":visible")&&a.switch_chart(a.type)},300);$(window).resize(function(){$(a.el).find(".canvas_wrapper").fadeOut(150);b()})};
SaikuChartRenderer.prototype.zoomin=function(){$(this.el).find(".canvas_wrapper").hide();var a=this.chart.root,b=a.data;b.datums(null,{selected:!1}).each(function(a){a.setVisible(!1)});b.clearSelected();a.render(!0,!0,!1);this.render_chart_element()};
SaikuChartRenderer.prototype.zoomout=function(){var a=this.chart.root,b=a.data,c=a.keptVisibleDatumSet;null===c||0===c.length?$(this.el).find(".zoomout").hide():1==c.length?($(this.el).find(".zoomout").hide(),a.keptVisibleDatumSet=[],pvc.data.Data.setVisible(b.datums(null,{visible:!1}),!0)):1<c.length&&(a.keptVisibleDatumSet.splice(c.length-1,1),b=b.datums(null,{visible:!1}).array(),_.intersection(a.keptVisibleDatumSet[c.length-1],b).forEach(function(a){a.setVisible(!0)}));a.render(!0,!0,!1)};
SaikuChartRenderer.prototype.render=function(){_.delay(this.render_chart_element,0,this)};
SaikuChartRenderer.prototype.switch_chart=function(a,b){null==b&&void 0==b||null==b.chartDefinition&&void 0==b.chartDefinition||(this.chartDefinition=b.chartDefinition);var c={stackedBar:{type:"BarChart",stacked:!0},bar:{type:"BarChart"},multiplebar:{type:"BarChart",multiChartIndexes:[1],dataMeasuresInColumns:!0,orientation:"vertical",smallTitlePosition:"top",multiChartMax:30,multiChartColumnsMax:Math.floor(this.cccOptions.width/200),smallWidth:200,smallHeight:150},line:{type:"LineChart"},pie:{type:"PieChart",
multiChartIndexes:[0]},heatgrid:{type:"HeatGridChart"},stackedBar100:{type:"NormalizedBarChart"},area:{type:"StackedAreaChart"},dot:{type:"DotChart"},waterfall:{type:"WaterfallChart"},treemap:{type:"TreemapChart"},sunburst:{type:"SunburstChart"}};null!==a&&""!==a&&("sunburst"==a?($(this.el).find(".zoombuttons a").hide(),this.type=a,this.sunburst(),this.hasProcessed&&this.render()):c.hasOwnProperty(a)?($(this.el).find(".zoombuttons a").hide(),this.type=a,this.cccOptions=this.getQuickOptions(c[a]),
this.define_chart(),this.hasProcessed&&this.render()):alert("Do not support chart type: '"+a+"'"))};
SaikuChartRenderer.prototype.sunburst=function(){this.type="sunburst";var a=this.process_data_tree({data:this.rawdata}),b=this.getQuickOptions({}),c=pv.dom(a).nodes();pv.colors(b.colors).by(function(a){return a.parentNode&&a.parentNode.nodeName});a=(new pv.Panel).width(b.width).height(b.height).canvas(b.canvas);c=a.add(pv.Layout.Partition.Fill).nodes(c).size(function(a){return a.nodeValue}).order("descending").orient("radial");c.node.add(pv.Wedge).fillStyle(pv.colors(b.colors).by(function(a){return a.parentNode&&
a.parentNode.nodeName})).visible(function(a){return 0<a.depth}).strokeStyle("#000").lineWidth(.5).text(function(a){var b="";"undefined"!=typeof a.nodeValue&&(b=" : "+a.nodeValue);return a.nodeName+b}).cursor("pointer").events("all").event("mousemove",pv.Behavior.tipsy({delayIn:200,delayOut:80,offset:2,html:!0,gravity:"nw",fade:!1,followMouse:!0,corners:!0,arrow:!1,opacity:1}));c.label.add(pv.Label).visible(function(a){return 6<=a.angle*a.outerRadius});this.chart=a};
SaikuChartRenderer.prototype.cccOptionsDefault={Base:{animate:!1,selectable:!0,valuesVisible:!1,legend:!0,legendPosition:"top",legendAlign:"right",compatVersion:2,legendSizeMax:"30%",axisSizeMax:"40%",plotFrameVisible:!1,orthoAxisMinorTicks:!1,colors:"#1f77b4 #aec7e8 #ff7f0e #ffbb78 #2ca02c #98df8a #d62728 #ff9896 #9467bd #c5b0d5 #8c564b #c49c94 #e377c2 #f7b6d2 #7f7f7f #c7c7c7 #bcbd22 #dbdb8d #17becf #9edae5".split(" ")},HeatGridChart:{orientation:"horizontal",useShapes:!0,shape:"circle",nullShape:"cross",
colorNormByCategory:!1,sizeRole:"value",legendPosition:"right",legend:!0,hoverable:!0,axisComposite:!0,colors:["red","yellow","lightgreen","darkgreen"],yAxisSize:"20%"},WaterfallChart:{orientation:"horizontal"},PieChart:{multiChartColumnsMax:3,multiChartMax:30,smallTitleFont:"bold 14px sans-serif",valuesVisible:!0,valuesMask:"{value.percent}",explodedSliceRadius:"10%",extensionPoints:{slice_innerRadiusEx:"40%",slice_offsetRadius:function(a){return a.isSelected()?"10%":0}},clickable:!0},LineChart:{extensionPoints:{area_interpolate:"monotone",
line_interpolate:"monotone"}},StackedAreaChart:{extensionPoints:{area_interpolate:"monotone",line_interpolate:"monotone"}},TreemapChart:{legendPosition:"right",multiChartIndexes:0,extensionPoints:{leaf_lineWidth:2},layoutMode:"slice-and-dice",valuesVisible:!0},SunburstChart:{valuesVisible:!1,hoverable:!1,selectable:!0,clickable:!1,multiChartIndexes:[0],multiChartMax:30}};
SaikuChartRenderer.prototype.getQuickOptions=function(a){var b=a&&a.type||"BarChart";a=_.extend({type:b,canvas:"canvas_"+this.id},this.cccOptionsDefault.Base,this.cccOptionsDefault[b],a);if(this.adjustSizeTo){var c=$(this.adjustSizeTo);c&&0<c.length&&(b=c.width()-40,c=c.height()-40,0<b&&(a.width=b),0<c&&(a.height=c))}null!==this.data&&5<this.data.resultset.length&&"HeatGridChart"!==a.type&&"horizontal"!==a.orientation&&(a.extensionPoints=_.extend(Object.create(a.extensionPoints||{}),{xAxisLabel_textAngle:-Math.PI/
2,xAxisLabel_textAlign:"right",xAxisLabel_textBaseline:"middle"}));a.colors=["#AE1717","#AE5B17","#0E6868"];return a};
SaikuChartRenderer.prototype.define_chart=function(a){this.hasProcessed||this.process_data_tree({data:this.rawdata},!0,!0);var b=this,c=this.adjustSizeTo?$(this.adjustSizeTo):$(this.el),d=null!==this.data&&80>this.data.height&&80>this.data.width,e=null!==this.data&&300>this.data.height&&300>this.data.width,e=!d&&!e,f=c.width()-40,g=c.height()-40,c=_.clone(this.cccOptions);a&&a.width&&(f=a.width);a&&a.height&&(g=a.height);0<f&&(c.width=f);0<g&&(c.height=g);e&&(c.hasOwnProperty("extensionPoints")&&
c.extensionPoints.hasOwnProperty("line_interpolate")&&delete c.extensionPoints.line_interpolate,c.hasOwnProperty("extensionPoints")&&c.extensionPoints.hasOwnProperty("area_interpolate")&&delete c.extensionPoints.area_interpolate);a={legend:{scenes:{item:{execute:function(){var a=this.chart();a.hasOwnProperty("keptVisibleDatumSet")||(a.keptVisibleDatumSet=[]);a=0<a.keptVisibleDatumSet.length?a.keptVisibleDatumSet[a.keptVisibleDatumSet.length-1]:[];0<a.length?_.intersection(this.datums().array(),a).forEach(function(a){a.toggleVisible()}):
pvc.data.Data.toggleVisible(this.datums());this.chart().render(!0,!0,!1)}}}},userSelectionAction:function(a){if(0===a.length)return[];var c=b.chart.root,d=c.data,e=this.chart;e.hasOwnProperty("keptVisibleDatumSet")||(e.keptVisibleDatumSet=[]);if(1500<d.datums().count())pvc.data.Data.setSelected(a,!0);else if(d.datums(null,{visible:!0}).count()==d.datums().count()){$(b.el).find(".zoomout, .rerender").show();var g=d.datums().array();_.each(_.difference(g,a),function(a){a.setVisible(!1)});e.keptVisibleDatumSet=
[];e.keptVisibleDatumSet.push(a)}else{g=0<e.keptVisibleDatumSet.length?e.keptVisibleDatumSet[e.keptVisibleDatumSet.length-1]:[];d=d.datums(null,{visible:!0}).array();d.length<g.length&&e.keptVisibleDatumSet.push(d);var f=[];_.each(_.difference(d,a),function(a){a.setVisible(!1)});_.each(_.intersection(d,a),function(a){f.push(a)});0<f.length&&e.keptVisibleDatumSet.push(f)}c.render(!0,!0,!1);return[]}};c=_.extend(c,{hoverable:d,animate:!1},this.chartDefinition);b.zoom&&(d=c.legend,c=_.extend(c,a),!1===
d&&(c.legend=!1));"TreemapChart"==c.type&&(c.legend.scenes.item.labelText=function(){var a="",b=this.group;if(b)switch(b=b.depth,b){case 0:return"";case 1:break;case 2:a=" └ ";break;default:a=Array(2*(b-2)+1).join(" ")+" └ "}return a+this.base()});this.chart=new pvc[c.type](c);this.chart.setData(this.data,{crosstabMode:!0,seriesInRows:!1})};
SaikuChartRenderer.prototype.render_chart_element=function(a){a=a||this;var b=null!==a.data&&300>a.data.height&&300>a.data.width,b=!(null!==a.data&&80>a.data.height&&80>a.data.width)&&!b,c=!1;a.chart.options&&a.chart.options.animate&&(c=!0);c&&!$(a.el).find(".canvas_wrapper").is(":visible")||$(a.el).find(".canvas_wrapper").hide();try{c&&$(a.el).find(".canvas_wrapper").show(),a.chart.render(),a.hasRendered=!0}catch(d){$("#canvas_"+a.id).text("Could not render chart"+d)}if(a.chart.options&&a.chart.options.animate)return!1;
isIE||b?$(a.el).find(".canvas_wrapper").show():$(a.el).find(".canvas_wrapper").fadeIn(400);return!1};
SaikuChartRenderer.prototype.process_data_tree=function(a,b,c){var d={};b&&(d.resultset=[],d.metadata=[],d.height=0,d.width=0);var e=d;if("undefined"!=typeof a&&"undefined"!=typeof a.data&&!(null!==a.data&&null!==a.data.error||null===a.data||a.data.cellset&&0===a.data.cellset.length)){var f=a.data.cellset;if(f&&0<f.length){var g=0,l=0,k=!1,h,p,m,z=function(a,b){return a+b};h=0;for(p=f.length;0===l&&h<p;h++)for(var q=0,t=f[h].length;q<t;q++){if(!k)for(;"COLUMN_HEADER"==f[h][q].type&&"null"==f[h][q].value;)h++;
k=!0;if("ROW_HEADER_HEADER"==f[h][q].type){for(;"ROW_HEADER_HEADER"==f[h][q].type;)b&&d.metadata.push({colIndex:q,colType:"String",colName:f[h][q].value}),q++;g=q-1}if("COLUMN_HEADER"==f[h][q].type){l=0;for(m=[];l<=h;)"null"!==f[l][q].value&&m.push(f[l][q].value),l++;b&&d.metadata.push({colIndex:q,colType:"Numeric",colName:m.join(" ~ ")});l=h+1}}k=[];for(m=0;m<=g;m++)k.push(null);h=l;for(p=f.length;h<p;h++)if(""!==f[h][0].value){t=[];m=[];q=l=null;for(m=0;m<=g;m++){if(f[h]&&"null"===f[h][m].value){for(var e=
d,w=0;w<g&&"null"===f[h][w].value;w++)e=e[k[w]];w>m&&(m=w)}if(f[h]&&"null"!==f[h][m].value){if(0===m)for(w=0;w<=g;w++)k[w]=null;"number"==typeof e&&(l[q]={},e=l[q]);q=f[h][m].value;k[m]=q;e.hasOwnProperty(q)||(e[q]={});l=e;e=e[q]}}m=_.clone(k);e=g+1;for(w=f[h].length;e<w;e++){var s=f[h][e],v=s.value||0,A=0!==v,n=s.properties.raw;n&&"null"!==n?v=parseFloat(n):"number"!==typeof s.value&&parseFloat(s.value.replace(/[^a-zA-Z 0-9.]+/g,""))&&(v=parseFloat(s.value.replace(/[^a-zA-Z 0-9.]+/g,"")),A=!1);0<
v&&A&&(v=s.value&&0<=s.value.indexOf("%")?100*v:v);t.push(v);m.push({f:s.value,v:v})}b&&d.resultset.push(m);e=_.reduce(t,z,0);q=null===q?"null":q;l[q]=e;e=d}c&&(this.rawdata=a.data,this.data=d,this.hasProcessed=!0,this.data.height=this.data.resultset.length);return d}$(this.el).find(".canvas_wrapper").text("No results").show()}};
var Modal=Backbone.View.extend({tagName:"div",className:"dialog",type:"modal",message:"Put content here",options:{autoOpen:!1,modal:!0,title:"Modal dialog",resizable:!1,draggable:!0},events:{"click a":"call"},buttons:[{text:"OK",method:"close"}],template:function(){return _.template("\x3cdiv class\x3d'dialog_icon'\x3e\x3c/div\x3e\x3cdiv class\x3d'dialog_body'\x3e\x3c%\x3d message %\x3e\x3c/div\x3e\x3cdiv class\x3d'dialog_footer'\x3e\x3c% _.each(buttons, function(button) { %\x3e\x3ca class\x3d'form_button i18n' href\x3d'#\x3c%\x3d button.method %\x3e'\x3e\x26nbsp;\x3c%\x3d button.text %\x3e\x26nbsp;\x3c/a\x3e\x3c% }); %\x3e\x3cdiv class\x3d'dialog_response'\x3e\x3c/div\x3e\x3c/div\x3e")(this)},
initialize:function(a){_.extend(this,a);_.bindAll(this,"call");_.extend(this,Backbone.Events)},render:function(){$(this.el).html(this.template()).addClass("dialog_"+this.type).dialog(this.options);var a=$(".ui-dialog-title");a.html(this.options.title);a.addClass("i18n");Saiku.i18n.translate();return this},call:function(a){var b=a.target.hash.replace("#","");if(!$(a.target).hasClass("disabled_toolbar")&&this[b])this[b](a);return!1},open:function(){$(this.el).dialog("open");this.trigger("open",{modal:this});
return this},close:function(){$(this.el).dialog("destroy").remove();$(this.el).remove();return!1}}),Tab=Backbone.View.extend({tagName:"li",events:{"click a":"select","mousedown a":"remove","click .close_tab":"remove"},template:function(){return _.template("\x3ca class\x3d'saikutab' href\x3d'#\x3c%\x3d id %\x3e'\x3e\x3c%\x3d caption %\x3e\x3c/a\x3e\x3cspan class\x3d'close_tab sprite'\x3eClose tab\x3c/span\x3e")({id:this.id,caption:this.caption})},initialize:function(a){_.extend(this,Backbone.Events);
_.extend(this,a);this.content.tab=this;this.caption=this.content.caption();this.id=_.uniqueId("tab_");this.close=a.close},render:function(){var a=this;this.content.render();$(this.el).html(this.template());!1===this.close&&($(this.el).find(".close_tab").hide(),$(this.el).css("padding-right","10px"));var b={"new":{name:"New",i18n:!0},duplicate:{name:"Duplicate",i18n:!0},closeothers:{name:"Close Others",i18n:!0},closethis:{name:"Close This",i18n:!0}};$.each(b,function(a,b){recursive_menu_translate(b,
Saiku.i18n.po_file)});$.contextMenu("destroy",".saikutab");$.contextMenu({selector:".saikutab",callback:function(b,d){var e=d.$trigger.attr("href").replace("#",""),e=Saiku.tabs.find(e);"closethis"==b?(e.remove(),a.select()):"closeothers"==b?(e.select(),Saiku.tabs.close_others(e)):"duplicate"==b?Saiku.tabs.duplicate(e):"new"==b&&Saiku.tabs.new_tab()},items:b});return this},set_caption:function(a){$(this.el).find(".saikutab").html(a)},destroy:function(){this.content&&this.content.query&&this.content.query.destroy()},
select:function(){this.parent.select(this);$(this.el).addClass("selected");this.trigger("tab:select");return!1},remove:function(a){if(!a||2===a.which||$(a.target).hasClass("close_tab")){this.parent.remove(this);try{$(this.el).remove(),this.destroy()}catch(b){Log.log(JSON.stringify({Message:"Tab could not be removed",Tab:JSON.stringify(this)}))}}return!1}}),TabPager=Backbone.View.extend({className:"pager_contents",events:{"click a":"select"},initialize:function(a){this.tabset=a.tabset;$(this.el).hide().appendTo("body");
$(window).click(function(a){$(a.target).hasClass("pager_contents")||$(".pager_contents").hide()})},render:function(){for(var a="",b=0,c=this.tabset._tabs.length;b<c;b++)a+="\x3ca href\x3d'#"+b+"'\x3e"+this.tabset._tabs[b].caption+"\x3c/a\x3e\x3cbr /\x3e";$(this.el).html(a);$(this.el).find(".i18n").i18n(Saiku.i18n.po_file)},select:function(a){var b=$(a.target).attr("href").replace("#","");this.tabset._tabs[b].select();$(this.el).hide();a.preventDefault();return!1}}),TabSet=Backbone.View.extend({className:"tabs",
queryCount:0,events:{"click a.pager":"togglePager","click a.new":"new_tab"},_tabs:[],render:function(){$(this.el).html('\x3ca href\x3d"#pager" class\x3d"pager sprite"\x3e\x3c/a\x3e\x3cul\x3e\x3cli class\x3d"newtab"\x3e\x3ca class\x3d"new"\x3e+\x26nbsp;\x26nbsp;\x3c/a\x3e\x3c/li\x3e\x3c/ul\x3e').appendTo($("#header"));this.content=$('\x3cdiv id\x3d"tab_panel"\x3e').appendTo($("body"));this.pager=new TabPager({tabset:this});return this},add:function(a,b){this.queryCount++;var c=new Tab({content:a,close:b});
this._tabs.push(c);c.parent=this;c.render().select();$(c.el).insertBefore($(this.el).find("ul li.newtab"));Saiku.session.trigger("tab:add",{tab:c});this.pager.render();return c},find:function(a){for(var b=0,c=this._tabs.length;b<c;b++)if(this._tabs[b].id==a)return this._tabs[b];return null},select:function(a){$(this.el).find("li").removeClass("selected");this.content.children().detach();this.content.append($(a.content.el))},remove:function(a){for(var b=0,c=this._tabs.length;b<c;b++)this._tabs[b]==
a&&(this._tabs.splice(b,1),Saiku.session.trigger("tab:remove",{tab:a}),this.pager.render(),this._tabs[this._tabs[b]?b:this._tabs.length-1].select());return!0},close_others:function(a){var b=_.indexOf(this._tabs,a);this._tabs[b].select();for(b=0;1<this._tabs.length;)this._tabs[b]!=a?this._tabs[b].remove():b++},close_all:function(){for(var a=0,b=this._tabs.length;a<b;a++)this._tabs[a].remove()},togglePager:function(){$(this.pager.el).toggle();return!1},new_tab:function(){this.add(new Workspace);this._tabs[this._tabs.length-
1].select();return!1},duplicate:function(a){Saiku.ui.block("Duplicating tab...");a.content.query?this.add(new Workspace({query:new Query({json:JSON.stringify(a.content.query.model)},Settings.PARAMS),viewState:a.content.viewState})):this.add(new Workspace);Saiku.ui.unblock();return!1}}),Cube=Backbone.Model.extend({initialize:function(a){this.url=Saiku.session.username+"/discover/"+a.key+"/metadata"},parse:function(a){var b=_.template($("#template-dimensions").html(),{dimensions:a.dimensions}),c=_.template($("#template-measures").html(),
{measures:a.measures}),d=_.template($("#template-attributes").html(),{cube:a});this.set({template_measures:c,template_dimensions:b,template_attributes:$(d).html(),data:a});"undefined"!==typeof localStorage&&localStorage&&localStorage.setItem("cube."+this.get("key"),JSON.stringify(this));return a}}),DimensionList=Backbone.View.extend({events:{"click span":"select","click a":"select","click .parent_dimension ul li a.level":"select_dimension","click .measure":"select_measure","click .addMeasure":"measure_dialog"},
initialize:function(a){_.bindAll(this,"render","load_dimension","select_dimension");this.workspace=a.workspace;this.cube=a.cube},load_dimension:function(){this.template=this.cube.get("template_attributes");this.render_attributes();this.workspace.sync_query()},render:function(){if(this.cube&&this.cube.has("template_attributes"))this.load_dimension();else if(this.cube){var a=_.template($("#template-attributes").html());$(this.el).html(a);$(this.el).find(".loading").removeClass("hide");this.workspace.bind("cube:loaded",
this.load_dimension)}else $(this.el).html("Could not load attributes. Please log out and log in again.");return this},render_attributes:function(){$(this.el).html(this.template);isIE&&8>=isIE?$(this.el).show():$(this.el).fadeTo(500,1);$(this.el).find(".addMeasure, .calculated_measures").show();$(this.el).find(".measure").parent("li").draggable({cancel:".not-draggable",connectToSortable:$(this.workspace.el).find(".fields_list_body.details ul.connectable"),helper:"clone",placeholder:"placeholder",opacity:.6,
tolerance:"touch",containment:$(this.workspace.el),cursorAt:{top:10,left:35}});$(this.el).find(".level").parent("li").draggable({cancel:".not-draggable, .hierarchy",connectToSortable:$(this.workspace.el).find(".fields_list_body.columns \x3e ul.connectable, .fields_list_body.rows \x3e ul.connectable, .fields_list_body.filter \x3e ul.connectable"),containment:$(this.workspace.el),helper:function(a,b){var c=$(a.target).hasClass("d_level")?$(a.target):$(a.target).parent(),d=c.find("a").attr("hierarchy"),
e=c.find("a").attr("level"),c=c.parent().clone().removeClass("d_hierarchy").addClass("hierarchy");c.find('li a[hierarchy\x3d"'+d+'"]').parent().hide();c.find('li a[level\x3d"'+e+'"]').parent().show();d=$('\x3cli class\x3d"selection"\x3e\x3c/li\x3e');d.append(c);return d},placeholder:"placeholder",opacity:.6,tolerance:"touch",cursorAt:{top:10,left:85}})},select:function(a){a=$(a.target).hasClass("root")?$(a.target):$(a.target).parent().find("span");a.hasClass("root")&&(a.find("a").toggleClass("folder_collapsed").toggleClass("folder_expand"),
a.toggleClass("collapsed").toggleClass("expand"),a.parents("li").find("ul").children("li").toggle());return!1},select_dimension:function(a,b){if("QUERYMODEL"==this.workspace.query.model.type)if($(a.target).parent().hasClass("ui-state-disabled"))a.preventDefault(),a.stopPropagation();else{var c=$(a.target).attr("hierarchy");$(a.target).parent().parent().attr("hierarchycaption");var d=$(a.target).attr("level"),e="ROWS",e=0<$(this.workspace.el).find(".workspace_fields ul.hierarchy[hierarchy\x3d'"+c+
"']").length?$(this.workspace.el).find(".workspace_fields ul[hierarchy\x3d'"+c+"'] a[level\x3d'"+d+"']").parent().show().parents(".fields_list_body").hasClass("rows")?"ROWS":"COLUMNS":(0<$(this.workspace.el).find(".workspace_fields .fields_list[title\x3d'ROWS'] ul.hierarchy").length?$(this.workspace.el).find(".workspace_fields .fields_list[title\x3d'COLUMNS'] ul.connectable"):$(this.workspace.el).find(".workspace_fields .fields_list[title\x3d'ROWS'] ul.connectable")).parents(".fields_list").attr("title");
this.workspace.query.helper.includeLevel(e,c,d);this.workspace.sync_query();this.workspace.query.run();a.preventDefault();return!1}},select_measure:function(a,b){if(!$(a.target).parent().hasClass("ui-state-disabled")){var c=$(a.target).parent().clone(),c={name:c.find("a").attr("measure"),type:c.find("a").attr("type")};this.workspace.query.helper.includeMeasure(c);this.workspace.sync_query();this.workspace.query.run();a.preventDefault();return!1}},measure_dialog:function(a,b){(new MeasuresModal({workspace:this.workspace,
measure:null})).render().open()}}),Toolbar=Backbone.View.extend({tagName:"div",events:{"click a":"call"},template:function(){return _.template($("#template-toolbar").html())(this)},initialize:function(){this.render()},render:function(){$(this.el).attr("id","toolbar").html(this.template());Saiku.events.trigger("toolbar:render",{toolbar:this});return this},call:function(a){var b=$(a.target).attr("href").replace("#","");if(this[b])this[b](a);a.preventDefault()},new_query:function(){Saiku.tabs.add(new Workspace);
return!1},open_query:function(){var a=_.find(Saiku.tabs._tabs,function(a){return a.content instanceof OpenQuery});a?a.select():Saiku.tabs.add(new OpenQuery);return!1},logout:function(){Saiku.session.logout()},about:function(){(new AboutModal).render().open();return!1},issue_tracker:function(){window.open("http://jira.meteorite.bi/");return!1}}),MDXModal=Modal.extend({type:"mdx",initialize:function(a){this.options.title="MDX";this.message=_.template("\x3ctextarea\x3e\x3c%\x3d mdx %\x3e\x3c/textarea\x3e")(a);
this.bind("open",function(){$(this.el).parents(".ui-dialog").css({width:"550px"})})}}),SelectionsModal=Modal.extend({type:"selections",buttons:[{text:"OK",method:"save"},{text:"Cancel",method:"close"}],events:{"click a":"call","click .search_term":"search_members","click .clear_search":"clear_search","change #show_unique":"show_unique_action","change #use_result":"use_result_action","dblclick .selection_options li.option_value label":"click_move_selection","click li.all_options":"click_all_member_selection",
"change #show_totals":"show_totals_action"},show_unique_option:!1,use_result_option:Settings.MEMBERS_FROM_RESULT,show_totals_option:"",members_limit:Settings.MEMBERS_LIMIT,members_search_limit:Settings.MEMBERS_SEARCH_LIMIT,members_search_server:!1,initialize:function(a){_.extend(this,a);this.options.title="\x3cspan class\x3d'i18n'\x3eSelections for\x3c/span\x3e "+this.name;this.message="Fetching members...";this.query=a.workspace.query;this.selected_members=[];this.available_members=[];_.bindAll(this,
"fetch_members","populate","finished","get_members","use_result_action","show_totals_action");this.axis="undefined";a.axis?(this.axis=a.axis,"FILTER"==a.axis&&(this.use_result_option=!1)):(a.target.parents(".fields_list_body").hasClass("rows")&&(this.axis="ROWS"),a.target.parents(".fields_list_body").hasClass("columns")&&(this.axis="COLUMNS"),a.target.parents(".fields_list_body").hasClass("filter")&&(this.axis="FILTER",this.use_result_option=!1));this.bind("open",this.post_render);this.render();$(this.el).parent().find(".ui-dialog-titlebar-close").bind("click",
this.finished);this.member=new Member({},{cube:a.workspace.selected_cube,dimension:a.key});$(this.el).find(".dialog_body").html(_.template($("#template-selections").html())(this));var b=this.member.level;a=this.workspace.query.helper.getHierarchy(this.member.hierarchy);var c=null;a&&a.levels.hasOwnProperty(b)&&(c=a.levels[b]);Settings.ALLOW_PARAMETERS&&(c&&(b=c.selection?c.selection.parameterName:null)&&$(this.el).find("input.parameter").val(b),$(this.el).find(".parameter").removeClass("hide"));b=
$(this.el).find("#show_totals");b.val("");1<_.size(a.levels)&&c&&c.hasOwnProperty("aggregators")&&c.aggregators?(0<c.aggregators.length&&(this.show_totals_option=c.aggregators[0]),b.removeAttr("disabled")):(b.attr("disabled",!0),this.show_totals_option="");b.val(this.show_totals_option);$(this.el).find("#use_result").attr("checked",this.use_result_option);$(this.el).find(".search_limit").text(this.members_search_limit);$(this.el).find(".members_limit").text(this.members_limit);this.get_members()},
show_totals_action:function(a){this.show_totals_option=$(a.target).val()},get_members:function(){var a=this,b="/result/metadata/hierarchies/"+encodeURIComponent(this.member.hierarchy)+"/levels/"+encodeURIComponent(this.member.level);this.search_path=b;a.workspace.block('\x3cspan class\x3d"processing_image"\x3e\x26nbsp;\x26nbsp;\x3c/span\x3e \x3cspan class\x3d"i18n"\x3e'+a.message+"\x3c/span\x3e ");this.workspace.query.action.get(b,{success:this.fetch_members,error:function(){a.workspace.unblock()},
data:{result:this.use_result_option,searchlimit:this.members_limit}})},clear_search:function(){$(this.el).find(".filterbox").val("");this.get_members()},search_members:function(){var a=this,b=$(this.el).find(".filterbox").val();if(!b)return!1;a.workspace.block('\x3cspan class\x3d"processing_image"\x3e\x26nbsp;\x26nbsp;\x3c/span\x3e \x3cspan class\x3d"i18n"\x3eSearching for members matching:\x3c/span\x3e '+b);a.workspace.query.action.get(a.search_path,{async:!1,success:function(b,d){d&&0<d.length&&
(a.available_members=d);a.populate()},error:function(){a.workspace.unblock()},data:{search:b,searchlimit:a.members_search_limit}})},fetch_members:function(a,b){b&&0<b.length&&(this.available_members=b);this.populate()},populate:function(a,b){var c=this,d;c.workspace.unblock();this.members_search_server=this.available_members.length>=this.members_limit||0===this.available_members.length;c.show_unique_option=!1;$(this.el).find(".options #show_unique").attr("checked",!1);$(this.el).find(".items_size").text(this.available_members.length);
this.members_search_server?$(this.el).find(".warning").text("More items available than listed. Pre-Filter on server."):$(this.el).find(".warning").text("");d=c.member.level;var e=c.workspace.query.helper.getHierarchy(c.member.hierarchy);e&&e.levels.hasOwnProperty(d)&&(this.selected_members=e.levels[d].selection?e.levels[d].selection.members:[]);var f=[];d=0;for(e=this.selected_members.length;d<e;d++)f.push(this.selected_members[d].caption);0===$(this.el).find(".used_selections .selection_options li.option_value").length&&
(e=$(this.el).find(".used_selections .selection_options"),e.empty(),d=_.template($("#template-selections-options").html())({options:this.selected_members}),$(e).html(d));this.available_members=_.filter(this.available_members,function(a){return-1===f.indexOf(a.caption)});0<this.available_members.length&&(e=$(this.el).find(".available_selections .selection_options"),e.empty(),d=_.template($("#template-selections-options").html())({options:this.available_members}),$(e).html(d));0<$(c.el).find(".selection_options.ui-selectable").length&&
$(c.el).find(".selection_options").selectable("destroy");$(c.el).find(".selection_options").selectable({distance:20,filter:"li",stop:function(a,b){$(c.el).find(".selection_options li.ui-selected input").each(function(a,b){b&&b.hasAttribute("checked")?b.checked=!0:$(b).attr("checked",!0);$(b).parents(".selection_options").find("li.all_options input").prop("checked",!0)});$(c.el).find(".selection_options li.ui-selected").removeClass("ui-selected")}});$(this.el).find(".filterbox").autocomplete({minLength:1,
delay:200,appendTo:".autocomplete",source:function(a,b){var d=!1===c.show_unique_option?"caption":"name",e=$.map(c.available_members,function(b){if(-1<b[d].toLowerCase().indexOf(a.term.toLowerCase()))return{label:!1===c.show_unique_option?b.caption:b.uniqueName,value:!1===c.show_unique_option?b.uniqueName:b.caption}});b(e)},select:function(a,b){encodeURIComponent(b.item.value);var d=b.item.label,e=!1===c.show_unique_option?b.item.value:b.item.label,f=!1===c.show_unique_option?b.item.label:b.item.value;
$(c.el).find('.available_selections .selection_options input[value\x3d"'+encodeURIComponent(e)+'"]').parent().remove();$(c.el).find('.used_selections .selection_options input[value\x3d"'+encodeURIComponent(e)+'"]').parent().remove();d='\x3cli class\x3d"option_value"\x3e\x3cinput type\x3d"checkbox" class\x3d"check_option" value\x3d"'+encodeURIComponent(e)+'" label\x3d"'+encodeURIComponent(f)+'"\x3e'+d+"\x3c/input\x3e\x3c/li\x3e";$(d).appendTo($(c.el).find(".used_selections .selection_options ul"));
$(c.el).find(".filterbox").val("");b.item.value=""},close:function(a,b){},open:function(a,b){}});$(this.el).find(".filterbox").autocomplete("enable");Saiku.i18n.translate();Saiku.ui.unblock()},post_render:function(a){var b=($(window).width()-1E3)/2,c=1040>$(window).width()?$(window).width():1040;$(a.modal.el).parents(".ui-dialog").css({width:c,left:"inherit",margin:"0",height:490}).offset({left:b});$("#filter_selections").attr("disabled",!1);$(this.el).find("a[href\x3d#save]").focus();$(this.el).find("a[href\x3d#save]").blur()},
move_selection:function(a){a.preventDefault();a=$(a.target).attr("id");var b=-1!==a.indexOf("add")?$(this.el).find(".used_selections .selection_options ul"):$(this.el).find(".available_selections .selection_options ul"),c=-1!==a.indexOf("add")?$(this.el).find(".available_selections .selection_options ul"):$(this.el).find(".used_selections .selection_options ul");(-1!==a.indexOf("all")?c.find("li.option_value input").parent():c.find("li.option_value input:checked").parent()).detach().appendTo(b);$(this.el).find(".selection_options ul li.option_value input:checked").prop("checked",
!1);$(this.el).find(".selection_options li.all_options input").prop("checked",!1)},updown_selection:function(a){a.preventDefault();return!1},click_all_member_selection:function(a,b){$(a.currentTarget).find("input").is(":checked")?$(a.currentTarget).parent().find("li.option_value input").prop("checked",!0):$(a.currentTarget).parent().find("li.option_value input").removeAttr("checked")},click_move_selection:function(a,b){a.preventDefault();var c=$(a.target).parent().parent().parent().parent().hasClass("used_selections")?
".available_selections":".used_selections";$(a.target).parent().appendTo($(this.el).find(c+" .selection_options ul"))},show_unique_action:function(){this.show_unique_option=!this.show_unique_option;!0===this.show_unique_option?($(this.el).find(".available_selections, .used_selections").addClass("unique"),$(this.el).find(".available_selections, .used_selections").removeClass("caption")):($(this.el).find(".available_selections, .used_selections").addClass("caption"),$(this.el).find(".available_selections, .used_selections").removeClass("unique"))},
use_result_action:function(){this.use_result_option=!this.use_result_option;this.get_members()},save:function(){var a=$("\x3cdiv\x3eSaving...\x3c/div\x3e");$(this.el).find(".dialog_body").children().hide();$(this.el).find(".dialog_body").prepend(a);var b=decodeURIComponent(this.member.hierarchy),a=decodeURIComponent(this.member.level),b=this.workspace.query.helper.getHierarchy(b),c=[],d=this.show_totals_option;0!==$(this.el).find(".used_selections input").length&&$(this.el).find(".used_selections .option_value input").each(function(a,
b){var d=$(b).val(),e=$(b).attr("label");c.push({uniqueName:decodeURIComponent(d),caption:decodeURIComponent(e)})});var e=$("#parameter").val();b&&b.levels.hasOwnProperty(a)&&(b.levels[a].aggregators=[],d&&b.levels[a].aggregators.push(d),b.levels[a].selection={type:"INCLUSION",members:c},Settings.ALLOW_PARAMETERS&&e&&(b.levels[a].selection.parameterName=e,this.workspace.query.helper.model()));this.finished()},finished:function(){$("#filter_selections").remove();this.available_members=null;$(this.el).find(".filterbox").autocomplete("destroy").remove();
$(this.el).dialog("destroy");$(this.el).remove();this.query.run()}}),DrillthroughModal=Modal.extend({type:"drillthrough",buttons:[{text:"Ok",method:"ok"},{text:"Cancel",method:"close"}],events:{"click .collapsed":"select","click .expand":"select","click .folder_collapsed":"select","click .folder_expanded":"select","click .dialog_footer a":"call","click .parent_dimension input":"select_dimension","click .measure_tree input":"select_measure","click input.all_measures":"select_all_measures","click input.all_dimensions":"select_all_dimensions"},
initialize:function(a){_.extend(this,a);this.options.title=a.title;this.query=a.workspace.query;this.position=a.position;this.action=a.action;Saiku.ui.unblock();_.bindAll(this,"ok","drilled");this.render();$(this.el).find(".dialog_body").html(_.template($("#template-drillthrough").html())(this));$(this.el).find(".maxrows").val(this.maxrows);a=$("#template-drillthrough-list").html();var b=this.workspace.metadata,c=null,d=null;b&&b.has("data")&&(c=b.get("data").dimensions,d=b.get("data").measures);
b&&c&&d||("undefined"!==typeof localStorage&&localStorage&&null!==localStorage.getItem("cube."+key)?Saiku.session.sessionworkspace.cube[key]=new Cube(JSON.parse(localStorage.getItem("cube."+key))):(Saiku.session.sessionworkspace.cube[key]=new Cube({key:key}),Saiku.session.sessionworkspace.cube[key].fetch({async:!1})),c=Saiku.session.sessionworkspace.cube[key].get("data").dimensions,d=Saiku.session.sessionworkspace.cube[key].get("data").measures);b=_.template($("#template-drillthrough-dimensions").html())({dimensions:c});
d=_.template($("#template-drillthrough-measures").html())({measures:d});$(a).appendTo($(this.el).find(".dialog_body"));$(this.el).find(".sidebar").height($("body").height()/2+$("body").height()/6);$(this.el).find(".sidebar").width(380);$(this.el).find(".dimension_tree").html("").append($(b));$(this.el).find(".measure_tree").html("").append($(d));Saiku.i18n.translate()},select:function(a){a=$(a.target).hasClass("root")?$(a.target):$(a.target).parent().find("span");a.hasClass("root")&&(a.find("a").toggleClass("folder_collapsed").toggleClass("folder_expand"),
a.toggleClass("collapsed").toggleClass("expand"),a.parents("li").find("ul").children("li").toggle());return!1},select_dimension:function(a){a=$(a.target);var b=a.is(":checked");a.parent().find("input").attr("checked",b)},select_all_dimensions:function(a){a=$(a.target).is(":checked");$(this.el).find(".dimension_tree input").attr("checked",a)},select_all_measures:function(a){a=$(a.target).is(":checked");$(this.el).find(".measure_tree input").attr("checked",a)},select_measure:function(a){$(a.target).is(":checked")},
ok:function(){var a=$("\x3cdiv\x3eDrilling through...\x3c/div\x3e");$(this.el).find(".dialog_body").children().hide();$(this.el).find(".dialog_body").prepend(a);var b="";$(this.el).find(".check_level:checked").each(function(a){0<a&&(b+=", ");b+=$(this).val()});var a=$(this.el).find(".maxrows").val(),c;c="?maxrows\x3d"+a+("undefined"!==typeof this.position?"\x26position\x3d"+this.position:"");c+="\x26returns\x3d"+b;"export"==this.action?(a=Settings.REST_URL+this.query.url()+"/drillthrough/export/csv"+
c,this.close(),window.open(a)):"table"==this.action&&(Saiku.ui.block("Executing drillthrough..."),this.query.action.get("/drillthrough",{data:{position:this.position,maxrows:a,returns:b},success:this.drilled}),this.close());return!1},drilled:function(a,b){var c="",c=null!==b&&null!==b.error?safe_tags_replace(b.error):(new SaikuTableRenderer).render(b);Saiku.ui.unblock();c='\x3cdiv id\x3d"fancy_results" class\x3d"workspace_results" style\x3d"overflow:visible"\x3e'+c+"\x3c/div\x3e";this.remove();$.fancybox(c,
{autoDimensions:!1,autoScale:!1,height:$("body").height()-100,width:$("body").width()-100,transitionIn:"none",transitionOut:"none"})},finished:function(){$(this.el).dialog("destroy").remove();this.query.run()}}),PermissionsModal=Modal.extend({type:"permissions",buttons:[{text:"Ok",method:"ok"},{text:"Cancel",method:"close"}],events:{"click .add_role":"add_role","click .remove_acl":"remove_acl","submit form":"add_role","click a":"call","click input.private":"keep_private"},rolesacl:{},acltype:"SECURED",
initialize:function(a){_.extend(this,a);this.options.title=a.title;this.file=a.file;this.rolesacl={};Saiku.ui.unblock();_.bindAll(this,"ok","add_role","remove_acl");this.bind("open",Saiku.i18n.translate());this.render();$(this.el).find(".dialog_body").html(_.template($("#template-permissions").html())(this));$(this.el).find(".filterbox").autocomplete({minLength:1,source:Saiku.session.roles}).data("autocomplete");a=new RepositoryAclObject({file:this.file});a.fetch({async:!1});var b="undefined"==typeof a.get("roles")||
null===a.get("roles")?{}:a.get("roles");this.rolesacl=b;b=_.template($("#template-permissions-rolelist").html())({roles:b});$(this.el).find(".rolelist").html(b);b="undefined"==typeof a.get("owner")||null===a.get("owner")?"":a.get("owner");a="undefined"==typeof a.get("type")||null===a.get("type")?null:a.get("type");null!==a&&"PRIVATE"==a&&($(this.el).find(".private_owner .owner").text(b),$(this.el).find(".private_owner").show());$(this.el).find(".i18n").i18n(Saiku.i18n.po_file)},add_role:function(a){a.preventDefault();
if("PRIVATE"==this.acltype)return!1;a=$(this.el).find(".filterbox").val();var b=[],c="",d=0;a&&0<a.length&&($(this.el).find(".acl:checked").each(function(a){0<a&&(c+=", ");d++;c+=$(this).val();b.push($(this).val())}),0<d?(this.rolesacl[a]=b,$("\x3coption value\x3d'"+a+"'\x3e"+a+" ["+c+"]\x3c/option\x3e").appendTo($(this.el).find(".select_roles")),a=$(this.el).find(".filterbox").val("")):alert("You need to chose at least one ACL method for this role."));return!1},keep_private:function(a){$(this.el).find("input.private").is(":checked")?
($(this.el).find(".permissions").addClass("disabled_toolbar"),$("input.acl, input.filterbox, input.add_role, input.remove_acl").prop("disabled",!0),this.acltype="PRIVATE"):($(this.el).find(".permissions").removeClass("disabled_toolbar"),$("input.acl, input.filterbox, input.add_role, input.remove_acl").prop("disabled",!1),this.acltype="SECURED")},remove_acl:function(a){var b=this;if("PRIVATE"==this.acltype)return!1;$(this.el).find(".select_roles option:selected").each(function(a){delete b.rolesacl[$(this).val()]});
$(this.el).find(".select_roles option:selected").remove();return!1},ok:function(){var a=this.close(),b={},b="PRIVATE"==this.acltype?{type:"PRIVATE",owner:Saiku.session.username}:{type:"SECURED",roles:this.rolesacl,owner:Saiku.session.username};(new RepositoryAclObject({file:this.file,acl:JSON.stringify(b)})).save({success:a});return!1}}),LoginForm=Modal.extend({type:"login",message:_.template("\x3cform id\x3d'login_form'\x3e\x3clabel for\x3d'username' class\x3d'i18n'\x3eUsername\x3c/label\x3e\x3cinput type\x3d'text' id\x3d'username' name\x3d'username' value\x3d'' /\x3e\x3clabel for\x3d'password' class\x3d'i18n'\x3ePassword\x3c/label\x3e\x3cinput type\x3d'password' id\x3d'password' name\x3d'password' value\x3d'' /\x3e\x3c% if (Settings.EVALUATION_PANEL_LOGIN) { %\x3e\x3cdiv class\x3d'eval-panel'\x3e\x3ca href\x3d'#eval_login' class\x3d'i18n' id\x3d'eval-login'\x3eEvaluation Login\x3c/a\x3e\x3cdiv class\x3d'eval-panel-user clearfix' hidden\x3e\x3cul\x3e\x3cli class\x3d'i18n'\x3eAdministrator\x3c/li\x3e\x3cli class\x3d'i18n'\x3eUsername: admin\x3c/li\x3e\x3cli class\x3d'i18n'\x3ePassword: admin\x3c/li\x3e\x3c/ul\x3e\x3c/div\x3e\x3c/div\x3e\x3c% } %\x3e\x3c/form\x3e")(),
buttons:[{text:"Login",method:"login"}],events:{"click a":"call","keyup #login_form input":"check","click #eval-login":"show_panel_user"},initialize:function(a){_.extend(this,a);_.bindAll(this,"adjust");this.options.title=Settings.VERSION;this.bind("open",this.adjust)},adjust:function(){$(this.el).parent().find(".ui-dialog-titlebar-close").hide();$(this.el).find("#username").select().focus()},check:function(a){13===a.which&&this.login()},login:function(){var a=$(this.el).find("#username").val(),b=
$(this.el).find("#password").val();$(this.el).dialog("close");this.session.login(a,b,$(this.el));return!0},setMessage:function(a){this.$el.find(".dialog_body").html(this.message)},setError:function(a){$(this.el).find(".dialog_response").html(a)},show_panel_user:function(a){a.preventDefault();$(a.currentTarget).next().slideToggle("fast")}}),DemoLoginForm=Modal.extend({type:"login",message:"\x3cform id\x3d'demo_form'\x3e\x3clabel for\x3d'email'\x3eEmail:\x3c/label\x3e\x3cinput type\x3d'text' id\x3d'email' name\x3d'email' value\x3d'' /\x3e\x3c/form\x3e",
buttons:[{text:"Start Demo",method:"login"}],events:{"click a":"call","submit form ":"login"},initialize:function(a){_.extend(this,a);_.bindAll(this,"adjust");this.options.title=Settings.VERSION;this.bind("open",this.adjust)},adjust:function(){$(this.el).parent().find(".ui-dialog-titlebar-close").hide();$(this.el).find("#email").select().focus()},login:function(a){var b=Settings.USERNAME,c=Settings.PASSWORD,d=$(this.el).find("#email").val();d&&((new logger({url:Settings.TELEMETRY_SERVER+"/input/demo"})).log({email:d,
created_at:Math.round((new Date).getTime()/1E3)}),$(this.el).dialog("close"),this.session.login(b,c));a&&(a.preventDefault(),a.stopPropagation());return!0}}),AboutModal=Modal.extend({initialize:function(){_.extend(this.options,{title:"About "+Settings.VERSION})},events:{"click a":"close"},dummy:function(){return!0},type:"info",message:Settings.VERSION+"\x3cbr\x3e\x3ca target\x3d'_blank' href\x3d'http://www.analytical-labs.com'\x3ehttp://www.analytical-labs.com/\x3c/a\x3e\x3cbr\x3e\x3cbr\x3ePowered by \x3cimg width\x3d'20px' src\x3d'images/src/meteorite_free.png' /\x3e \x3ca target\x3d'_blank' href\x3d'http://meteorite.bi'\x3ehttp://meteorite.bi/\x3c/a\x3e "}),
AddFolderModal=Modal.extend({type:"save",closeText:"Save",events:{"click .form_button":"save","submit form":"save"},buttons:[{text:"OK",method:"save"}],initialize:function(a){this.success=a.success;this.path=a.path;this.message="\x3cform id\x3d'add_folder'\x3e\x3clabel class\x3d'i18n' for\x3d'name'\x3eTo add a new folder, please type a name in the text box below:\x3c/label\x3e\x3cinput type\x3d'text' class\x3d'newfolder' name\x3d'name' /\x3e\x3c/form\x3e";_.extend(this.options,{title:"Add Folder"});
if(isIE&&9>isIE)$(this.el).find("form").on("submit",this.save)},save:function(a){a.preventDefault();a=$(this.el).find('input[name\x3d"name"]').val();(new SavedQuery({file:this.path+a,name:a})).save({},{success:this.success,dataType:"text",error:this.error});this.close();return!1},error:function(){$(this.el).find("dialog_body").html("Could not add new folder")}}),FilterModal=Modal.extend({type:"filter",closeText:"Save",events:{"submit form":"save","click .dialog_footer a":"call"},buttons:[{text:"OK",
method:"save"},{text:"Cancel",method:"close"}],message:"",expression_text:function(){var a="\x3cform id\x3d'custom_filter'\x3e\x3ctable border\x3d'0px'\x3e";"Order"==this.expressionType&&(a+="\x3ctr\x3e\x3ctd class\x3d'col1'\x3eSort Type: \x3cselect id\x3d'fun'\x3e\x3coption\x3eASC\x3c/option\x3e\x3coption\x3eBASC\x3c/option\x3e\x3coption\x3eDESC\x3c/option\x3e\x3coption\x3eBDESC\x3c/option\x3e \x3c/select\x3e\x3c/td\x3e\x3c/tr\x3e");return a+="\x3ctr\x3e\x3ctd class\x3d'col1'\x3e"+this.expressionType+
" MDX Expression:\x3c/td\x3e\x3c/tr\x3e\x3ctr\x3e\x3ctd class\x3d'col1'\x3e\x3ctextarea class\x3d'filter_expression'\x3e\x3c/textarea\x3e\x3c/td\x3e\x3c/tr\x3e\x3c/table\x3e\x3c/form\x3e"},expression:" ",expressonType:"",initialize:function(a){var b=this;this.axis=a.axis;this.query=a.query;this.success=a.success;this.expression=a.expression;this.expressionType=a.expressionType;_.bindAll(this,"save","expression_text");_.extend(this.options,{title:"Custom "+this.expressionType+" for "+this.axis});this.message=
this.expression_text(this.expressionType);this.bind("open",function(){$(this.el).find("textarea").val("").val(b.expression)});if(isIE&&9>isIE)$(this.el).find("form").on("submit",this.save)},save:function(a){a.preventDefault();this.expression=$(this.el).find("textarea").val();a="";"undefined"!=typeof this.expression&&this.expression&&""!==this.expression?("Order"==this.expressionType?(a=$("#fun").val(),this.success(a,this.expression)):this.success(this.expression),this.close()):(a+="You have to enter a MDX expression for the "+
this.expressionType+" function! ",alert(a));return!1},error:function(){$(this.el).find("dialog_body").html("Could not add new folder")}}),CustomFilterModal=Modal.extend({type:"filter",closeText:"Save",events:{"submit form":"save","change .function":"switch_function","change .type":"switch_type","click .dialog_footer a":"call"},buttons:[{text:"OK",method:"save"},{text:"Cancel",method:"close"}],message:"\x3cform id\x3d'custom_filter'\x3e\x3ctable border\x3d'0px'\x3e\x3ctr\x3e\x3ctd class\x3d'col0'\x3eDefine Filter:\x3c/td\x3e\x3ctd class\x3d'col1'\x3e\x3cselect class\x3d'function'\x3e\x3coption\x3eSelect a Function...\x3c/option\x3e\x3coption value\x3d'TopCount'\x3eTopCount\x3c/option\x3e\x3coption value\x3d'TopPercent'\x3eTopPercent\x3c/option\x3e\x3coption value\x3d'TopSum'\x3eTopSum\x3c/option\x3e\x3coption value\x3d'BottomCount'\x3eBottomCount\x3c/option\x3e\x3coption value\x3d'BottomPercent'\x3eBottomPercent\x3c/option\x3e\x3coption value\x3d'BottomSum'\x3eBottomSum\x3c/option\x3e\x3c/select\x3e\x3c/td\x3e\x3c/tr\x3e\x3ctr class\x3d'filter_details hide'\x3e\x3ctd\x3e\x3cspan class\x3d'ntype'\x3e\x3c/span\x3e\x3c/td\x3e\x3ctd\x3e\x3cinput class\x3d'n' /\x3e\x3c/td\x3e\x3c/tr\x3e\x3ctr class\x3d'filter_details hide'\x3e\x3ctd\x3eSort by:\x3c/td\x3e\x3ctd\x3e\x3cselect class\x3d'type'\x3e\x3coption value\x3d'measure'\x3eMeasure\x3c/option\x3e\x3coption value\x3d'custom'\x3eMDX Expression\x3c/option\x3e\x3c/select\x3e\x3c/td\x3e\x3c/tr\x3e\x3ctr class\x3d'filter_details hide'\x3e\x3ctd\x3e\x26nbsp;\x3c/td\x3e\x3ctd class\x3d'sortingoption'\x3e\x26nbsp;\x3c/td\x3e\x3c/table\x3e\x3c/form\x3e",
func:null,func_type:"Measure",n:"",sortliteral:"",measure_list:null,initialize:function(a){var b=this;this.axis=a.axis;this.measures=a.measures;this.query=a.query;this.success=a.success;this.func=a.func;this.n=a.n;this.sortliteral=a.sortliteral;this.isMdx=!0;_.bindAll(this,"build_measures_list","save");this.measure_list=this.build_measures_list();_.extend(this.options,{title:"Custom Filter for "+this.axis});this.bind("open",function(){null!==b.func&&($(b.el).find(".function").val(b.func),b.switch_function({target:$(b.el).find(".function")}),
$(b.el).find(".n").val(b.n),!0===b.isMdx&&null!==b.sortliteral&&($(this.el).find(".type").val("custom"),$(this.el).find(".sortingoption").html("").html("\x3ctextarea class\x3d'sortliteral'\x3e"+b.sortliteral+"\x3c/textarea\x3e")))});if(isIE&&9>isIE)$(this.el).find("form").on("submit",this.save)},build_measures_list:function(){var a=this;if(null!==this.measure_list)return"";var b="\x3cselect class\x3d'sortliteral'\x3e";_.each(this.measures,function(c){var d="";c.uniqueName==a.sortliteral&&(d=" selected ",
a.isMdx=!1);b+="\x3coption "+d+"value\x3d'"+c.uniqueName+"'\x3e"+c.caption+"\x3c/option\x3e"});return b+="\x3c/select\x3e"},switch_function:function(a){a=$(a.target).val();"undefined"==typeof a||""===a?$(this.el).find(".filter_details").hide():(a=a.replace("Top","").replace("Bottom",""),$(this.el).find(".ntype").html(a+":"),$(this.el).find(".filter_details").show(),$(this.el).find(".sortingoption").html("").html(this.measure_list));return!1},switch_type:function(a){"measure"==$(a.target).val()?$(this.el).find(".sortingoption").html("").html(this.measure_list):
$(this.el).find(".sortingoption").html("").html("\x3ctextarea class\x3d'sortliteral' /\x3e");return!1},save:function(a){a.preventDefault();this.func=$(this.el).find(".function").val();this.n=parseInt($(this.el).find(".n").val());this.sortliteral=$(this.el).find(".sortliteral").val();a="";"undefined"!=typeof this.n&&this.n||(a+="You have to enter a numeric for N! ");"undefined"!=typeof this.sortliteral&&this.sortliteral&&""!==this.sortliteral||(a+="You have to enter a MDX expression for the sort literal! ");
""!==a?alert(a):(this.success(this.func,this.n,this.sortliteral),this.close());return!1},error:function(){$(this.el).find("dialog_body").html("Could not add new folder")}}),DateFilterModal=Modal.extend({type:"date-filter",buttons:[{text:"Save",method:"save"},{text:"Cancel",method:"close"}],events:{"click a":"call","focus .selection-date":"selection_date","click .selection-radio":"disable_divselections","click .operator-radio":"show_fields","click #add-date":"add_selected_date","click .del-date":"del_selected_date"},
template_days_mdx:"Filter({parent}.Members, {parent}.CurrentMember.NAME {comparisonOperator} '{dates}'",template_many_years_mdx:" {logicalOperator} {parent}.CurrentMember.NAME {comparisonOperator} '{dates}'",template_mdx:"{parent} CurrentDateMember([{dimension}.{hierarchy}], '[\"{dimension}.{hierarchy}\"]\\.{AnalyzerDateFormat}', EXACT)",template_last_mdx:"{parent} LastPeriods({periodamount}, CurrentDateMember([{dimension}.{hierarchy}], '[\"{dimension}.{hierarchy}\"]\\.{AnalyzerDateFormat}', EXACT))",
template_dialog:_.template('\x3cdiv class\x3d"box-selections"\x3e\x3cdiv class\x3d"selection-option"\x3e\x3cinput type\x3d"radio" class\x3d"selection-radio" name\x3d"selection-radio" id\x3d"selection-radio-operator" level-type\x3d"TIME_DAYS" disabled\x3e\x3c/div\x3e\x3cdiv class\x3d"available-selections" selection-name\x3d"operator" available\x3d"false"\x3e\x3cspan class\x3d"i18n"\x3eOperator:\x3c/span\x3e\x3cbr\x3e\x3cdiv class\x3d"selection-options"\x3e\x3cdiv class\x3d"form-group-selection"\x3e\x3clabel\x3e\x3cinput type\x3d"radio" name\x3d"operator-radio" class\x3d"operator-radio" id\x3d"op-equals" value\x3d"\x3d"\x3e Equals\x3c/label\x3e\x3c/div\x3e\x3cdiv class\x3d"form-group-selection"\x3e\x3clabel\x3e\x3cinput type\x3d"radio" name\x3d"operator-radio" class\x3d"operator-radio" id\x3d"op-after" value\x3d"\x3e"\x3e After\x3c/label\x3e\x3c/div\x3e\x3cdiv class\x3d"form-group-selection"\x3e\x3clabel\x3e\x3cinput type\x3d"radio" name\x3d"operator-radio" class\x3d"operator-radio" id\x3d"op-before" value\x3d"\x3c"\x3e Before\x3c/label\x3e\x3c/div\x3e\x3cdiv class\x3d"form-group-selection"\x3e\x3clabel\x3e\x3cinput type\x3d"radio" name\x3d"operator-radio" class\x3d"operator-radio" id\x3d"op-between" value\x3d"\x3e|\x3c"\x3e Between\x3c/label\x3e\x3cbr\x3e\x3c/div\x3e\x3cdiv class\x3d"form-group-selection"\x3e\x3clabel\x3e\x3cinput type\x3d"radio" name\x3d"operator-radio" class\x3d"operator-radio" id\x3d"op-different" value\x3d"\x3c\x3e"\x3e Different\x3c/label\x3e\x3c/div\x3e\x3cdiv class\x3d"form-group-selection"\x3e\x3clabel\x3e\x3cinput type\x3d"radio" name\x3d"operator-radio" class\x3d"operator-radio" id\x3d"op-after-equals" value\x3d"\x3e\x3d"\x3e After\x26Equals\x3c/label\x3e\x3c/div\x3e\x3cdiv class\x3d"form-group-selection"\x3e\x3clabel\x3e\x3cinput type\x3d"radio" name\x3d"operator-radio" class\x3d"operator-radio" id\x3d"op-before-equals" value\x3d"\x3c\x3d"\x3e Before\x26Equals\x3c/label\x3e\x3c/div\x3e\x3cdiv class\x3d"form-group-selection"\x3e\x3clabel\x3e\x3cinput type\x3d"radio" name\x3d"operator-radio" class\x3d"operator-radio" id\x3d"op-notbetween"\x3e Not Between\x3c/label\x3e\x3cbr\x3e\x3c/div\x3e\x3cdiv class\x3d"inline-form-group"\x3e\x3cdiv class\x3d"form-group" id\x3d"div-selection-date" hidden\x3e\x3clabel\x3eSelect a date:\x3c/label\x3e\x3cinput type\x3d"text" class\x3d"selection-date" id\x3d"selection-date" placeholder\x3d"Choose a date"\x3e\x3ca class\x3d"form_button" id\x3d"add-date"\x3eadd\x3c/a\x3e\x3c/div\x3e\x3cdiv class\x3d"form-group" id\x3d"div-selected-date" hidden\x3e\x3cfieldset\x3e\x3clegend\x3eSelected date:\x3c/legend\x3e\x3cul id\x3d"selected-date"\x3e\x3c/ul\x3e\x3c/fieldset\x3e\x3c/div\x3e\x3c/div\x3e\x3cdiv class\x3d"form-group" id\x3d"div-select-start-date" hidden\x3e\x3clabel\x3eSelect a start date:\x3c/label\x3e\x3cinput type\x3d"text" class\x3d"selection-date" id\x3d"start-date" placeholder\x3d"Choose a date"\x3e\x3c/div\x3e\x3cdiv class\x3d"form-group" id\x3d"div-select-end-date" hidden\x3e\x3clabel\x3eSelect an end date:\x3c/label\x3e\x3cinput type\x3d"text" class\x3d"selection-date" id\x3d"end-date" placeholder\x3d"Choose a date"\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e\x3cdiv class\x3d"box-selections"\x3e\x3cdiv class\x3d"selection-option"\x3e\x3cinput type\x3d"radio" class\x3d"selection-radio" name\x3d"selection-radio" id\x3d"selection-radio-fixed-date"\x3e\x3c/div\x3e\x3cdiv class\x3d"available-selections" selection-name\x3d"fixed-date" available\x3d"false"\x3e\x3cspan class\x3d"i18n"\x3eFixed Date:\x3c/span\x3e\x3cbr\x3e\x3cdiv class\x3d"selection-options"\x3e\x3clabel\x3e\x3cinput type\x3d"radio" name\x3d"fixed-radio" id\x3d"fd-yesterday"\x3e Yesterday\x3c/label\x3e\x3clabel\x3e\x3cinput type\x3d"radio" name\x3d"fixed-radio" id\x3d"fd-day"\x3e Today\x3c/label\x3e\x3clabel\x3e\x3cinput type\x3d"radio" name\x3d"fixed-radio" id\x3d"fd-week"\x3e Current Week\x3c/label\x3e\x3clabel\x3e\x3cinput type\x3d"radio" name\x3d"fixed-radio" id\x3d"fd-month"\x3e Current Month\x3c/label\x3e\x3clabel\x3e\x3cinput type\x3d"radio" name\x3d"fixed-radio" id\x3d"fd-quarter"\x3e Current Quarter\x3c/label\x3e\x3cbr\x3e\x3clabel\x3e\x3cinput type\x3d"radio" name\x3d"fixed-radio" id\x3d"fd-year"\x3e Current Year\x3c/label\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e\x3cdiv class\x3d"box-selections"\x3e\x3cdiv class\x3d"selection-option"\x3e\x3cinput type\x3d"radio" class\x3d"selection-radio" name\x3d"selection-radio" id\x3d"selection-radio-available"\x3e\x3c/div\x3e\x3cdiv class\x3d"available-selections" selection-name\x3d"rolling-date" available\x3d"false"\x3e\x3cspan class\x3d"i18n"\x3eRolling Date:\x3c/span\x3e\x3cbr\x3e\x3cdiv class\x3d"selection-options"\x3e\x3cdiv class\x3d"form-group-selection"\x3e\x3cselect id\x3d""\x3e\x3coption value\x3d"last"\x3eLast\x3c/option\x3e\x3coption value\x3d"next" disabled class\x3d"keep-disabled"\x3eNext\x3c/option\x3e\x3c/select\x3e\x3c/div\x3e\x3cdiv class\x3d"form-group-selection"\x3e\x3cinput type\x3d"text" id\x3d"date-input"\x3e\x3c/div\x3e\x3cdiv class\x3d"form-group-selection"\x3e\x3cselect id\x3d"period-select"\x3e\x3coption name\x3d"TIME_DAYS" id\x3d"rd-days"\x3eDay(s)\x3c/option\x3e\x3coption name\x3d"TIME_WEEKS" id\x3d"rd-weeks"\x3eWeek(s)\x3c/option\x3e\x3coption name\x3d"TIME_MONTHS" id\x3d"rd-months"\x3eMonth(s)\x3c/option\x3e\x3coption name\x3d"TIME_YEARS" id\x3d"rd-years"\x3eYear(s)\x3c/option\x3e\x3c/select\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e'),
initialize:function(a){_.extend(this,a);this.options.title="Selections for Year";this.message="Loading...";this.query=a.workspace.query;this.selections=[];this.dates=[];_.bindAll(this,"finished");this.bind("open",this.post_render);this.render();this.$el.parent().find(".ui-dialog-titlebar-close").bind("click",this.finished);this.member=new Member({},{cube:this.workspace.selected_cube,dimension:this.key});this.$el.find(".dialog_body").html(this.template_dialog);this.$el.find(".available-selections *").prop("disabled",
!0).off("click");this.dataLevels=this.save_data_levels();this.check_leveltype_radio();this.add_values_fixed_date();this.add_values_last_periods();this.populate()},post_render:function(a){var b=($(window).width()-600)/2,c=600>$(window).width()?$(window).width():600;$(a.modal.el).parents(".ui-dialog").css({width:c,left:"inherit",margin:"0",height:490}).offset({left:b})},check_leveltype_radio:function(){var a=this,b;this.$el.find(".selection-radio").each(function(c,d){b=$(d).attr("level-type");_.find(a.dataLevels,
function(a,c,g){(b===a.levelType||a.saikuDayFormatString)&&$(d).prop("disabled",!1)})})},show_fields:function(a){a=a.type?$(a.currentTarget):$(a);var b=a.parent("label").text().split(" ")[1];if(void 0!==b)switch(b){case "Equals":case "Different":a.closest(".selection-options").find("#div-selection-date").show();a.closest(".selection-options").find("#div-selected-date").show();a.closest(".selection-options").find("#div-select-start-date").hide();a.closest(".selection-options").find("#div-select-end-date").hide();
a.closest(".selection-options").find("#add-date").show();break;case "After":case "After\x26Equals":case "Before":case "Before\x26Equals":a.closest(".selection-options").find("#div-selection-date").show();a.closest(".selection-options").find("#div-selected-date").hide();a.closest(".selection-options").find("#div-select-start-date").hide();a.closest(".selection-options").find("#div-select-end-date").hide();a.closest(".selection-options").find("#add-date").hide();break;case "Between":case "Not":a.closest(".selection-options").find("#div-selection-date").hide();
a.closest(".selection-options").find("#div-selected-date").hide();a.closest(".selection-options").find("#div-select-start-date").show();a.closest(".selection-options").find("#div-select-end-date").show();a.closest(".selection-options").find("#add-date").hide();break;default:a.closest(".selection-options").find("#div-selection-date").hide(),a.closest(".selection-options").find("#div-selected-date").hide(),a.closest(".selection-options").find("#div-select-start-date").hide(),a.closest(".selection-options").find("#div-select-end-date").hide(),
a.closest(".selection-options").find("#add-date").hide()}else this.$el.find(".selection-options").find("#div-selection-date").hide(),this.$el.find(".selection-options").find("#div-selected-date").hide(),this.$el.find(".selection-options").find("#div-select-start-date").hide(),this.$el.find(".selection-options").find("#div-select-end-date").hide(),this.$el.find(".selection-options").find("#add-date").hide()},save_data_levels:function(){var a=this,b=[];_.each(this.data.hierarchies.levels,function(c,
d,e){if(void 0!==e[d].annotations.AnalyzerDateFormat||void 0!==e[d].annotations.SaikuDayFormatString)void 0!==e[d].annotations.AnalyzerDateFormat?b.push({name:e[d].name,analyzerDateFormat:e[d].annotations.AnalyzerDateFormat.replace(/[.]/gi,"\\."),levelType:e[d].levelType,saikuDateProperty:e[d].annotations.SaikuDateProperty||"",saikuDayFormatString:e[d].annotations.SaikuDayFormatString||""}):b.push({name:e[d].name,analyzerDateFormat:"",levelType:e[d].levelType,saikuDateProperty:e[d].annotations.SaikuDateProperty||
"",saikuDayFormatString:e[d].annotations.SaikuDayFormatString||""}),e[d].annotations.SaikuDayFormatString&&(a.saikuDateProperty="",a.saikuDayFormatString=e[d].annotations.SaikuDayFormatString)});return b},add_values_fixed_date:function(){var a=this;this.$el.find(".available-selections").each(function(b,c){"fixed-date"===$(c).attr("selection-name")&&($(c).find("input:radio").each(function(b,c){var f=$(c).attr("id").split("-")[1];_.find(a.dataLevels,function(b,d,k){f===b.name.toLowerCase()?$(c).val(a.dataLevels[d].analyzerDateFormat):
"yesterday"===f&&"day"===b.name.toLowerCase()&&$(c).val(a.dataLevels[d].analyzerDateFormat)})}),$(c).find("input:radio").each(function(a,b){null!==$(b).val()&&void 0!==$(b).val()&&""!==$(b).val()&&"on"!==$(b).val()||$(b).addClass("keep-disabled")}))})},add_values_last_periods:function(){var a=this;this.$el.find(".available-selections").each(function(b,c){"rolling-date"===$(c).attr("selection-name")&&($(c).find("#period-select \x3e option").each(function(b,c){var f=$(c).attr("name");_.find(a.dataLevels,
function(b,d,k){f===b.levelType&&$(c).val(a.dataLevels[d].analyzerDateFormat)})}),$(c).find("#period-select \x3e option").each(function(a,b){null!==$(b).attr("value")&&void 0!==$(b).attr("value")&&""!==$(b).attr("value")||$(b).addClass("keep-disabled")}))})},selection_date:function(a){$(a.currentTarget).datepicker({dateFormat:"yy/mm/dd"})},clear_selections:function(a){this.show_fields(a);this.$el.find('input[type\x3d"text"]').val("");this.$el.find("select").prop("selectedIndex",0);this.$el.find("#selected-date").empty();
this.$el.find(".available-selections *").prop("checked",!1);this.dates=[]},disable_divselections:function(a){var b=Array.prototype.slice.call(arguments),c=a.type?$(a.currentTarget):$(a);b[1]||this.clear_selections(a);this.$el.find(".available-selections").attr("available",!1);this.$el.find(".available-selections *").prop("disabled",!0).off("click");c.closest(".box-selections").find(".available-selections").attr("available",!0);c.closest(".box-selections").find(".available-selections *:not(.keep-disabled)").prop("disabled",
!1).on("click");a.type&&c.closest(".box-selections").find("select").each(function(a,b){$(b).find("option:not([disabled])").first().attr("selected","selected")})},day_format_string:function(){var a=this.saikuDayFormatString;return a=a.replace(/[a-zA-Z]/gi,"9")},add_selected_date:function(a){a.preventDefault();var b=$(a.currentTarget),c=this.day_format_string();a=this.$el.find("#selection-date");b=b.closest(".inline-form-group").find("#div-selected-date").find("#selected-date");""!==a.val()?(c=Saiku.toPattern(a.val(),
c),a.css("border","1px solid #ccc"),b.append($("\x3cli\x3e\x3c/li\x3e").text(c).append('\x3ca href\x3d"#" class\x3d"del-date"\x3ex\x3c/a\x3e')),this.dates.push(c)):a.css("border","1px solid red");a.val("")},del_selected_date:function(a){a.preventDefault();$(a.currentTarget).parent().remove()},populate:function(){var a=this.get_storage();if(a&&!_.isEmpty(a))if("operator"===a.type){var b=this.$el.find("#selection-radio-operator"),c=this.$el.find("#"+a.checked),d=c.parent("label").text().split(" ")[1],
e=this;b.prop("checked",!0);c.prop("checked",!0);this.disable_divselections(b,!0);this.show_fields(c);this.dates=a.values;"After"===d||"After\x26Equals"===d||"Before"===d||"Before\x26Equals"===d?this.$el.find("#selection-date").val(this.dates[0]):"Between"===d?(e.$el.find("#start-date").val(this.dates[0]),e.$el.find("#end-date").val(this.dates[1])):_.each(this.dates,function(a,b){e.$el.find("#selected-date").append($("\x3cli\x3e\x3c/li\x3e").text(a).append('\x3ca href\x3d"#" class\x3d"del-date"\x3ex\x3c/a\x3e'))})}else"fixed-date"===
a.type?(b=this.$el.find("#selection-radio-fixed-date"),b.prop("checked",!0),this.$el.find("#"+a.checked).prop("checked",!0)):(b=this.$el.find("#selection-radio-available"),b.prop("checked",!0),this.$el.find("#date-input").val(a.periodAmount),this.$el.find('select#period-select option[id\x3d"'+a.periodSelect+'"]').prop("selected",!0)),this.disable_divselections(b,!0)},populate_mdx:function(a,b,c){a.workinglevel!==a.level&&void 0!==a.workinglevel&&(a.parent="[{dimension}.{hierarchy}].[{level}].members,",
a.parent=a.parent.replace(/{(\w+)}/g,function(b,c){return a[c]}));this.template_mdx=this.template_mdx.replace(/{(\w+)}/g,function(b,c){return a[c]});if("dayperiods"===b){a.parent="[{dimension}].[{hierarchy}].[{level}]";a.parent=a.parent.replace(/{(\w+)}/g,function(b,c){return a[c]});if(1<this.dates.length){b=this.dates.length;for(c=0;c<b;c++)a.dates=this.dates[c],"\x3e|\x3c"===a.comparisonOperator?0===c?(a.comparisonOperator=a.comparisonOperator.split("|")[0],this.template_days_mdx=this.template_days_mdx.replace(/{(\w+)}/g,
function(b,c){return a[c]}),a.comparisonOperator="\x3e|\x3c"):(a.logicalOperator="AND",a.comparisonOperator=a.comparisonOperator.split("|")[1],this.template_days_mdx+=this.template_many_years_mdx.replace(/{(\w+)}/g,function(b,c){return a[c]})):0===c?this.template_days_mdx=this.template_days_mdx.replace(/{(\w+)}/g,function(b,c){return a[c]}):(a.logicalOperator="OR",this.template_days_mdx+=this.template_many_years_mdx.replace(/{(\w+)}/g,function(b,c){return a[c]}));return this.template_days_mdx+")"}a.dates=
this.dates[0];return this.template_days_mdx=this.template_days_mdx.replace(/{(\w+)}/g,function(b,c){return a[c]})+")"}return"lastperiods"===b?this.template_last_mdx=this.template_last_mdx.replace(/{(\w+)}/g,function(b,c){return a[c]}):"yesterday"!==b?this.template_mdx:this.template_mdx+".lag(1)"},save:function(a){a.preventDefault();a=$("\x3cdiv\x3eSaving...\x3c/div\x3e");$(this.el).find(".dialog_body").children().hide();$(this.el).find(".dialog_body").prepend(a);var b=this,c,d,e,f,g={};if(null===
b.hierarchy||void 0===b.hierarchy)b.hierarchy=b.dimension;this.$el.find(".available-selections").each(function(a,h){var l;if("true"===$(h).attr("available")){g.type=$(h).attr("selection-name");"operator"===$(h).attr("selection-name")?$(h).find("input:radio").each(function(a,d){if(!0===$(d).is(":checked")){var e=$(d).parent("label").text().split(" ")[1];g.checked=$(d).attr("id");"After"===e||"After\x26Equals"===e||"Before"===e||"Before\x26Equals"===e?(b.dates=[],b.dates.push(b.$el.find("#selection-date").val())):
"Between"===e&&(b.dates=[],b.dates.push(b.$el.find("#start-date").val()),b.dates.push(b.$el.find("#end-date").val()));c="dayperiods";f=$(d).val();g.values=b.dates}}):"fixed-date"===$(h).attr("selection-name")?$(h).find("input:radio").each(function(a,b){!0===$(b).is(":checked")&&(c=$(b).attr("id").split("-")[1],l=$(b).val(),g.checked=$(b).attr("id"))}):"rolling-date"===$(h).attr("selection-name")&&(l=$("#period-select").find(":selected").val(),c="lastperiods",e=$(h).find("input:text").val(),g.fixedDateName=
c,g.periodAmount=$(h).find("input:text").val(),g.periodSelect=$("#period-select").find(":selected").attr("id"));for(var m,z=0,q=b.dataLevels.length;z<q;z++)b.dataLevels[z].analyzerDateFormat===l&&(m=b.dataLevels[z].name);d=b.populate_mdx({dimension:b.dimension,hierarchy:b.hierarchy,level:b.name,parent:"",AnalyzerDateFormat:l,periodamount:e,comparisonOperator:f,saikuDateProperty:b.saikuDateProperty,workinglevel:m},c)}});var l=decodeURIComponent(this.member.hierarchy);a=decodeURIComponent(this.member.level);
l=this.workspace.query.helper.getHierarchy(l);g.name=this.name;this.set_storage(g);l&&l.levels.hasOwnProperty(a)&&(l.levels[a]={mdx:d,name:a});this.finished()},set_storage:function(a){var b=this;if(localStorage.getItem("dateFilter")){var c=JSON.parse(localStorage.getItem("dateFilter"));_.find(c,function(d,e,f){f[e].name===b.name?c[e]=a:c.push(a);localStorage.setItem("dateFilter",JSON.stringify(c))})}else c=[],c.push(a),localStorage.setItem("dateFilter",JSON.stringify(c))},get_storage:function(){var a=
this,b;if(localStorage.getItem("dateFilter")){var c=JSON.parse(localStorage.getItem("dateFilter"));_.find(c,function(c,e,f){f[e].name===a.name&&(b=f[e])})}return b},finished:function(){this.$el.dialog("destroy");this.$el.remove();this.query.run()}}),QueryToolbar=Backbone.View.extend({events:{"click .options a.button":"call","click .renderer a.button":"switch_render_button"},chart:{},render_mode:"table",spark_mode:null,initialize:function(a){this.workspace=a.workspace;_.bindAll(this,"call","activate_buttons",
"spark_bar","spark_line","render_row_viz","run_row_viz","switch_render_button");this.render_mode="table";this.spark_mode=null;this.workspace.bind("query:new",this.activate_buttons);this.workspace.bind("query:result",this.activate_buttons);this.workspace.bind("table:rendered",this.run_row_viz)},activate_buttons:function(a){"undefined"!=typeof a&&null!==a&&($(this.el).find("a").removeClass("disabled_toolbar"),a.data||$(this.el).find("a.export_button, a.stats").addClass("disabled_toolbar"),isIE&&$(this.el).find("a.export_button").addClass("disabled_toolbar"))},
template:function(){var a=$("#template-query-toolbar").html()||"";return _.template(a)()},render:function(){$(this.el).html(this.template());$(this.el).find("render_table").addClass("on");$(this.el).find("ul.table").show();return this},switch_render_button:function(a){var b=$(a.target);a.preventDefault();if($(a.target).hasClass("disabled_toolbar"))return!1;b.parent().siblings().find(".on").removeClass("on");b.hasClass("render_chart")?(this.switch_render("chart"),this.workspace.query.setProperty("saiku.ui.render.mode",
"chart"),a=0<$(this.el).find("ul.chart li a.on:first").size()?$(this.el).find("ul.chart li a.on:first").attr("href").replace("#",""):null,null!==a&&this.workspace.query.setProperty("saiku.ui.render.type",a)):(this.switch_render("table"),this.workspace.query.setProperty("saiku.ui.render.mode","table"),this.workspace.query.setProperty("saiku.ui.render.type",this.spark_mode))},switch_render:function(a){a="undefined"!=typeof a?a.toLowerCase():"table";$(this.el).find("ul.renderer a.on").removeClass("on");
$(this.el).find("ul.renderer a.render_"+a).addClass("on");"chart"==a?($(this.el).find("ul.chart").show(),$(this.el).find("ul.table").hide(),this.render_mode="chart",$(this.workspace.el).find(".workspace_results").children().hide(),$(this.workspace.chart.el).find(".canvas_wrapper").hide(),this.workspace.chart.show()):($(this.el).find("ul.chart").hide(),$(this.el).find("ul.table").show(),$(this.el).find("ul.table .stats").removeClass("on"),$(this.workspace.el).find(".workspace_results").children().hide(),
$(this.workspace.el).find(".workspace_results .table_wrapper").show(),$(this.workspace.chart.el).hide().children().hide(),this.render_mode="table",this.workspace.query.result.hasRun()&&this.workspace.table.render({data:this.workspace.query.result.lastresult()}));return!1},call:function(a){var b=$(a.target).hasClass("button")?$(a.target):$(a.target).parent();if(!b.hasClass("disabled_toolbar")){var c=b.attr("href").replace("#","");if("table"==this.render_mode&&this[c])this[c](a);else if("chart"==this.render_mode)if(b.hasClass("chartoption")&&
(b.parent().siblings().find(".chartoption.on").removeClass("on"),b.addClass("on")),"export_button"==c)this.workspace.chart[c](a);else this.workspace.chart.renderer.switch_chart(c),this.workspace.query.setProperty("saiku.ui.render.type",c)}a.preventDefault();return!1},spark_bar:function(){$(this.el).find("ul.table .spark_bar").toggleClass("on");$(this.el).find("ul.table .spark_line").removeClass("on");$(this.workspace.table.el).find("td.spark").remove();$(this.el).find("ul.table .spark_bar").hasClass("on")?
(this.spark_mode="spark_bar",this.workspace.query.setProperty("saiku.ui.render.type","spark_bar"),_.delay(this.render_row_viz,10,"spark_bar")):this.spark_mode=null},spark_line:function(){$(this.el).find("ul.table .spark_line").toggleClass("on");$(this.el).find("ul.table .spark_bar").removeClass("on");$(this.workspace.table.el).find("td.spark").remove();$(this.el).find("ul.table .spark_line").hasClass("on")?(this.spark_mode="spark_line",this.workspace.query.setProperty("saiku.ui.render.type","spark_line"),
_.delay(this.render_row_viz,10,"spark_line")):this.spark_mode=null},run_row_viz:function(a){"table"==this.render_mode&&null!==this.spark_mode&&this.render_row_viz(this.spark_mode)},render_row_viz:function(a){$(this.workspace.table.el).find("tr").each(function(b,c){var d=[];$(c).find("td.data div").each(function(a,b){var c=$(b).attr("alt"),c="undefined"!=typeof c&&""!==c&&null!==c&&"undefined"!=c?parseFloat(c):0;d.push(c)});$("\x3ctd class\x3d'data spark'\x3e\x26nbsp;\x3cdiv id\x3d'chart"+b+"'\x3e\x3c/div\x3e\x3c/td\x3e").appendTo($(c));
var e=9*d.length;if(0<d.length){var f=(new pv.Panel).canvas("chart"+b).height(12).width(e).margin(0);"spark_bar"==a?f.add(pv.Bar).data(d).left(pv.Scale.linear(0,d.length).range(0,e).by(pv.index)).height(pv.Scale.linear(0,_.max(d)).range(0,12)).width(6).bottom(0):"spark_line"==a&&(e/=2,f.width(e),f.add(pv.Line).data(d).left(pv.Scale.linear(0,d.length-1).range(0,e).by(pv.index)).bottom(pv.Scale.linear(d).range(0,12)).strokeStyle("#000").lineWidth(1));f.render()}})}}),WorkspaceToolbar=Backbone.View.extend({enabled:!1,
events:{"click a":"call"},initialize:function(a){this.workspace=a.workspace;_.bindAll(this,"call","reflect_properties","run_query","swap_axes_on_dropzones","display_drillthrough","clicked_cell_drillthrough_export","clicked_cell_drillthrough","activate_buttons","switch_to_mdx","post_mdx_transform","toggle_fields_action");this.workspace.bind("properties:loaded",this.reflect_properties);this.workspace.trigger("workspace:toolbar:render",{workspace:this.workspace});this.workspace.bind("query:new",this.activate_buttons);
this.workspace.bind("query:result",this.activate_buttons)},activate_buttons:function(a){null!==a&&a.data&&a.data.cellset&&0<a.data.cellset.length?($(a.workspace.toolbar.el).find(".button").removeClass("disabled_toolbar"),$(a.workspace.el).find("td.data").removeClass("cellhighlight").unbind("click"),$(a.workspace.el).find(".table_mode").removeClass("on")):($(a.workspace.toolbar.el).find(".button").addClass("disabled_toolbar").removeClass("on"),$(a.workspace.el).find(".fields_list .disabled_toolbar").removeClass("disabled_toolbar"),
$(a.workspace.toolbar.el).find(".new, .open, .save, .edit, .run,.auto,.non_empty,.toggle_fields,.toggle_sidebar,.switch_to_mdx, .mdx").removeClass("disabled_toolbar"));this.reflect_properties()},template:function(){var a=$("#template-workspace-toolbar").html()||"";return _.template(a)()},render:function(){$(this.el).html(this.template());return this},call:function(a){a.preventDefault();var b=a.target.hash.replace("#","");if(!$(a.target).hasClass("disabled_toolbar")&&this[b])this[b](a);return!1},reflect_properties:function(){var a=
this.workspace.query.model.properties?this.workspace.query.model.properties:Settings.QUERY_PROPERTIES;!0===a["saiku.olap.query.nonempty"]&&$(this.el).find(".non_empty").addClass("on");!0===a["saiku.olap.query.automatic_execution"]&&$(this.el).find(".auto").addClass("on");!0!==a["saiku.olap.query.drillthrough"]&&$(this.el).find(".drillthrough, .drillthrough_export").addClass("disabled_toolbar");!0!==a["org.saiku.query.explain"]&&$(this.el).find(".explain_query").addClass("disabled_toolbar");!0!==a["org.saiku.connection.scenario"]?
$(this.el).find(".query_scenario").addClass("disabled_toolbar"):($(this.el).find(".query_scenario").removeClass("disabled_toolbar"),$(this.el).find(".drillthrough, .drillthrough_export").addClass("disabled_toolbar"));"true"!=a["saiku.olap.query.limit"]&&!0!==a["saiku.olap.query.filter"]||$(this.workspace.el).find(".fields_list_header").addClass("limit");"undefined"!==this.workspace.query.getProperty("saiku.olap.result.formatter")&&"flattened"==this.workspace.query.getProperty("saiku.olap.result.formatter")&&
($(this.el).find(".group_parents").hasClass("on")||$(this.el).find(".group_parents").addClass("on"));0<$(this.workspace.el).find(".workspace_results tbody.ui-selectable").length&&$(this.el).find(".zoom_mode").addClass("on");$(this.el).find(".spark_bar, .spark_line").removeClass("on");$(this.el).find("a.edit").removeClass("disabled_toolbar");"VIEW"==Settings.MODE||this.workspace.isReadOnly?($(this.el).find("a.edit").hide(),$(this.el).find("a.save").hide()):("view"==this.workspace.viewState?$(this.el).find("a.edit").removeClass("on"):
$(this.el).find("a.edit").addClass("on"),$(this.el).find("a.edit").show("normal"))},new_query:function(a){this.workspace.switch_view_state("edit");this.workspace.new_query();return!1},edit_query:function(a){$(a.target).toggleClass("on");$(a.target).hasClass("on")?this.workspace.switch_view_state("edit"):this.workspace.switch_view_state("view")},save_query:function(a){this.workspace.query&&("undefined"!=typeof this.editor&&(a=this.editor.getValue(),this.workspace.query.model.mdx=a),(new SaveQuery({query:this.workspace.query})).render().open())},
open_query:function(a){(new OpenDialog).render().open()},run_query:function(a){this.workspace.query.run(!0)},automatic_execution:function(a){var b=!this.workspace.query.getProperty("saiku.olap.query.automatic_execution");this.workspace.query.setProperty("saiku.olap.query.automatic_execution",b);b?$(a.target).addClass("on"):$(a.target).removeClass("on")},toggle_fields:function(a){a&&$(this.el).find(".toggle_fields").toggleClass("on");$(this.el).find(".toggle_fields").hasClass("on")?this.toggle_fields_action("show"):
this.toggle_fields_action("hide")},toggle_fields_action:function(a,b){"show"==a&&$(".workspace_editor").is(":visible")||"hide"==a&&$(".workspace_editor").is(":hidden")||(b?($(".workspace_editor").css("height",""),$(".workspace_editor").is(":hidden")?$(".workspace_editor").show():$(".workspace_editor").hide()):"hide"==a?$(this.workspace.el).find(".workspace_editor").hide():$(this.workspace.el).find(".workspace_editor").show())},toggle_sidebar:function(){this.workspace.toggle_sidebar()},group_parents:function(a){$(a.target).toggleClass("on");
$(a.target).hasClass("on")?this.workspace.query.setProperty("saiku.olap.result.formatter","flattened"):this.workspace.query.setProperty("saiku.olap.result.formatter","flat");this.workspace.query.run()},non_empty:function(a){var b=!this.workspace.query.getProperty("saiku.olap.query.nonempty");this.workspace.query.helper.nonEmpty(b);this.workspace.query.setProperty("saiku.olap.query.nonempty",b);$(a.target).toggleClass("on");this.workspace.query.run()},swap_axis:function(a){$(this.workspace.el).find(".workspace_results table").html("");
this.workspace.query.helper.swapAxes();this.workspace.sync_query();this.workspace.query.run(!0)},check_modes:function(a){if("undefined"!==typeof a&&null!==a)if(0<$(this.workspace.el).find(".workspace_results tbody.ui-selectable").length&&$(this.workspace.el).find(".workspace_results tbody").selectable("destroy"),!$(a).hasClass("on"))$(this.workspace.el).find("td.data").removeClass("cellhighlight").unbind("click"),$(this.workspace.el).find(".table_mode").removeClass("on"),this.workspace.query.run();
else if($(a).hasClass("drillthrough_export"))$(this.workspace.el).find("td.data").addClass("cellhighlight").unbind("click").click(this.clicked_cell_drillthrough_export),$(this.workspace.el).find(".query_scenario, .drillthrough, .zoom_mode").removeClass("on");else if($(a).hasClass("drillthrough"))$(this.workspace.el).find("td.data").addClass("cellhighlight").unbind("click").click(this.clicked_cell_drillthrough),$(this.workspace.el).find(".query_scenario, .drillthrough_export, .zoom_mode").removeClass("on");
else if($(a).hasClass("query_scenario"))this.workspace.query.scenario.activate(),$(this.workspace.el).find(".drillthrough, .drillthrough_export, .zoom_mode").removeClass("on");else if($(a).hasClass("zoom_mode")){var b=this;$(b.workspace.el).find(".workspace_results tbody").selectable({filter:"td",stop:function(a,d){var e=[];$(b.workspace.el).find(".workspace_results").find("td.ui-selected div").each(function(a,b){var c=$(b).attr("rel");c&&e.push(c)});$(b.workspace.el).find(".workspace_results").find(".ui-selected").removeClass(".ui-selected");
e=_.uniq(e);0<e.length&&b.workspace.query.action.put("/zoomin",{success:b.workspace.sync_query,data:{selections:JSON.stringify(e)}})}});$(this.workspace.el).find(".drillthrough, .drillthrough_export").removeClass("on")}},query_scenario:function(a){$(a.target).toggleClass("on");this.check_modes($(a.target))},zoom_mode:function(a){$(a.target).toggleClass("on");this.check_modes($(a.target))},drillthrough:function(a){$(a.target).toggleClass("on");this.check_modes($(a.target))},display_drillthrough:function(a,
b){this.workspace.table.render({data:b});Saiku.ui.unblock()},export_drillthrough:function(a){$(a.target).toggleClass("on");this.check_modes($(a.target))},clicked_cell_drillthrough_export:function(a){$target=$(a.target).hasClass("data")?$(a.target).find("div"):$(a.target);a=$target.attr("rel");(new DrillthroughModal({workspace:this.workspace,maxrows:1E4,title:"Drill-Through to CSV",action:"export",position:a,query:this.workspace.query})).open()},clicked_cell_drillthrough:function(a){$target=$(a.target).hasClass("data")?
$(a.target).find("div"):$(a.target);a=$target.attr("rel");(new DrillthroughModal({workspace:this.workspace,maxrows:200,title:"Drill-Through",action:"table",success:this.display_drillthrough,position:a,query:this.workspace.query})).open()},swap_axes_on_dropzones:function(a,b){this.workspace.query.parse(b);this.workspace.unblock();this.workspace.sync_query();Saiku.ui.unblock()},show_mdx:function(a){(new MDXModal({mdx:this.workspace.query.model.mdx})).render().open()},export_xls:function(a){window.location=
Settings.REST_URL+this.workspace.query.url()+"/export/xls/"+this.workspace.query.getProperty("saiku.olap.result.formatter")},export_csv:function(a){window.location=Settings.REST_URL+this.workspace.query.url()+"/export/csv"},export_pdf:function(a){window.location=Settings.REST_URL+this.workspace.query.url()+"/export/pdf/"+this.workspace.query.getProperty("saiku.olap.result.formatter")},switch_to_mdx:function(a){var b=this;$(this.workspace.el).find(".workspace_fields").addClass("hide");$(this.el).find(".auto, .query_scenario, .buckets, .non_empty, .swap_axis, .mdx, .switch_to_mdx, .zoom_mode").parent().hide();
0<$(this.workspace.el).find(".workspace_results tbody.ui-selectable").length&&$(this.workspace.el).find(".workspace_results tbody").selectable("destroy");$(this.el).find(".run").attr("href","#run_mdx");$(this.el).find(".run, .save, .open, .new, .edit").removeClass("disabled_toolbar");if("view"!=Settings.MODE&&"table"!=Settings.MODE&&!this.workspace.isReadOnly){$mdx_editor=$(this.workspace.el).find(".mdx_input");$(this.workspace.el).find(".workspace_editor .mdx_input, .workspace_editor .editor_info, .workspace_editor").removeClass("hide").show();
this.editor=ace.edit("mdx_editor");this.editor.setShowPrintMargin(!1);this.editor.setFontSize(11);this.editor.commands.addCommand({name:"runmdx",bindKey:{win:"Ctrl-Enter",mac:"Command-Enter"},exec:function(a){b.run_mdx()},readOnly:!0});a=function(){var a=b.editor.getCursorPosition();$mdx_editor.parent().find(".editor_info").html("\x26nbsp; "+(a.row+1)+", "+a.column)};this.editor.on("changeSelection",a);a();var c=function(){var a=$(document).height()/3,a=Math.floor(a/b.editor.renderer.lineHeight),
a=((b.editor.getSession().getScreenLength()>a?a:b.editor.getSession().getScreenLength())+1)*b.editor.renderer.lineHeight+b.editor.renderer.scrollBar.getWidth();$mdx_editor.height(a.toString()+"px");b.editor.resize();b.workspace.adjust()};a=function(){var a=b.editor.session;b.editor.resize();a.setUseWrapMode(!0);if(a.getUseWrapMode()){var c=b.editor.renderer.characterWidth,f=b.editor.renderer.scroller.clientWidth;0<f&&a.setWrapLimitRange(null,parseInt(f/c,10))}};a();c();b.editor.focus();b.editor.clearSelection();
b.editor.getSession().setValue("");b.editor.getSession().on("change",c);$(window).resize(a);b.editor.on("changeSelection",c);b.editor.on("focus",function(a){c();return!0});b.editor.on("blur",function(a){100<$(b.workspace.el).find(".mdx_input").height()&&$(b.workspace.el).find(".mdx_input").height(100);b.editor.resize();b.workspace.adjust();return!0});this.editor.getSession().setMode("ace/mode/text")}this.workspace.dimension_list&&$(this.workspace.el).find(".sidebar_inner ul li a").css({fontWeight:"normal"}).parent("li").removeClass("ui-draggable ui-draggable-disabled ui-state-disabled");
this.activate_buttons({workspace:this.workspace});$(this.workspace.toolbar.el).find(".run").removeClass("disabled_toolbar");$(this.workspace.table.el).empty();this.workspace.adjust();this.post_mdx_transform()},post_mdx_transform:function(){var a=this;"MDX"!==this.workspace.query.model.type&&(this.workspace.query.model.queryModel={},this.workspace.query.model.type="MDX",this.workspace.query.setProperty("saiku.olap.result.formatter","flat"),a.workspace.query.helper.model().parameters={});var b=this.workspace.query.model.mdx;
a.editor&&(a.editor.setValue(b,0),a.editor.clearSelection(),a.editor.focus());$(a.el).find(".group_parents").removeClass("on");if(Settings.ALLOW_PARAMETERS){var c=function(){var b=a.editor.getValue(),c=[];if(b)for(var f=0,g=b.length;f<g-1;f++)if("$"===b[f]&&"{"===b[f+1]){for(var l="",k=!1,f=f+2;f<g;f++)if("}"!==b[f])l+=b[f];else{k=!0;f++;break}k&&l&&0<l.length&&c.push(l)}var h=a.workspace.query.helper.model().parameters,p={};_.each(c,function(a){p[a]=h[a]?h[a]:""});a.workspace.query.helper.model().parameters=
p;a.workspace.update_parameters()},b=function(){_.delay(c,1E3)};a.editor.getSession().off("change",b);a.editor.getSession().on("change",b);a.workspace.update_parameters()}},run_mdx:function(a){100<$(this.workspace.el).find(".mdx_input").height()&&$(this.workspace.el).find(".mdx_input").height(100);this.editor.resize();a=this.editor.getValue();this.workspace.query.model.mdx=a;this.workspace.query.run(!0)},explain_query:function(a){this.workspace.query.action.get("/explain",{success:function(a,c){var d=
"\x3ctextarea style\x3d'width: "+($("body").width()-165)+"px;height:"+($("body").height()-175)+"px;'\x3e",d=null!==c&&null!==c.error?d+c.error:c.cellset&&0===c.cellset.length?d+"Empty explain plan!":d+c.cellset[1][0].value,d=d+"\x3c/textarea\x3e";Saiku.ui.unblock();$.fancybox('\x3cdiv id\x3d"fancy_results" class\x3d"workspace_results" style\x3d"overflow:visible"\x3e\x3ctable\x3e\x3ctr\x3e\x3cth clas\x3d"row_header"\x3eExplain Plan\x3c/th\x3e\x3c/tr\x3e\x3ctr\x3e\x3ctd\x3e'+d+"\x3c/td\x3e\x3c/tr\x3e\x3c/table\x3e\x3c/div\x3e",
{autoDimensions:!1,autoScale:!1,height:$("body").height()-100,width:$("body").width()-100,transitionIn:"none",transitionOut:"none"})}});return!1}}),WorkspaceDropZone=Backbone.View.extend({template:function(){var a=$("#template-workspace-dropzones").html()||"";return _.template(a)()},events:{"sortstop .fields_list_body.details":"set_measures","sortstop .axis_fields":"select_dimension","click .d_measure":"remove_measure_click","click .d_level":"selections","click .axis_fields_header.limit":"limit_axis",
"click .clear_axis":"clear_axis"},initialize:function(a){this.workspace=a.workspace;_.bindAll(this,"clear_axis")},render:function(){var a=this;$(this.el).html(this.template());$(this.el).find(".fields_list_body.details ul.connectable").sortable({items:"\x3e li",opacityg:.6,placeholder:"placeholder",tolerance:"pointer",containment:$(a.workspace.el),start:function(a,c){c.placeholder.text(c.helper.text())}});$(this.el).find(".axis_fields ul.connectable").sortable({connectWith:$(a.el).find(".axis_fields ul.connectable"),
forcePlaceholderSize:!1,forceHelperSize:!0,items:"li.selection",opacity:.6,placeholder:"placeholder",tolerance:"touch",cursorAt:{top:10,left:60},containment:$(a.workspace.el),start:function(b,c){var d=$(c.helper).find("a").parent().parent().attr("hierarchycaption");c.placeholder.text(d);$(c.helper).css({width:"auto",height:"auto"});$(a.el).find(".axis_fields ul.hierarchy li.d_level:visible").addClass("temphide").hide()}});return this},set_measures:function(a,b){var c=[];$(this.el).find(".fields_list_body.details ul.connectable li.d_measure").each(function(a,
b){var f={name:$(b).find("a").attr("measure"),type:$(b).find("a").attr("type")};c.push(f)});this.workspace.query.helper.setMeasures(c);this.workspace.sync_query();this.workspace.query.run()},remove_measure_click:function(a){a.preventDefault();($(a.target).hasClass("d_measure")?$(a.target).find("a"):$(a.target)).parent().remove();this.set_measures()},remove_dimension:function(a,b){if($(b.helper).hasClass("d_measure"))$(b.helper).detach(),this.set_measures();else{var c=$(b.helper).find("a").attr("hierarchy");
$(this.el).find('ul.hierarchy[hierarchy\x3d"'+c+'"]').parents(".fields_list").attr("title");$(b.helper).find("a").attr("level");this.workspace.query.helper.removeHierarchy(c);this.workspace.sync_query();this.workspace.query.run()}},synchronize_query:function(){var a=this;this.reset_dropzones();var b=this.workspace.query.helper.model();if(b.hasOwnProperty("queryModel")&&b.queryModel.hasOwnProperty("axes")){var c=b.queryModel.axes,d;for(d in c){var e=$(a.el).find('.fields_list[title\x3d"'+d+'"]');_.each(c[d].hierarchies,
function(b){var c=$(a.workspace.dimension_list.el).find('ul.d_hierarchy[hierarchy\x3d"'+b.name+'"]').clone().removeClass("d_hierarchy").addClass("hierarchy");c.find("li.d_level").hide();for(var d in b.levels)c.find('li a[level\x3d"'+d+'"]').parent().show(),$(a.workspace.dimension_list.el).find('ul.d_hierarchy[hierarchy\x3d"'+b.name+'"] li a[level\x3d"'+d+'"]').parent().draggable("disable").parents(".parent_dimension").find(".folder_collapsed").addClass("selected");b=$('\x3cli class\x3d"selection"\x3e\x3c/li\x3e');
b.append(c);b.appendTo(e.find("ul.connectable"))})}_.each(b.queryModel.details.measures||[],function(b){b=$(a.workspace.dimension_list.el).find('.measure_tree a.measure[measure\x3d"'+b.name+'"]').parent();b.clone().show().appendTo($(a.el).find(".fields_list_body.details ul.connectable"));b.draggable("disable")});this.update_dropzones()}},reset_dropzones:function(){$(this.el).find(".fields_list_body ul.connectable").find("li.selection, li.d_measure").remove();$(this.workspace.dimension_list.el).find("li.ui-draggable-disabled").draggable("enable");
$(this.el).find('.fields_list[title\x3d"ROWS"] .limit').removeClass("on");$(this.el).find('.fields_list[title\x3d"COLUMNS"] .limit').removeClass("on");$(this.workspace.el).find(".fields_list_body .clear_axis").addClass("hide")},update_dropzones:function(){$(this.workspace.el).find(".fields_list_body").each(function(a,b){var c=$(b);0===c.find("ul.connectable li.selection, ul.connectable li.d_measure").length?c.siblings(".clear_axis").addClass("hide"):c.siblings(".clear_axis").removeClass("hide")})},
clear_axis:function(a){a.preventDefault();a=$(a.target).siblings(".fields_list_body").parent().attr("title");"DETAILS"==a?this.workspace.query.helper.clearMeasures():this.workspace.query.helper.clearAxis(a);this.workspace.sync_query();this.workspace.query.run();return!1},select_dimension:function(a,b){if($(b.item).is(":visible")){$(this.el).find(".axis_fields ul.hierarchy").each(function(a,b){$(b).find("li.temphide").show().removeClass("temphide")});var c=b.item.find(".level").attr("hierarchy"),d=
-1;b.item.parents("ul.connectable").find("li.selection").each(function(a,b){$(b).find("ul.hierarchy").attr("hierarchy")==c&&(d=a)});var e=b.item.parents(".axis_fields").parent().attr("title"),f=$(a.target).parents(".axis_fields").parent().attr("title");b.item.hasClass("d_level")?(f=b.item.find("a.level").attr("level"),this.workspace.query.helper.includeLevel(e,c,f,d)):this.workspace.query.helper.moveHierarchy(f,e,c,d);$(b.item).detach();this.workspace.sync_query();this.workspace.query.run()}},find_type_time:function(a,
b,c){void 0===this.workspace.metadata&&(this.workspace.metadata=Saiku.session.sessionworkspace.cube[this.workspace.selected_cube]);var d={};d.dimensions=_.findWhere(this.workspace.metadata.attributes.data.dimensions,{name:a});void 0===b&&(b=a);d.hierarchies=_.findWhere(d.dimensions.hierarchies,{name:b});if(void 0===d.hierarchies||null===d.hierarchies)d.hierarchies=_.findWhere(d.dimensions.hierarchies,{name:a+"."+b});d.level=_.findWhere(d.hierarchies.levels,{name:c});if(null===d.level||void 0===d.level)d.level=
_.findWhere(d.hierarchies.levels,{caption:c});return d},selections:function(a,b){a&&a.preventDefault();var c=$(a.target).hasClass("d_level")?$(a.target).find(".level"):$(a.target),d=c.attr("hierarchy").replace(/[\[\]]/gi,"").split(".")[0],e=c.attr("hierarchy").replace(/[\[\]]/gi,"").split(".")[1],f=c.text(),f=this.find_type_time(d,e,f),g=c.attr("href").replace("#","");void 0===f.level.annotations||null===f.level.annotations||void 0===f.level.annotations.AnalyzerDateFormat&&void 0===f.level.annotations.SaikuDayFormatString?
(new SelectionsModal({target:c,name:c.text(),key:g,workspace:this.workspace})).open():(new DateFilterModal({AnalyzerDateFormat:f.level.annotations.AnalyzerDateFormat,data:f,dimension:d,hierarchy:e,target:c,name:c.text(),key:g,workspace:this.workspace})).open();return!1},limit_axis:function(a){var b=this;if("undefined"==typeof this.workspace.query||"QUERYMODEL"!=this.workspace.query.model.type||"view"==Settings.MODE)return!1;var c=$(a.target).hasClass("limit")?$(a.target):$(a.target).parent(),d=c.siblings(".fields_list_body").parent().attr("title");
$.contextMenu("destroy",".limit");$.contextMenu({appendTo:c,selector:".limit",ignoreRightClick:!0,build:function(a,f){var g={},l=Saiku.session.sessionworkspace.cube[b.workspace.selected_cube].get("data").measures,k=b.workspace.query.helper.getAxis(d),h,p,m,z,q,t,w,s,v,A=!1,n=!1,x=!1;k&&k.filters&&_.each(k.filters,function(a){"N"==a.flavour&&(h=k["function"],p=a.expressions[0],m=a.expressions[1],x=!0);"Generic"==a.flavour&&(z=a.expressions[0],A=!0)});k&&k.sortOrder&&(q=k.sortOrder,t=k.sortEvaluationLiteral,
n=!0);k&&k.aggregators&&0<k.aggregators.length&&(v=k.aggregators[0]);null!==h&&null===m?s=h+"###SEPARATOR###"+p:null!==h&&null!==m&&null!==p&&(s="custom");n&&null!==q&&(w="customsort");_.each(l,function(a){g[a.uniqueName]={name:a.caption,payload:{n:10,sortliteral:a.uniqueName}}});var F=[];_.each(k.hierarchies,function(a){for(var b in a.levels){console.log(b);var c="",c=null!=a.levels[b].caption?a.levels[b].caption:a.levels[b].name;F[a.levels[b].name]={name:c}}});var y=function(a,b){var c={},d;for(d in a)c[b+
"###SEPARATOR###"+d]=_.clone(a[d]),c[b+"###SEPARATOR###"+d].fun=b,b==h&&m==d&&a[d].payload.n==p&&(s=b+"Quick",c[b+"###SEPARATOR###"+d].name="\x3cb\x3e"+a[d].name+"\x3c/b\x3e"),b==q&&t==d&&(w=b+"Quick",c[b+"###SEPARATOR###"+d].name="\x3cb\x3e"+a[d].name+"\x3c/b\x3e");return c},y={filter:{name:"Filter",i18n:!0,items:{customfilter:{name:"Custom...",i18n:!0},clearfilter:{name:"Clear Filter",i18n:!0}}},limit:{name:"Limit",i18n:!0,items:{"TopCount###SEPARATOR###10":{name:"Top 10",i18n:!0},"BottomCount###SEPARATOR###10":{name:"Bottom 10",
i18n:!0},TopCountQuick:{name:"Top 10 by...",i18n:!0,items:y(g,"TopCount")},BottomCountQuick:{name:"Bottom 10 by...",i18n:!0,items:y(g,"BottomCount")},customtop:{name:"Custom Limit...",i18n:!0},clearlimit:{name:"Clear Limit",i18n:!0}}},sort:{name:"Sort",i18n:!0,items:{ASCQuick:{name:"Ascending",i18n:!0,items:y(g,"ASC")},DESCQuick:{name:"Descending",i18n:!0,items:y(g,"DESC")},BASCQuick:{name:"Ascending (Breaking Hierarchy)",i18n:!0,items:y(g,"BASC")},BDESCQuick:{name:"Descending (Breaking Hierarchy)",
i18n:!0,items:y(g,"BDESC")},customsort:{name:"Custom...",i18n:!0},clearsort:{name:"Clear Sort",i18n:!0}}},grand_totals:{name:"Grand totals",i18n:!0,items:{show_totals_not:{name:"None",i18n:!0},show_totals_sum:{name:"Sum",i18n:!0},show_totals_min:{name:"Min",i18n:!0},show_totals_max:{name:"Max",i18n:!0},show_totals_avg:{name:"Avg",i18n:!0}}},parameters:{name:"Parameters",i18n:!0,items:{ParamQuick:{name:"Add Parameter",i18n:!0,items:y(F,"Param")},ParamRemove:{name:"Remove Parameter",i18n:!0,items:y(null,
"Param")}}},cancel:{name:"Cancel",i18n:!0}};$.each(y,function(a,b){recursive_menu_translate(b,Saiku.i18n.po_file)});var D=y.grand_totals.items;if(v)for(var u in D)u.substring(12)==v&&(D[u].name="\x3cb\x3e"+D[u].name+"\x3c/b");else D.show_totals_not.name="\x3cb\x3e"+D.show_totals_not.name+"\x3c/b";g["10"]={payload:{n:10}};A&&(v=y.filter,v.name="\x3cb\x3e"+v.name+"\x3c/b\x3e",v.items.customfilter.name="\x3cb\x3e"+v.items.customfilter.name+"\x3c/b\x3e");n&&(n=y.sort.items,y.sort.name="\x3cb\x3e"+y.sort.name+
"\x3c/b\x3e",w in n&&(n[w].name="\x3cb\x3e"+n[w].name+"\x3c/b\x3e"));x&&(n=y.limit.items,y.limit.name="\x3cb\x3e"+y.limit.name+"\x3c/b\x3e",s in n&&(n[s].name="\x3cb\x3e"+n[s].name+"\x3c/b\x3e"));return{callback:function(a,e){var f;if("cancel"!=a)if("clearfilter"==a)c.removeClass("on"),b.workspace.query.helper.removeFilter(k,"Generic"),b.synchronize_query(),b.workspace.query.run();else if("customfilter"==a)f=function(a){var c=[];c.push(a);b.workspace.query.helper.removeFilter(k,"Generic");k.filters.push({flavour:"Generic",
operator:null,"function":"Filter",expressions:c});b.synchronize_query();b.workspace.query.run()},(new FilterModal({axis:d,success:f,query:b.workspace.query,expression:z,expressionType:"Filter"})).render().open();else if("clearlimit"==a)c.removeClass("on"),b.workspace.query.helper.removeFilter(k,"N"),b.synchronize_query(),b.workspace.query.run();else if("customtop"==a)f=function(a,c,d){var e=[];e.push(c);d&&e.push(d);b.workspace.query.helper.removeFilter(k,"N");k.filters.push({flavour:"N",operator:null,
"function":a,expressions:e});b.synchronize_query();b.workspace.query.run()},(new CustomFilterModal({axis:d,measures:l,success:f,query:b.workspace.query,func:h,n:p,sortliteral:m})).render().open();else if("customsort"==a)f=function(a,c){k.sortOrder=a;k.sortEvaluationLiteral=c;b.synchronize_query();b.workspace.query.run()},(new FilterModal({axis:d,success:f,query:b.workspace.query,expression:t,expressionType:"Order"})).render().open();else{if("clearsort"==a)k.sortOrder=null,k.sortEvaluationLiteral=
null,alert("maybe?"),b.synchronize_query();else if(0===a.indexOf("show_totals_")){f=a.substring(12);var n=[];n.push(f);k.aggregators=n}else{f=a.split("###SEPARATOR###")[0];var v=a.split("###SEPARATOR###")[1];-1<_.indexOf(["ASC","BASC","DESC","BDESC"],f)?(k.sortOrder=f,k.sortEvaluationLiteral=g[v].payload.sortliteral):(n=[],n.push(g[v].payload.n),(v=g[v].payload.sortliteral)&&n.push(v),b.workspace.query.helper.removeFilter(k,"N"),k.filters.push({flavour:"N",operator:null,"function":f,expressions:n}));
b.synchronize_query()}b.workspace.query.run()}},items:y}}});c.contextMenu()}}),Table=Backbone.View.extend({className:"table_wrapper",events:{"click th.row":"clicked_cell","click th.col":"clicked_cell"},initialize:function(a){this.workspace=a.workspace;this.renderer=new SaikuTableRenderer;_.bindAll(this,"render","process_data");this.workspace.bind("query:result",this.render);this.id=_.uniqueId("table_");$(this.el).attr("id",this.id)},clicked_cell:function(a){var b=this;if("QM"!=this.workspace.query.get("type")||
"table"==Settings.MODE)return!1;0<$(this.workspace.el).find(".workspace_results.ui-selectable").length&&$(this.workspace.el).find(".workspace_results").selectable("destroy");a=$(a.target).hasClass("row")||$(a.target).hasClass("col")?$(a.target).find("div"):$(a.target);$(document);$.contextMenu("destroy",".row, .col");$.contextMenu({appendTo:a,selector:".row, .col",ignoreRightClick:!0,build:function(a,d){var e=$(d.currentTarget).find("div"),f=$(d.currentTarget).hasClass("rows")?"ROWS":"COLUMNS",g=
e.attr("rel").split(":"),l=parseInt(g[0]),g=parseInt(g[1]),l=b.workspace.query.result.lastresult().cellset[l][g],g=b.workspace.query,k=g.get("schema"),g=g.get("connection")+"/"+g.get("catalog")+"/"+(""===k||null===k?"null":k)+"/"+g.get("cube"),h=l.properties.dimension,p=l.properties.hierarchy,m=l.properties.level,z="",q=JSON.stringify({hierarchy:p,uniquename:m,type:"level",action:"delete"})+","+JSON.stringify({hierarchy:p,uniquename:l.properties.uniquename,type:"member",action:"add"}),l=l.properties.uniquename,
t={},k=(k=Saiku.session.sessionworkspace.cube[g])&&k.has("data")?k.get("data").dimensions:null;k||(Saiku.session.sessionworkspace.cube[g].fetch({async:!1}),k=Saiku.session.sessionworkspace.cube[g].get("data").dimensions);var w={},s=[];b.workspace.query.action.get("/axis/"+f+"/dimension/"+encodeURIComponent(h),{success:function(a,b){w=b},async:!1});_.each(w.selections,function(a){-1==_.indexOf(s,a.levelUniqueName)&&s.push(a.levelUniqueName)});_.each(k,function(a){a.name==h&&_.each(a.hierarchies,function(a){a.uniqueName==
p&&_.each(a.levels,function(a){t[a.name]={name:a.caption,payload:JSON.stringify({hierarchy:p,uniquename:a.uniqueName,type:"level",action:"add"})};-1<_.indexOf(s,a.uniqueName)&&(t[a.name].disabled=!0,t["remove-"+a.name]={name:a.caption,payload:JSON.stringify({hierarchy:p,uniquename:a.uniqueName,type:"level",action:"delete"})});a.uniqueName==m&&(z=a.caption,l_name=a.name);t["keep-"+a.name]=t[a.name];t["include-"+a.name]=JSON.parse(JSON.stringify(t[a.name]));t["keep-"+a.name].payload=q+","+t[a.name].payload})})});
t.keeponly={payload:q};t.getchildren={payload:l};t.hasOwnProperty("remove-"+l_name)&&t.hasOwnProperty("include-"+l_name)&&(t.showall={payload:t["remove-"+l_name].payload+", "+t["include-"+l_name].payload});g=function(a){var b={},c;for(c in t)null!==a&&a.length<c.length&&c.substr(0,a.length)==a&&(b[c]=t[c]);return b};e={name:{name:"\x3cb\x3e"+e.html()+"\x3c/b\x3e",disabled:!0},sep1:"---------",keeponly:{name:"Keep Only",i18n:!0,payload:q}};"Measures"!=h&&(e.getchildren={name:"Show Children",i18n:!0,
payload:l},e.fold1key={name:"Include Level",i18n:!0,items:g("include-")},e.fold2key={name:"Keep and Include Level",i18n:!0,items:g("keep-")},e.fold3key={name:"Remove Level",i18n:!0,items:g("remove-")},e.filterlevel={name:"Filter Level",i18n:!0},t.showall&&(e.showall={name:"Remove Filters",i18n:!0}));$.each(e,function(a,b){recursive_menu_translate(b,Saiku.i18n.po_file)});return{callback:function(a,c){var d="/axis/"+f+"/dimension/"+encodeURIComponent(h),e=!1;0<=a.indexOf("filterlevel")?(a=encodeURIComponent(h)+
"/hierarchy/"+encodeURIComponent(p)+"/"+encodeURIComponent(m),(new SelectionsModal({target:null,axis:f,name:z,key:a,workspace:b.workspace})).open()):(0<=a.indexOf("children")&&(d="/axis/"+f+"/dimension/"+encodeURIComponent(h)+"/children",e=!0),e&&b.workspace.query.set({formatter:"flat"}),b.workspace.query.action.put(d,{success:b.workspace.sync_query,dataType:"text",data:e?{member:t[a].payload}:{selections:"["+t[a].payload+"]"}}))},items:e}}});a.contextMenu()},render:function(a,b){"undefined"==typeof a||
"undefined"==typeof a.data||$(this.workspace.el).is(":visible")&&!$(this.el).is(":visible")||null!==a.data&&null!==a.data.error||null===a.data||a.data.height&&0===a.data.height||(this.clearOut(),$(this.el).html("Rendering "+a.data.width+" columns and "+a.data.height+" rows..."),_.delay(this.process_data,2,a.data))},clearOut:function(){this.renderer.clear();$(this.workspace.el).find(".workspace_results").unbind("scroll");var a=document.getElementById(this.id),b=a.firstChild;b&&a.removeChild(b)},process_data:function(a){this.workspace.processing.hide();
this.workspace.adjust();this.clearOut();$(this.el).html("\x3ctable\x3e\x3c/table\x3e");this.renderer.render(a,{htmlObject:$(this.el).find("table"),batch:Settings.TABLE_LAZY,batchSize:Settings.TABLE_LAZY_SIZE,batchIntervalSize:Settings.TABLE_LAZY_LOAD_ITEMS,batchIntervalTime:Settings.TABLE_LAZY_LOAD_TIME});this.post_process()},post_process:function(){"QM"==this.workspace.query.get("type")&&"view"!=Settings.MODE?$(this.el).addClass("headerhighlight"):$(this.el).removeClass("headerhighlight");$(this.el).find(".i18n").i18n(Saiku.i18n.po_file);
this.workspace.trigger("table:rendered",this)}}),Workspace=Backbone.View.extend({className:"tab_container",events:{"click .sidebar_separator":"toggle_sidebar","change .cubes":"new_query","drop .sidebar":"remove_dimension","drop .workspace_results":"remove_dimension","click .refresh_cubes":"refresh","click .cancel":"cancel","click .admin":"admin"},initialize:function(a){_.bindAll(this,"caption","adjust","toggle_sidebar","prepare","new_query","init_query","update_caption","populate_selections","refresh",
"sync_query","cancel","cancelled","no_results","error","switch_view_state");_.extend(this,Backbone.Events);this.loaded=!1;this.bind("query:result",this.render_result);this.toolbar=new WorkspaceToolbar({workspace:this});this.toolbar.render();this.upgrade=new Upgrade({workspace:this});this.upgrade.render();this.querytoolbar=new QueryToolbar({workspace:this});this.querytoolbar.render();this.drop_zones=new WorkspaceDropZone({workspace:this});this.drop_zones.render();this.table=new Table({workspace:this});
this.chart=new Chart({workspace:this});this.item={};this.viewState=a&&a.viewState?a.viewState:Settings.DEFAULT_VIEW_STATE;this.isReadOnly="view"==Settings.MODE||!1;a&&a.item&&(this.item=a.item)&&this.item.hasOwnProperty("acl")&&0>_.indexOf(this.item.acl,"WRITE")&&(this.isReadOnly=!0,this.viewState="view");a&&(a.query||a.viewState)||(this.viewState="edit");a&&a.query&&(this.query=a.query,this.query.workspace=this,this.query.save({},{success:this.init_query,error:function(){Saiku.ui.unblock();if(1>
$("body").find(".error_loading_query").length){var a=Saiku.i18n&&Saiku.i18n.po_file.error_loading_query?Saiku.i18n.po_file.error_loading_query:null;a||($('\x3cspan class\x3d"i18n error_loading_query"\x3eError Loading Query\x3c/span\x3e').hide().appendTo("body"),Saiku.i18n.translate(),a=$(".error_loading_query").text())}else a=$(".error_loading_query").text();alert(a)}}));Saiku.session.bind("tab:add",this.prepare)},caption:function(a){if(this.query&&this.query.model){if(this.item&&this.item.name)return this.item.name.split(".")[0];
if(this.query.model.mdx)return this.query.model.name}else if(this.query&&this.query.get("name"))return this.query.get("name");a&&Saiku.tabs.queryCount++;return"\x3cspan class\x3d'i18n'\x3eUnsaved query\x3c/span\x3e ("+Saiku.tabs.queryCount+")"},template:function(){var a=$("#template-workspace").html()||"";return _.template(a)({cube_navigation:Saiku.session.sessionworkspace.cube_navigation})},refresh:function(a){a&&a.preventDefault();Saiku.session.sessionworkspace.refresh()},render:function(){$(this.el).html(this.template());
this.processing=$(this.el).find(".query_processing");this.isReadOnly||Settings.MODE&&("view"==Settings.MODE||"table"==Settings.MODE||"chart"==Settings.MODE)?($(this.el).find(".workspace_editor").remove(),this.toggle_sidebar(),$(this.el).find(".sidebar_separator").remove(),$(this.el).find(".workspace_inner").css({"margin-left":0}),$(this.el).find(".workspace_fields").remove(),$(this.el).find(".sidebar").hide(),$(this.toolbar.el).find(".run, .auto, .toggle_fields, .toggle_sidebar,.switch_to_mdx, .new").parent().remove()):
($(this.el).find(".workspace_editor").append($(this.drop_zones.el)),$(this.el).find(".sidebar").droppable({accept:".d_measure, .selection"}),$(this.el).find(".workspace_results").droppable({accept:".d_measure, .selection"}));!Settings.MODE||"table"!=Settings.MODE&&"chart"!=Settings.MODE?($(this.el).find(".workspace_toolbar").append($(this.toolbar.el)),$(this.el).find(".query_toolbar").append($(this.querytoolbar.el)),$(this.el).find(".upgrade").append($(this.upgrade.el))):($(this.el).find(".workspace_toolbar").remove(),
$(this.el).find(".query_toolbar").remove());this.switch_view_state(this.viewState,!0);$(this.el).find(".workspace_results").append($(this.table.el));this.chart.render_view();this.tab.bind("tab:select",this.adjust);$(window).resize(this.adjust);Saiku.session.trigger("workspace:new",{workspace:this});if(Settings.PLUGIN&&Saiku.session.isAdmin){var a=$("\x3ca /\x3e").attr({href:"#adminconsole",title:"Admin Console"}).click(Saiku.AdminConsole.show_admin).addClass("button admin_console");$(this.el).find(".refresh_cubes_nav").css("margin-right",
"40px");$(this.el).find(".admin_console_nav").append(a)}return this},clear:function(){this.table.clearOut();$(this.el).find(".workspace_results table,.connectable").html("");$(this.el).find(".workspace_results_info").empty();$(this.el).find(".parameter_input").empty();$(this.chart.el).find("div.canvas").empty();$(this.querytoolbar.el).find("ul.options a.on").removeClass("on");$(this.el).find('.fields_list[title\x3d"ROWS"] .limit').removeClass("on");$(this.el).find('.fields_list[title\x3d"COLUMNS"] .limit').removeClass("on");
Saiku.session.trigger("workspace:clear",{workspace:this})},adjust:function(){var a=$(this.el).find(".sidebar_separator"),b=87;if(!0===Settings.PLUGIN||!0===Settings.BIPLUGIN)b=2,"table"==Settings.MODE&&(b=-5);if(0===$("#header").length||$("#header").is("hidden"))b=2;a.height($("body").height()-b);$(this.el).find(".sidebar").height($("body").height()-b);$(this.querytoolbar.el).find("div").height($("body").height()-b-10);var a=$(this.el).find(".workspace_editor").is(":hidden")?0:$(this.el).find(".workspace_editor").height(),
c=$(this.el).find(".query_processing").is(":hidden")?0:$(this.el).find(".query_processing").height()+62,d=$(this.el).find(".upgradeheader").is(":hidden")?0:$(this.el).find(".upgrade").height();$(this.el).find(".workspace_results").css({height:$("body").height()-b-$(this.el).find(".workspace_toolbar").height()-$(this.el).find(".workspace_results_info").height()-a-c-d-20});this.querytoolbar&&$(this.querytoolbar.el).find("a").tipsy({delayIn:700,fade:!0});this.toolbar&&$(this.toolbar.el).find("a").tipsy({delayIn:900,
fade:!0});this.trigger("workspace:adjust",{workspace:this})},toggle_sidebar:function(){$(this.el).find(".sidebar").toggleClass("hide");$(this.toolbar.el).find(".toggle_sidebar").toggleClass("on");var a=($(this.el).find(".sidebar").is(":visible")?$(this.el).find(".sidebar").width():0)+$(this.el).find(".sidebar_separator").width()+1;$(this.el).find(".workspace_inner").css({"margin-left":a})},prepare:function(){$(this.el).find(".cubes").parent().css({backgroundColor:"#AC1614"}).delay(300).animate({backgroundColor:"#fff"},
"slow")},new_query:function(){this.query&&(this.query.destroy(),this.query.clear(),this.query.name&&(this.query.name=void 0,this.update_caption(!0)),this.query.name=void 0);this.clear();this.processing.hide();Saiku.session.trigger("workspace:clear",{workspace:this});this.selected_cube=$(this.el).find(".cubes").val();if(!this.selected_cube)return $(this.el).find(".calculated_measures, .addMeasure").hide(),$(this.el).find(".dimension_tree").html(""),$(this.el).find(".measure_tree").html(""),!1;this.metadata=
Saiku.session.sessionworkspace.cube[this.selected_cube];for(var a=this.selected_cube.split("/"),b=a[3],c=4,d=a.length;c<d;c++)b+="/"+a[c];this.query=new Query({cube:{connection:a[0],catalog:a[1],schema:"null"==a[2]?"":a[2],name:decodeURIComponent(b)}},{workspace:this});this.query.save({},{data:{json:JSON.stringify(this.query.model)},async:!1});this.init_query()},init_query:function(a){var b=this;try{var c=this.query.model.properties?this.query.model.properties:{},d="RENDER_MODE"in Settings?Settings.RENDER_MODE:
"saiku.ui.render.mode"in c?c["saiku.ui.render.mode"]:null,e="RENDER_TYPE"in Settings?Settings.RENDER_TYPE:"saiku.ui.render.type"in c?c["saiku.ui.render.type"]:null;"table"==Settings.MODE?d="table":"chart"==Settings.MODE&&(d="chart");"undefined"!=typeof d&&null!==d&&this.querytoolbar.switch_render(d);"chart"==d?($(this.chart.el).find(".canvas_wrapper").hide(),this.chart.renderer.switch_chart(e),$(this.querytoolbar.el).find('ul.chart [href\x3d"#'+e+'"]').parent().siblings().find(".on").removeClass("on"),
$(this.querytoolbar.el).find('ul.chart [href\x3d"#'+e+'"]').addClass("on")):"table"==d&&e in this.querytoolbar&&(this.querytoolbar.render_mode="table",this.querytoolbar.spark_mode=e,$(this.querytoolbar.el).find("ul.table a."+e).addClass("on"))}catch(f){Saiku.error(this.cid,f)}"table"==Settings.MODE&&this.query?this.query.run(!0):("MDX"==this.query.model.type?(this.query.setProperty("saiku.olap.result.formatter","flat"),$(this.el).find(".sidebar").hasClass("hide")||this.toggle_sidebar(),$(this.el).find(".workspace_fields").addClass("hide"),
this.toolbar.switch_to_mdx()):($(this.el).find(".workspace_editor").removeClass("hide").show(),$(this.el).find(".workspace_fields").removeClass("disabled").removeClass("hide"),$(this.el).find(".workspace_editor .mdx_input").addClass("hide"),$(this.el).find(".workspace_editor .editor_info").addClass("hide"),$(this.toolbar.el).find(".auto, .toggle_fields, .query_scenario, .buckets, .non_empty, .swap_axis, .mdx, .switch_to_mdx, .zoom_mode").parent().show(),$(this.el).find(".run").attr("href","#run_query")),
this.adjust(),this.switch_view_state(this.viewState,!0),$(this.el).find(".sidebar").hasClass("hide")||"chart"!=Settings.MODE&&"table"!=Settings.MODE&&"view"!=Settings.MODE&&!this.isReadOnly||this.toggle_sidebar(),"view"==Settings.MODE&&this.query||this.isReadOnly?this.query.run(!0):(void 0===this.selected_cube&&(c=this.query.model.cube.schema,this.selected_cube=this.query.model.cube.connection+"/"+this.query.model.cube.catalog+"/"+(""===c||null===c?"null":c)+"/"+encodeURIComponent(this.query.model.cube.name),
$(this.el).find(".cubes").val(this.selected_cube)),this.selected_cube?(c=Saiku.session.sessionworkspace.cube[this.selected_cube],this.dimension_list=new DimensionList({workspace:this,cube:c}),this.dimension_list.render(),$(this.el).find(".metadata_attribute_wrapper").html("").append($(this.dimension_list.el)),c.has("data")||c.fetch({success:function(){b.trigger("cube:loaded")}}),this.trigger("query:new",{workspace:this})):($(this.el).find(".calculated_measures, .addMeasure").hide(),$(this.el).find(".dimension_tree").html(""),
$(this.el).find(".measure_tree").html("")),"undefined"!=typeof a&&this.query.run(!0),Saiku.i18n.translate()))},synchronize_query:function(){this.isReadOnly||Settings.hasOwnProperty("MODE")},sync_query:function(a){if("QUERYMODEL"===this.query.helper.model().type&&(a=a?a:$(this.dimension_list.el),!this.isReadOnly&&(!Settings.hasOwnProperty("MODE")||"table"!=Settings.MODE&&"view"!=Settings.MODE))){a.find(".selected").removeClass("selected");var b=this.query.helper.getCalculatedMeasures();b&&0<b.length&&
(b=_.template($("#template-calculated-measures").html(),{measures:b}),a.find(".calculated_measures").html(b),a.find(".calculated_measures").find(".measure").parent("li").draggable({cancel:".not-draggable",connectToSortable:$(this.el).find(".fields_list_body.details ul.connectable"),helper:"clone",placeholder:"placeholder",opacity:.6,tolerance:"touch",containment:$(this.el),cursorAt:{top:10,left:35}}));this.drop_zones.synchronize_query()}Saiku.i18n.translate()},populate_selections:function(a){console.log("populate_selections");
a.workspace.sync_query();return!1},update_caption:function(a){a=this.caption(a);this.tab.set_caption(a)},remove_dimension:function(a,b){"QUERYMODEL"==this.query.model.type&&this.drop_zones.remove_dimension(a,b)},update_parameters:function(){var a=this;if(Settings.ALLOW_PARAMETERS){var b="\x3cspan class\x3d'i18n'\x3eParameters\x3c/span\x3e: ",c=this.query.helper.model().parameters,d=!1,e;for(e in c)d="",c[e]&&null!==c[e]&&(d=c[e]),b+="\x3cb\x3e"+e+"\x3c/b\x3e \x3cinput type\x3d'text' placeholder\x3d'"+
e+"' value\x3d'"+d+"' /\x3e",d=!0;b+="";d?$(this.el).find(".parameter_input").html(b):$(this.el).find(".parameter_input").html("");$(this.el).find(".parameter_input input").off("change");$(this.el).find(".parameter_input input").on("change",function(b){var c=$(b.target).attr("placeholder");b=$(b.target).val();a.query.helper.model().parameters[c]=b})}},render_result:function(a){$(this.el).find(".workspace_results_info").empty();if(null!==a.data&&null!==a.data.error)return this.error(a);if(null===a.data||
a.data.cellset&&0===a.data.cellset.length)return this.no_results(a);var b=(new Date).getHours();10>b&&(b="0"+b);var c=(new Date).getMinutes();10>c&&(c="0"+c);b=b+":"+c;c=null!==a.data.runtime?(a.data.runtime/1E3).toFixed(2):"";a='\x3cb\x3e\x3cspan class\x3d"i18n"\x3eInfo:\x3c/span\x3e\x3c/b\x3e \x26nbsp;'+b+"\x26emsp;/ \x26nbsp;"+a.data.width+" x "+a.data.height+"\x26nbsp; / \x26nbsp;"+c+"s";this.update_parameters();$(this.el).find(".workspace_results_info").html(a);this.adjust()},switch_view_state:function(a,
b){var c=a||"edit";"edit"==c?(this.toolbar.toggle_fields_action("show",b),this.query&&"MDX"==this.query.get("type")&&this.toolbar.editor.gotoLine(0),$(this.el).find(".sidebar").hasClass("hide")&&this.toggle_sidebar(),$(this.toolbar.el).find(".auto, .toggle_fields, .toggle_sidebar,.switch_to_mdx, .new").parent().css({display:"block"})):"view"==c&&(this.toolbar.toggle_fields_action("hide",b),$(this.el).find(".sidebar").hasClass("hide")||this.toggle_sidebar(),$(this.toolbar.el).find(".auto, .toggle_fields, .toggle_sidebar,.switch_to_mdx").parent().hide());
this.viewState=c;$(window).trigger("resize")},block:function(a){$(this.el).block({message:'\x3cspan class\x3d"saiku_logo" style\x3d"float:left"\x3e\x26nbsp;\x26nbsp;\x3c/span\x3e '+a});Saiku.i18n.translate()},unblock:function(){isIE||$(this.el).unblock();Saiku.ui.unblock()},cancel:function(a){var b=this;a&&a.preventDefault();this.query.action.del("/cancel",{success:function(){b.cancelled()}})},admin:function(a){Saiku.AdminConsole.show_admin()},cancelled:function(a){this.processing.html('\x3cspan class\x3d"processing_image"\x3e\x26nbsp;\x26nbsp;\x3c/span\x3e \x3cspan class\x3d"i18n"\x3eCanceling Query...\x3c/span\x3e').show()},
no_results:function(a){this.processing.html('\x3cspan class\x3d"i18n"\x3eNo Results\x3c/span\x3e').show()},error:function(a){this.processing.html(safe_tags_replace(a.data.error)).show()}}),DeleteRepositoryObject=Modal.extend({type:"delete",buttons:[{text:"Yes",method:"del"},{text:"No",method:"close"}],initialize:function(a){this.options.title="Confirm deletion";this.query=a.query;this.success=a.success;this.message='\x3cspan class\x3d"i18n"\x3eAre you sure you want to delete \x3c/span\x3e\x3cspan\x3e'+
this.query.get("name")+"?\x3c/span\x3e"},del:function(){this.query.set("id",_.uniqueId("query_"));this.query.id=_.uniqueId("query_");this.query.url=this.query.url()+"?file\x3d"+encodeURIComponent(this.query.get("file"));this.query.destroy({success:this.success,dataType:"text",error:this.error,wait:!0});this.close()},error:function(){$(this.el).find("dialog_body").html('\x3cspan class\x3d"i18n"\x3eCould not delete repository object\x3c/span\x3e')}}),MoveRepositoryObject=Modal.extend({type:"save",closeText:"Move",
events:{click:"select_root_folder","click .dialog_footer a":"call","click .query":"select_name","dblclick .query":"open_query","click li.folder":"toggle_folder","keyup .search_file":"search_file","click .cancel_search":"cancel_search","click .export_btn":"export_zip","change .file":"select_file"},buttons:[{id:"test",text:"Move",method:"open_query"},{text:"Cancel",method:"close"}],initialize:function(a){var b=this;this.movefolder=a.query;this.success=a.success;this.message='\x3cbr/\x3e\x3cb\x3e\x3cdiv class\x3d\'query_name\'\x3e\x3cspan class\x3d\'i18n\'\x3ePlease select a folder.....\x3c/span\x3e\x3c/div\x3e\x3c/b\x3e\x3cbr/\x3e\x3cdiv class\x3d\'RepositoryObjects\'\x3eLoading....\x3c/div\x3e\x3cbr\x3e\x3cdiv style\x3d"height:25px; line-height:25px;"\x3e\x3cb\x3e\x3cspan class\x3d"i18n"\x3eSearch:\x3c/span\x3e\x3c/b\x3e \x26nbsp; \x3cspan class\x3d"search"\x3e\x3cinput type\x3d"text" class\x3d"search_file"\x3e\x3c/input\x3e\x3cspan class\x3d"cancel_search"\x3e\x3c/span\x3e\x3c/span\x3e\x3c/div\x3e';
_.extend(this.options,{title:"Move"});this.selected_folder=null;this.repository=new Repository({},{dialog:this});this.bind("open",function(){var a=$("body").height()/2+$("body").height()/6;420<a&&(a=420);$(this.el).find(".RepositoryObjects").height(a);$(this.el).dialog("option","position","center");$(this.el).parents(".ui-dialog").css({width:"550px"});$(this.el).find(".dialog_footer").find('a[href\x3d"#open_query"]').hide();b.repository.fetch()});_.bindAll(this,"populate","toggle_folder","select_name",
"select_file","select_folder","open_query")},populate:function(a){function b(a){_.forEach(a,function(a){"FOLDER"===a.type&&(c.queries[a.path]=a,b(a.repoObjects))})}var c=this;$(this.el).find(".RepositoryObjects").html(_.template($("#template-repository-objects").html())({repoObjects:a}));c.queries={};b(a)},select_root_folder:function(a){"name"!==$(a.target).attr("name")&&this.unselect_current_selected_folder()},toggle_folder:function(a){var b=$(a.currentTarget);this.unselect_current_selected_folder();
b.children(".folder_row").addClass("selected");var c=b.children(".folder_content");b.children(".folder_row").find(".sprite").hasClass("collapsed")?(b.children(".folder_row").find(".sprite").removeClass("collapsed"),c.removeClass("hide")):(b.children(".folder_row").find(".sprite").addClass("collapsed"),c.addClass("hide"));this.select_folder();this.select_name(a);return!1},select_name:function(a){a=$(a.currentTarget);this.unselect_current_selected_folder();a.parent().parent().has(".folder").children(".folder_row").addClass("selected");
a=a.find("a").attr("href");a=a.replace("#","");$(this.el).find(".query_name").html(a);$(this.el).find(".dialog_footer").find('a[href\x3d"#open_query"]').show();this.select_folder();return!1},unselect_current_selected_folder:function(){$(this.el).find(".selected").removeClass("selected")},select_folder:function(){var a=$(this.el).find(".selected"),a=0<a.length?a.children("a").attr("href").replace("#",""):null;if("undefined"!=typeof a&&null!==a&&""!==a){var b=$("#importForm");b.find(".directory").val(a);
var c=Settings.REST_URL+(new RepositoryZipExport).url()+"upload";b.attr("action",c);$(this.el).find(".zip_folder").text(a);this.selected_folder=a;$(this.el).find(".export_btn, .import_btn").removeAttr("disabled");this.select_file()}else $(this.el).find(".import_btn, .export_btn").attr("disabled","true")},select_file:function(){var a=$("#importForm").find(".file").val();"undefined"!=typeof a&&""!==a&&null!==a&&null!==this.selected_folder?$(this.el).find(".import_btn").removeAttr("disabled"):$(this.el).find(".import_btn").attr("disabled",
"true")},open_query:function(a){var b=$(a.currentTarget),c=$(this.el).find(".query_name").html();b.hasClass("query")&&(c=b.find("a").attr("href").replace("#",""));var d=this;(new MoveObject).save({source:this.movefolder.get("file"),target:c},{success:function(){d.close();d.success()}});a.preventDefault();return!1}}),MoveObject=Backbone.Model.extend({url:function(){return"api/repository/resource/move"}}),OpenQuery=Backbone.View.extend({className:"tab_container",events:{"click .query":"view_query",
"dblclick .query":"select_and_open_query","click .add_folder":"add_folder","click li.folder":"toggle_folder","click .workspace_toolbar a.button":"prevent_default","click .workspace_toolbar a.open":"open_query","click .workspace_toolbar a.edit":"edit_query","click .workspace_toolbar [href\x3d#edit_folder]":"edit_folder","click .workspace_toolbar [href\x3d#delete_folder]":"delete_repoObject","click .workspace_toolbar [href\x3d#delete_query]":"delete_repoObject","click .workspace_toolbar [href\x3d#edit_permissions]":"edit_permissions",
"click .queries":"click_canvas","keyup .search_file":"search_file","click .cancel_search":"cancel_search"},template:function(){return _.template($("#template-open-dialog").html())()},template_repository_objects:function(a){$(this.el).find(".sidebar ul").html(_.template($("#template-repository-objects").html())({repoObjects:a}))},caption:function(){return"Repository"},render:function(){$(this.el).html(this.template());this.tab.bind("tab:select",this.fetch_queries);this.tab.bind("tab:select",this.adjust);
$(window).resize(this.adjust);var a=this,b={open:{name:"Open",i18n:!0},edit:{name:"Edit",i18n:!0},"delete":{name:"Delete",i18n:!0},move:{name:"Move",i18n:!0},sep1:"---------","new":{name:"New Folder",i18n:!0}};$.each(b,function(a,b){recursive_menu_translate(b,Saiku.i18n.po_file)});$.contextMenu("destroy","li.query, div.folder_row");$.contextMenu({selector:"li.query, div.folder_row",events:{show:function(b){$(a.el).find(".selected").removeClass("selected");$(this).addClass("selected");var d=$(this).find("a").attr("href").replace("#",
""),d=a.queries[d];"undefined"!=typeof d.acl&&0>_.indexOf(d.acl,"WRITE")?(b.commands["delete"].disabled=!0,b.items["delete"].disabled=!0,b.commands.edit.disabled=!0,b.items.edit.disabled=!0,b.commands.move.disabled=!0,b.items.move.disabled=!0):(b.commands["delete"].disabled=!1,b.items["delete"].disabled=!1,b.commands.edit.disabled=!1,b.items.edit.disabled=!1,b.commands.move.disabled=!1,b.items.move.disabled=!1);$(this).hasClass("folder_row")?(b.commands.open.disabled=!0,b.items.open.disabled=!0):
(b.commands.open.disabled=!1,b.items.open.disabled=!1)}},callback:function(b,d){var e=$(this).find("a").attr("href").replace("#",""),f=a.queries[e];a.selected_query=new SavedQuery({file:e,name:f.name,type:f.type});"open"==b&&$(this).hasClass("query")&&a.open_query();"edit"==b&&$(this).hasClass("query")?a.edit_query():"new"==b?a.add_folder():"delete"==b?a.delete_repoObject():"move"==b&&a.move_repoObject()},items:b});return this},initialize:function(a){_.bindAll(this,"adjust","fetch_queries","clear_query",
"select_and_open_query","cancel_search","add_folder");this.repository=new Repository({},{dialog:this})},fetch_queries:function(){this.repository.fetch()},populate:function(a){function b(a){_.forEach(a,function(a){c.queries[a.path]=a;"FOLDER"===a.type&&b(a.repoObjects)})}var c=this;c.template_repository_objects(a);c.queries={};b(a)},search_file:function(a){var b=$(this.el).find(".search_file").val().toLowerCase();"undefined"==typeof b||""===b||null===b||27==a.which||9==a.which?this.cancel_search():
($(this.el).find(".search_file").val()?$(this.el).find(".cancel_search").show():$(this.el).find(".cancel_search").hide(),$(this.el).find("li.query").removeClass("hide"),$(this.el).find("li.query a").each(function(a){-1==$(this).text().toLowerCase().indexOf(b)&&$(this).parent("li.query").addClass("hide")}),$(this.el).find("li.folder").addClass("hide"),$(this.el).find("li.query").not(".hide").parents("li.folder").removeClass("hide"),$(this.el).find("li.folder .folder_row").find(".sprite").removeClass("collapsed"),
$(this.el).find("li.folder .folder_content").removeClass("hide"));return!1},cancel_search:function(a){$(this.el).find("input.search_file").val("");$(this.el).find(".cancel_search").hide();$(this.el).find("li.query, li.folder").removeClass("hide");$(this.el).find(".folder_row").find(".sprite").addClass("collapsed");$(this.el).find("li.folder .folder_content").addClass("hide");$(this.el).find(".search_file").val("").focus();$(this.el).find(".cancel_search").hide()},view_query:function(a){a.preventDefault();
a=$(a.currentTarget);var b=a.find("a");this.unselect_current_selected();a.addClass("selected");a=b.attr("href").replace("#","");var b=b.text(),c=this.queries[a];$(this.el).find(".workspace_toolbar").removeClass("hide");$(this.el).find(".for_queries").addClass("hide");$(this.el).find(".for_folder").addClass("hide");$(this.el).find(".add_folder").parent().addClass("hide");"undefined"!=typeof c.acl&&-1<_.indexOf(c.acl,"READ")&&$(this.el).find(".for_queries .open").parent().removeClass("hide");"undefined"!=
typeof c.acl&&-1<_.indexOf(c.acl,"WRITE")&&($(this.el).find(".for_queries .delete").parent().removeClass("hide"),$(this.el).find(".for_queries .edit").parent().removeClass("hide"));"undefined"!=typeof c.acl&&-1<_.indexOf(c.acl,"GRANT")&&$(this.el).find(".for_queries .edit_permissions").parent().removeClass("hide");try{var d=a.split("/");if(1<d.length){var e=d.splice(0,d.length-1).join("/"),f=this.queries[e];"undefined"!=typeof f.acl&&-1<_.indexOf(f.acl,"WRITE")&&$(this.el).find(".add_folder").parent().removeClass("hide")}else 1==
d.length&&$(this.el).find(".add_folder").parent().removeClass("hide")}catch(g){}var d=$(this.el).find(".workspace_results").html("\x3ch3\x3e\x3cstrong\x3e"+c.name+"\x3c/strong\x3e\x3c/h3\x3e"),d=$('\x3cul id\x3d"query_info" /\x3e').appendTo(d),l;for(l in c)c.hasOwnProperty(l)&&"name"!=l&&d.append($("\x3cli /\x3e").html("\x3cstrong\x3e"+l+"\x3c/strong\x3e : "+c[l]));this.selected_query=new SavedQuery({file:a,name:b,type:c.type});return!1},view_folder:function(a){var b=$(a.currentTarget).children("div").children("a");
a=b.attr("href").replace("#","");var b=b.text(),c=this.queries[a];$(this.el).find(".workspace_toolbar").removeClass("hide");$(this.el).find(".add_folder").parent().addClass("hide");$(this.el).find(".for_queries").addClass("hide");$(this.el).find(".for_folder").addClass("hide");"undefined"!=typeof c.acl&&-1<_.indexOf(c.acl,"WRITE")&&($(this.el).find(".for_folder .delete").parent().removeClass("hide"),$(this.el).find(".add_folder").parent().removeClass("hide"));"undefined"!=typeof c.acl&&-1<_.indexOf(c.acl,
"GRANT")&&$(this.el).find(".for_folder .edit_permissions").parent().removeClass("hide");$(this.el).find(".workspace_results").html("\x3ch3\x3e\x3cstrong\x3e"+b+"\x3c/strong\x3e\x3c/h3\x3e");this.selected_query=new SavedQuery({file:a,name:b,type:c.type})},prevent_default:function(a){a.preventDefault();return!1},add_folder:function(a){$selected=$(this.el).find(".selected");a="";if("undefined"!==typeof $selected&&$selected)if($selected.hasClass("folder_row"))a=$selected.children("a").attr("href"),a=
1<a.length?a.substring(1,a.length):a,a+="/";else if($selected.hasClass("query")&&!$selected.parent().hasClass("RepositoryObjects")){var b=$selected.find("a");a=b.attr("href");b=b.text();a=a.substring(1,a.length-b.length)}(new AddFolderModal({path:a,success:this.clear_query})).render().open();return!1},click_canvas:function(a){$(a.currentTarget).hasClass("sidebar")&&$(this.el).find(".selected").removeClass("selected");$(this.el).find(".add_folder").parent().removeClass("hide");return!1},toggle_folder:function(a){var b=
$(a.currentTarget);this.unselect_current_selected();b.children(".folder_row").addClass("selected");var c=b.children(".folder_content");b.children(".folder_row").find(".sprite").hasClass("collapsed")?(b.children(".folder_row").find(".sprite").removeClass("collapsed"),c.removeClass("hide")):(b.children(".folder_row").find(".sprite").addClass("collapsed"),c.addClass("hide"));this.view_folder(a);return!1},select_and_open_query:function(a){a=$(a.currentTarget).find("a");var b=a.attr("href").replace("#",
"");a.text();this.selected_query=new SavedQuery({file:b,name:b});this.open_query()},open_query:function(a){Saiku.ui.block("Opening query...");var b=this.queries[this.selected_query.get("file")],c=_.extend({file:this.selected_query.get("file"),formatter:Settings.CELLSET_FORMATTER},Settings.PARAMS),c=new Query(c,{name:this.selected_query.get("name")}),d=null;a&&!a.hasOwnProperty("currentTarget")&&(d=a);Saiku.tabs.add(new Workspace({query:c,item:b,viewState:d}));return!1},edit_query:function(){this.open_query("edit")},
delete_repoObject:function(a){(new DeleteRepositoryObject({query:this.selected_query,success:this.clear_query})).render().open();return!1},move_repoObject:function(a){(new MoveRepositoryObject({query:this.selected_query,success:this.clear_query})).render().open();return!1},edit_folder:function(a){alert("todo: edit folder properties/permissions");return!1},edit_permissions:function(a){(new PermissionsModal({workspace:this.workspace,title:"\x3cspan class\x3d'i18n'\x3ePermissions\x3c/span\x3e",file:this.selected_query.get("file")})).open()},
clear_query:function(){$(this.el).find(".workspace_toolbar").addClass("hide");$(this.el).find(".workspace_results").html("");this.fetch_queries()},adjust:function(){$separator=$(this.el).find(".sidebar_separator");$separator.height($("body").height()-87);$(this.el).find(".sidebar").css({width:300,height:$("body").height()-87});$(this.el).find(".workspace_inner").css({"margin-left":305});$(this.el).find(".workspace").css({"margin-left":-305});$(this.el).find(".workspace_results").css({width:$(document).width()-
$(this.el).find(".sidebar").width()-30,height:$(document).height()-$("#header").height()-$(this.el).find(".workspace_toolbar").height()-$(this.el).find(".workspace_fields").height()-40})},toggle_sidebar:function(){$(this.el).find(".sidebar").toggleClass("hide");var a=$(this.el).find(".sidebar").hasClass("hide")?5:265;$(this.el).find(".workspace_inner").css({"margin-left":a})},unselect_current_selected:function(){$(this.el).find(".selected").removeClass("selected")}}),SaveQuery=Modal.extend({type:"save",
closeText:"Save",events:{click:"select_root_folder","click .dialog_footer a":"call","submit form":"save","click .query":"select_name","click li.folder":"toggle_folder","keyup .search_file":"search_file","click .cancel_search":"cancel_search"},buttons:[{text:"Save",method:"save"},{text:"Cancel",method:"close"}],folder_name:null,file_name:null,initialize:function(a){var b=this,c="",d="";if(a.query.name){a.query.name=a.query.name.replace(/:/g,"/");var e=a.query.name.split("/"),d=a.query.name;this.file_name=
c=e[e.length-1];1<e.length&&(this.folder_name=e.splice(0,e.length-1).join("/"))}this.query=a.query;this.message=_.template("\x3cform id\x3d'save_query_form'\x3e\x3clabel for\x3d'name' class\x3d'i18n'\x3eFile:\x3c/label\x3e\x26nbsp;\x3cinput type\x3d'text' name\x3d'name' value\x3d'\x3c%\x3d name %\x3e' /\x3e \x3cspan class\x3d'save sprite'\x3e\x3c/span\x3e\x3cdiv class\x3d'RepositoryObjects'\x3e\x3cspan class\x3d'i18n'\x3eLoading...\x3c/span\x3e\x3c/div\x3e\x3cbr /\x3e\x3c/form\x3e\x3cdiv style\x3d\"height:25px; line-height:25px;\"\x3e\x3cb\x3e\x3cspan class\x3d\"i18n\"\x3eSearch:\x3c/span\x3e\x3c/b\x3e \x26nbsp; \x3cspan class\x3d\"search\"\x3e\x3cinput type\x3d\"text\" class\x3d\"search_file\"\x3e\x3c/input\x3e\x3cspan class\x3d\"cancel_search\"\x3e\x3c/span\x3e\x3c/span\x3e\x3c/div\x3e")({name:d});
_.extend(this.options,{title:"Save query"});this.repository=new Repository({},{dialog:this});this.bind("open",function(){var a=$("body").height()/2+$("body").height()/6;420<a&&(a=420);var c=($("body").height()-600)/2*100/$("body").height();$(this.el).find(".RepositoryObjects").height(a);$(this.el).dialog("option","position","center");$(this.el).parents(".ui-dialog").css({width:"550px",top:c+"%"});b.repository.fetch()});_.bindAll(this,"copy_to_repository","close","toggle_folder","select_name","populate",
"set_name","cancel_search");if(isIE&&9>isIE)$(this.el).find("form").on("submit",this.save)},populate:function(a){$(this.el).find(".RepositoryObjects").html(_.template($("#template-repository-objects").html())({repoObjects:a}))},select_root_folder:function(a){"name"!==$(a.target).attr("name")&&this.unselect_current_selected_folder()},toggle_folder:function(a){a=$(a.currentTarget);this.unselect_current_selected_folder();a.children(".folder_row").addClass("selected");var b=a.find("a").attr("href").replace("#",
"");this.set_name(b,null);b=a.children(".folder_content");a.children(".folder_row").find(".sprite").hasClass("collapsed")?(a.children(".folder_row").find(".sprite").removeClass("collapsed"),b.removeClass("hide")):(a.children(".folder_row").find(".sprite").addClass("collapsed"),b.addClass("hide"));return!1},set_name:function(a,b){if(null!==a){this.folder_name=a;var c=(null!==this.folder_name?this.folder_name+"/":"")+(null!==this.file_name?this.file_name:"");$(this.el).find('input[name\x3d"name"]').val(c)}null!==
b&&$(this.el).find('input[name\x3d"name"]').val(b)},search_file:function(a){var b=$(this.el).find(".search_file").val().toLowerCase();"undefined"==typeof b||""===b||null===b||27==a.which||9==a.which?this.cancel_search():($(this.el).find(".search_file").val()?$(this.el).find(".cancel_search").show():$(this.el).find(".cancel_search").hide(),$(this.el).find("li.query").removeClass("hide"),$(this.el).find("li.query a").filter(function(a){return-1==$(this).text().toLowerCase().indexOf(b)}).parent().addClass("hide"),
$(this.el).find("li.folder").addClass("hide"),$(this.el).find("li.query").not(".hide").parents("li.folder").removeClass("hide"),$(this.el).find("li.folder .folder_row").find(".sprite").removeClass("collapsed"),$(this.el).find("li.folder .folder_content").removeClass("hide"));return!1},cancel_search:function(a){$(this.el).find("input.search_file").val("");$(this.el).find(".cancel_search").hide();$(this.el).find("li.query, li.folder").removeClass("hide");$(this.el).find(".folder_row").find(".sprite").addClass("collapsed");
$(this.el).find("li.folder .folder_content").addClass("hide");$(this.el).find(".search_file").val("").focus();$(this.el).find(".cancel_search").hide()},select_name:function(a){a=$(a.currentTarget);this.unselect_current_selected_folder();a.parent().parent().has(".folder").children(".folder_row").addClass("selected");a=a.find("a").attr("href").replace("#","");this.set_name(null,a);return!1},unselect_current_selected_folder:function(){$(this.el).find(".selected").removeClass("selected")},save:function(a){var b=
$(this.el).find('input[name\x3d"name"]').val();null!==b&&0<b.length?(this.query.set({name:b,folder:""}),this.query.trigger("query:save"),this.copy_to_repository()):alert("You need to enter a name!");a.preventDefault();return!1},copy_to_repository:function(){var a=this,b=this.query.get("folder"),c=this.query.get("name"),c=6<c.length&&c.indexOf(".saiku")==c.length-6?c:c+".saiku",c=b+c;(new SavedQuery({name:this.query.get("name"),file:c,content:JSON.stringify(this.query.model)})).save({},{success:this.close,
error:function(b,c,f){c&&403==c.status&&c.responseText?alert(c.responseText):a.close();return!0},dataType:"text"})}}),OpenDialog=Modal.extend({type:"save",closeText:"Open",events:{click:"select_root_folder","click .dialog_footer a":"call","click .query":"select_name","dblclick .query":"open_query","click li.folder":"toggle_folder","keyup .search_file":"search_file","click .cancel_search":"cancel_search","click .export_btn":"export_zip","change .file":"select_file"},buttons:[{id:"test",text:"Open",
method:"open_query"},{text:"Cancel",method:"close"}],initialize:function(a){var b=this;this.message='\x3cbr/\x3e\x3cb\x3e\x3cdiv class\x3d\'query_name\'\x3e\x3cspan class\x3d\'i18n\'\x3ePlease select a file.....\x3c/span\x3e\x3c/div\x3e\x3c/b\x3e\x3cbr/\x3e\x3cdiv class\x3d\'RepositoryObjects\'\x3eLoading....\x3c/div\x3e\x3cbr\x3e\x3cdiv style\x3d"height:25px; line-height:25px;"\x3e\x3cb\x3e\x3cspan class\x3d"i18n"\x3eSearch:\x3c/span\x3e\x3c/b\x3e \x26nbsp; \x3cspan class\x3d"search"\x3e\x3cinput type\x3d"text" class\x3d"search_file"\x3e\x3c/input\x3e\x3cspan class\x3d"cancel_search"\x3e\x3c/span\x3e\x3c/span\x3e\x3c/div\x3e';
Settings.ALLOW_IMPORT_EXPORT&&(this.message+="\x3cspan class\x3d'export_zip'\x3e \x3c/span\x3e \x3cb\x3e\x3cspan class\x3d'i18n'\x3eImport or Export Files for Folder\x3c/span\x3e: \x3c/b\x3e \x3cspan class\x3d'i18n zip_folder'\x3e\x3c Select Folder... \x3e\x3c/span\x3e \x26nbsp; \x3cinput type\x3d'submit' value\x3d'Export' class\x3d'export_btn' disabled /\x3e\x3cbr/\x3e\x3cbr /\x3e\x3cbr /\x3e\x3cform id\x3d'importForm' target\x3d'_blank' method\x3d'POST' enctype\x3d'multipart/form-data'\x3e\x3cinput type\x3d'hidden' name\x3d'directory' class\x3d'directory'/\x3e\x3cinput type\x3d'file' name\x3d'file' class\x3d'file'/\x3e\x3cinput type\x3d'submit' value\x3d'Import' class\x3d'import_btn' disabled /\x3e\x3c/form\x3e");
_.extend(this.options,{title:"Open"});this.selected_folder=null;this.repository=new Repository({},{dialog:this});this.bind("open",function(){var a=$("body").height()/2+$("body").height()/6;420<a&&(a=420);var d=($("body").height()-600)/2*100/$("body").height();$(this.el).find(".RepositoryObjects").height(a);$(this.el).dialog("option","position","center");$(this.el).parents(".ui-dialog").css({width:"550px",top:d+"%"});$(this.el).find(".dialog_footer").find('a[href\x3d"#open_query"]').hide();b.repository.fetch()});
_.bindAll(this,"close","toggle_folder","select_name","populate","cancel_search","export_zip","select_folder","select_file")},populate:function(a){function b(a){_.forEach(a,function(a){c.queries[a.path]=a;"FOLDER"===a.type&&b(a.repoObjects)})}var c=this;$(this.el).find(".RepositoryObjects").html(_.template($("#template-repository-objects").html())({repoObjects:a}));c.queries={};b(a)},select_root_folder:function(a){"name"!==$(a.target).attr("name")&&this.unselect_current_selected_folder()},toggle_folder:function(a){a=
$(a.currentTarget);this.unselect_current_selected_folder();a.children(".folder_row").addClass("selected");var b=a.children(".folder_content");a.children(".folder_row").find(".sprite").hasClass("collapsed")?(a.children(".folder_row").find(".sprite").removeClass("collapsed"),b.removeClass("hide")):(a.children(".folder_row").find(".sprite").addClass("collapsed"),b.addClass("hide"));this.select_folder();return!1},select_name:function(a){a=$(a.currentTarget);this.unselect_current_selected_folder();a.parent().parent().has(".folder").children(".folder_row").addClass("selected");
a=a.find("a").attr("href");a=a.replace("#","");$(this.el).find(".query_name").html(a);$(this.el).find(".dialog_footer").find('a[href\x3d"#open_query"]').show();this.select_folder();return!1},unselect_current_selected_folder:function(){$(this.el).find(".selected").removeClass("selected")},search_file:function(a){var b=$(this.el).find(".search_file").val().toLowerCase();"undefined"==typeof b||""===b||null===b||27==a.which||9==a.which?this.cancel_search():($(this.el).find(".search_file").val()?$(this.el).find(".cancel_search").show():
$(this.el).find(".cancel_search").hide(),$(this.el).find("li.query").removeClass("hide"),$(this.el).find("li.query a").filter(function(a){return-1==$(this).text().toLowerCase().indexOf(b)}).parent().addClass("hide"),$(this.el).find("li.folder").addClass("hide"),$(this.el).find("li.query").not(".hide").parents("li.folder").removeClass("hide"),$(this.el).find("li.folder .folder_row").find(".sprite").removeClass("collapsed"),$(this.el).find("li.folder .folder_content").removeClass("hide"));return!1},
cancel_search:function(a){$(this.el).find("input.search_file").val("");$(this.el).find(".cancel_search").hide();$(this.el).find("li.query, li.folder").removeClass("hide");$(this.el).find(".folder_row").find(".sprite").addClass("collapsed");$(this.el).find("li.folder .folder_content").addClass("hide");$(this.el).find(".search_file").val("").focus();$(this.el).find(".cancel_search").hide()},export_zip:function(a){a=this.selected_folder;if("undefined"!=typeof a&&""!==a){var b=Settings.REST_URL+(new RepositoryZipExport({directory:a})).url();
window.open(b+"?directory\x3d"+a+"\x26type\x3dsaiku")}},select_folder:function(){var a=$(this.el).find(".selected"),a=0<a.length?a.children("a").attr("href").replace("#",""):null;if("undefined"!=typeof a&&null!==a&&""!==a){var b=$("#importForm");b.find(".directory").val(a);var c=Settings.REST_URL+(new RepositoryZipExport).url()+"upload";b.attr("action",c);$(this.el).find(".zip_folder").text(a);this.selected_folder=a;$(this.el).find(".export_btn, .import_btn").removeAttr("disabled");this.select_file()}else $(this.el).find(".import_btn, .export_btn").attr("disabled",
"true")},select_file:function(){var a=$("#importForm").find(".file").val();"undefined"!=typeof a&&""!==a&&null!==a&&null!==this.selected_folder?$(this.el).find(".import_btn").removeAttr("disabled"):$(this.el).find(".import_btn").attr("disabled","true")},open_query:function(a){var b=$(a.currentTarget),c=$(this.el).find(".query_name").html();b.hasClass("query")&&(c=b.find("a").attr("href").replace("#",""));new SavedQuery({file:c});this.close();Saiku.ui.block("Opening query...");var b=this.queries[c],
d=_.extend({file:c,formatter:Settings.CELLSET_FORMATTER},Settings.PARAMS),c=new Query(d,{name:c});Saiku.tabs.add(new Workspace({query:c,item:b}));a.preventDefault();return!1}}),Upgrade=Backbone.View.extend({tagName:"div",events:{},template:function(){var a=$("\x3cdiv\x3e\x3cdiv id\x3d'uphead' class\x3d'upgradeheader'\x3eYou are using Eagle BI Server.\x3c/a\x3e\x3c/div\x3e\x3c/div\x3e").html()||
"";return _.template(a)()},initialize:function(){},render:function(){(new License).fetch_license("api/license/",function(a){if("error"!==a.status)return this});var a=Saiku.session.upgradeTimeout;"undefined"!==typeof localStorage&&localStorage&&null!==localStorage.getItem("saiku.upgradeTimeout")&&(a=localStorage.getItem("saiku.upgradeTimeout"));var b=(new Date).getTime();if(!a||6E5<b-a)$(this.el).html(this.template()),Saiku.session.upgradeTimeout=b,"undefined"!==typeof localStorage&&localStorage&&
localStorage.setItem("saiku.upgradeTimeout",b);return this},call:function(a){}}),MeasuresModal=Modal.extend({type:"filter",closeText:"Save",events:{"submit form":"save","click .dialog_footer a":"call"},buttons:[{text:"OK",method:"save"},{text:"Cancel",method:"close"}],message:"\x3cform id\x3d'measure_form'\x3e\x3ctable border\x3d'0px'\x3e\x3ctr\x3e\x3ctd class\x3d'col0 i18n'\x3eName:\x3c/td\x3e\x3ctd class\x3d'col1'\x3e\x3cinput type\x3d'text' class\x3d'measure_name' value\x3d'Measure Name'\x3e\x3c/input\x3e\x3c/td\x3e\x3c/tr\x3e\x3ctr\x3e\x3ctd class\x3d'col0 i18n'\x3eFormula:\x3c/td\x3e\x3ctd class\x3d'col1'\x3e\x3ctextarea class\x3d'measureFormula'\x3eMeasures.[Store Sales] + 100\x3c/textarea\x3e\x3c/td\x3e\x3c/tr\x3e\x3ctr\x3e\x3ctd class\x3d'col0 i18n'\x3eFormat:\x3c/td\x3e\x3ctd class\x3d'col1'\x3e\x3cinput class\x3d'measure_format' type\x3d'text' value\x3d'#,##0.00'\x3e\x3c/input\x3e\x3c/td\x3e\x3c/tr\x3e\x3c/table\x3e\x3c/form\x3e",
measure:null,initialize:function(a){this.workspace=a.workspace;this.measure=a.measure;_.bindAll(this,"save");this.options.title="Calculated Measure";this.measure&&_.extend(this.options,{title:"Custom Filter for "+this.axis});this.bind("open",function(){});if(isIE&&9>isIE)$(this.el).find("form").on("submit",this.save)},save:function(a){a.preventDefault();var b=$(this.el).find(".measure_name").val(),c=$(this.el).find(".measureFormula").val();a=$(this.el).find(".measure_format").val();var d="";"undefined"!=
typeof b&&b||(d+="You have to enter a name for the measure! ");"undefined"!=typeof c&&c&&""!==c||(d+="You have to enter a MDX formula for the calculated measure! ");""!==d?alert(d):(b={name:b,formula:c,properties:{},uniqueName:"[Measures]."+b},a&&(b.properties.FORMAT_STRING=a),this.workspace.query.helper.addCalculatedMeasure(b),this.workspace.sync_query(),this.close());return!1},error:function(){$(this.el).find("dialog_body").html("Could not add new folder")}}),License=Backbone.Model.extend({initialize:function(){this.url=
"api/license";_.bindAll(this,"fetch_license")},fetch_license:function(a,b){this.fetch({success:function(a){b&&"function"===typeof b&&b({status:"success",data:a})},error:function(a){b&&"function"===typeof b&&b({status:"error",data:a})}})}}),SaikuOlapQueryTemplate={queryModel:{axes:{FILTER:{mdx:null,filters:[],sortOrder:null,sortEvaluationLiteral:null,hierarchizeMode:null,location:"FILTER",hierarchies:[],nonEmpty:!1},COLUMNS:{mdx:null,filters:[],sortOrder:null,sortEvaluationLiteral:null,hierarchizeMode:null,
location:"COLUMNS",hierarchies:[],nonEmpty:!0},ROWS:{mdx:null,filters:[],sortOrder:null,sortEvaluationLiteral:null,hierarchizeMode:null,location:"ROWS",hierarchies:[],nonEmpty:!0}},visualTotals:!1,visualTotalsPattern:null,lowestLevelsOnly:!1,details:{axis:"COLUMNS",location:"BOTTOM",measures:[]},calculatedMeasures:[]},queryType:"OLAP",type:"QUERYMODEL"},SaikuOlapQueryHelper=function(a){this.query=a};SaikuOlapQueryHelper.prototype.model=function(){return this.query.model};
SaikuOlapQueryHelper.prototype.clearAxis=function(a){this.model().queryModel.axes[a].hierarchies=[]};SaikuOlapQueryHelper.prototype.getHierarchy=function(a){var b=function(b){return b&&b.name==a},c;for(c in this.model().queryModel.axes){var d=this.model().queryModel.axes[c];if(d=_.find(d.hierarchies,b))return d}return null};
SaikuOlapQueryHelper.prototype.moveHierarchy=function(a,b,c,d){c=this.getHierarchy(c);var e=this.model().queryModel.axes[a].hierarchies.indexOf(c);b=this.model().queryModel.axes[b].hierarchies;this.model().queryModel.axes[a].hierarchies.splice(e,1);"undefined"!=typeof d&&-1<d&&b.length>d?b.splice(d,0,c):b.push(c)};
SaikuOlapQueryHelper.prototype.removeHierarchy=function(a){var b=this.getHierarchy(a);if(!b)return null;if(a=this.findAxisForHierarchy(a)){var c=a.hierarchies.indexOf(b);a.hierarchies.splice(c,1)}return b};SaikuOlapQueryHelper.prototype.findAxisForHierarchy=function(a){for(var b in this.model().queryModel.axes){var c=this.model().queryModel.axes[b];if(c.hierarchies&&0<c.hierarchies.length)for(var d=0,e=c.hierarchies.length;d<e;d++)if(c.hierarchies[d].name==a)return c}return null};
SaikuOlapQueryHelper.prototype.getAxis=function(a){if(a in this.model().queryModel.axes)return this.model().queryModel.axes[a];Saiku.log("Cannot find axis: "+a)};SaikuOlapQueryHelper.prototype.removeFilter=function(a,b){if(b&&1<a.filters.length){for(var c=-1,d=0,e=a.filters.length;d<e;d++)a.filters[d].flavour==b&&(c=d);c&&0<=c&&a.filters.splice(c,0)}else a.filters=[]};
SaikuOlapQueryHelper.prototype.includeLevel=function(a,b,c,d){var e=this.getHierarchy(b);e||(e={name:b,levels:{}});e.levels[c]={name:c};var f=this.findAxisForHierarchy(b);f?this.moveHierarchy(f.location,a,b,d):(b=this.model().queryModel.axes[a])?"undefined"!=typeof d&&-1<d&&b.hierarchies.length>d?b.hierarchies.splice(d,0,e):b.hierarchies.push(e):Saiku.log("Cannot find axis: "+a+" to include Level: "+c)};
SaikuOlapQueryHelper.prototype.removeLevel=function(a,b){(a=this.getHierarchy(a))&&a.levels.hasOwnProperty(b)&&delete a.levels[b]};SaikuOlapQueryHelper.prototype.includeMeasure=function(a){var b=this.model().queryModel.details.measures,c=b.length,d,e=!1;if(b&&!_.isEmpty(b)){for(d=0;d<c;d++)if(b[d].name===a.name){e=!0;break}else e=!1;!1===e&&b.push(a)}else b.push(a)};
SaikuOlapQueryHelper.prototype.removeMeasure=function(a){var b=this.query.model.queryModel.details.measures;(a=_.findWhere(b,{name:a}))&&-1<_.indexOf(b,a)&&_.without(b,a)};SaikuOlapQueryHelper.prototype.clearMeasures=function(){this.model().queryModel.details.measures=[]};SaikuOlapQueryHelper.prototype.setMeasures=function(a){this.model().queryModel.details.measures=a};SaikuOlapQueryHelper.prototype.addCalculatedMeasure=function(a){a&&(this.removeCalculatedMeasure(a.name),this.model().queryModel.calculatedMeasures.push(a))};
SaikuOlapQueryHelper.prototype.removeCalculatedMeasure=function(a){var b=this.model().queryModel.calculatedMeasures;(a=_.findWhere(b,{name:a}))&&-1<_.indexOf(b,a)&&_.without(b,a)};SaikuOlapQueryHelper.prototype.getCalculatedMeasures=function(){var a=this.model().queryModel.calculatedMeasures;return a?a:null};SaikuOlapQueryHelper.prototype.swapAxes=function(){var a=this.model().queryModel.axes,b=a.ROWS;b.location="COLUMNS";a.ROWS=a.COLUMNS;a.ROWS.location="ROWS";a.COLUMNS=b};
SaikuOlapQueryHelper.prototype.nonEmpty=function(a){a?(this.model().queryModel.axes.ROWS.nonEmpty=!0,this.model().queryModel.axes.COLUMNS.nonEmpty=!0):(this.model().queryModel.axes.ROWS.nonEmpty=!1,this.model().queryModel.axes.COLUMNS.nonEmpty=!1)};
var Plugin=Backbone.Model.extend({}),PluginCollection=Backbone.Collection.extend({model:Plugin,url:"info"}),RepositoryUrl="api/repository",repoPathUrl=function(){return Settings.BIPLUGIN?"pentaho/repository":RepositoryUrl},RepositoryObject=Backbone.Model.extend({url:function(){return repoPathUrl()+"/resource"}}),RepositoryAclObject=Backbone.Model.extend({url:function(){return repoPathUrl()+"/resource/acl"},parse:function(a){"OK"!=a&&_.extend(this.attributes,a)}}),RepositoryZipExport=Backbone.Model.extend({url:function(){return repoPathUrl()+
"/zip"}}),SavedQuery=Backbone.Model.extend({parse:function(a){},url:function(){return repoPathUrl()+"/resource"},move_query_to_workspace:function(a,b){var c=b,d=a.get("file"),e;for(e in Settings)if("PARAM"==e.match("^PARAM"))var f=e.substring(5,e.length),g=new RegExp("\\$\\{"+f+"\\}","g"),f=new RegExp("\\$\\{"+f.toLowerCase()+"\\}","g"),c=c.replace(g,Settings[e]),c=c.replace(f,Settings[e]);c=new Query({xml:c,formatter:Settings.CELLSET_FORMATTER},{name:d});Saiku.tabs.add(new Workspace({query:c}))}}),
Repository=Backbone.Collection.extend({model:SavedQuery,initialize:function(a,b){b&&b.dialog&&(this.dialog=b.dialog)},parse:function(a){this.dialog&&this.dialog.populate(a)},url:function(){return repoPathUrl()+"?type\x3dsaiku"}}),Result=Backbone.Model.extend({result:null,firstRun:!1,initialize:function(a,b){this.query=b.query},parse:function(a){this.query.workspace.unblock();this.query.workspace.processing.hide();this.result=a;a.error||(this.query.model=_.extend({},a.query));this.firstRun=!0;this.query.workspace.trigger("query:result",
{workspace:this.query.workspace,data:a})},hasRun:function(){return this.firstRun},lastresult:function(){return this.result},url:function(){return"api/query/execute"}}),QueryAction=Backbone.Model.extend({initialize:function(a,b){this.query=b.query;this.url=this.query.url},get:function(a,b){this.handle("fetch",a,b)},post:function(a,b){this.handle("save",a,b)},put:function(a,b){this.id=_.uniqueId("queryaction_");this.handle("save",a,b);delete this.id},del:function(a,b){this.id=_.uniqueId("queryaction_");
this.handle("delete",a,b);delete this.id},handle:function(a,b,c){this.url=this.query.url()+b;this.attributes=c.data?c.data:{};"save"==a?this.save({},c):"delete"==a?this.destroy(c):"fetch"==a&&(this.parse=function(){},this.fetch(c))}}),QueryScenario=Backbone.Model.extend({initialize:function(a,b){_.bindAll(this,"attach_listeners","activate","clicked_cell","save_writeback","cancel_writeback","check_input");this.query=b.query},activate:function(){$(this.query.workspace.el).find("td.data").unbind("click").addClass("cellhighlight").click(this.clicked_cell)},
attach_listeners:function(a){a.workspace.query&&a.workspace.query.properties&&"true"===a.workspace.query.properties.properties["org.saiku.connection.scenario"]&&$(a.workspace.el).find(".query_scenario").hasClass("on")&&$(a.workspace.el).find("td.data").click(this.clicked_cell)},clicked_cell:function(a){a=$(a.target).hasClass("data")?$(a.target).find("div"):$(a.target);var b=a.attr("alt");a.attr("rel");b=$("\x3cinput type\x3d'text' value\x3d'"+b+"' /\x3e").keyup(this.check_input).blur(this.cancel_writeback);
a.html("").append(b);b.focus()},check_input:function(a){13==a.which?this.save_writeback(a):27!=a.which&&9!=a.which||this.cancel_writeback(a);return!1},save_writeback:function(a){a=$(a.target).closest("input");this.set({value:a.val(),position:a.parent().attr("rel")});this.save();var b=a.val();a.parent().text(b)},cancel_writeback:function(a){a=$(a.target).closest("input");a.parent().text(a.parent().attr("alt"))},parse:function(){this.query.run()},url:function(){return this.query.url()+"/cell/"+this.get("position")+
"/"+this.get("value")}}),Query=Backbone.Model.extend({formatter:Settings.CELLSET_FORMATTER,properties:null,initialize:function(a,b){_.extend(this,b);_.bindAll(this,"run");this.uuid="xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=16*Math.random()|0;return("x"==a?b:b&3|8).toString(16)}).toUpperCase();this.model=_.extend({name:this.uuid},SaikuOlapQueryTemplate);a.cube&&(this.model.cube=a.cube);this.helper=new SaikuOlapQueryHelper(this);this.action=new QueryAction({},{query:this});
this.result=new Result({limit:Settings.RESULT_LIMIT},{query:this});this.scenario=new QueryScenario({},{query:this})},parse:function(a){this.id=this.uuid;a.name&&(this.uuid=this.id=a.name);this.model=_.extend(this.model,a);this.model.properties=_.extend({},Settings.QUERY_PROPERTIES,this.model.properties)},setProperty:function(a,b){this.model.properties[a]=b},getProperty:function(a){return this.model.properties[a]},run:function(a,b){var c=this;Saiku.ui.unblock();if("undefined"==typeof this.model.properties||
!1!==this.model.properties["saiku.olap.query.automatic_execution"]||!1!==a&&void 0!==a&&null!==a){this.workspace.unblock();$(this.workspace.el).find(".workspace_results_info").empty();this.workspace.trigger("query:run");this.result.result=null;var d=!1,e="Query Validation failed!",f=this.helper.model();if("OLAP"==f.queryType)if("QUERYMODEL"==f.type){var g=0<Object.keys(f.queryModel.axes.COLUMNS.hierarchies).length,l=0<Object.keys(f.queryModel.axes.ROWS.hierarchies).length,k="COLUMNS"==f.queryModel.details.axis&&
0<f.queryModel.details.measures.length;l&&g&&k||(e="");g||k||(e+='\x3cspan class\x3d"i18n"\x3eYou need to include at least one measure or a level on columns for a valid query.\x3c/span\x3e');l||(e+='\x3cspan class\x3d"i18n"\x3eYou need to include at least one level on rows for a valid query.\x3c/span\x3e');(g||k)&&l&&(d=!0)}else"MDX"==f.type&&((d=f.mdx&&0<f.mdx.length)||(e='\x3cspan class\x3d"i18n"\x3eYou need to enter some MDX statement to execute.\x3c/span\x3e'));d?(this.workspace.table.clearOut(),
$(this.workspace.processing).html('\x3cspan class\x3d"processing_image"\x3e\x26nbsp;\x26nbsp;\x3c/span\x3e \x3cspan class\x3d"i18n"\x3eRunning query...\x3c/span\x3e [\x26nbsp;\x3ca class\x3d"cancel i18n" href\x3d"#cancel"\x3eCancel\x3c/a\x3e\x26nbsp;]').show(),this.workspace.adjust(),this.workspace.trigger("query:fetch"),Saiku.i18n.translate(),this.workspace.block('\x3cspan class\x3d"processing_image"\x3e\x26nbsp;\x26nbsp;\x3c/span\x3e \x3cspan class\x3d"i18n"\x3eRunning query...\x3c/span\x3e [\x26nbsp;\x3ca class\x3d"cancel i18n" href\x3d"#cancel"\x3eCancel\x3c/a\x3e\x26nbsp;]'),
this.result.save({},{contentType:"application/json",data:JSON.stringify(f),error:function(){Saiku.ui.unblock();c.workspace.table.clearOut();$(c.workspace.processing).html('\x3cspan class\x3d"i18n"\x3eError executing query. Please check the server logs or contact your administrator!\x3c/span\x3e').show();c.workspace.adjust();Saiku.i18n.translate()}})):(this.workspace.table.clearOut(),$(this.workspace.processing).html(e).show(),this.workspace.adjust(),Saiku.i18n.translate())}},enrich:function(){var a=
this;this.workspace.query.action.post("/../enrich",{contentType:"application/json",data:JSON.stringify(a.model),async:!1,success:function(b,c){a.model=c}})},url:function(){return"api/query/"+encodeURI(this.uuid)}}),Session=Backbone.Model.extend({username:null,password:null,sessionid:null,upgradeTimeout:null,isAdmin:!1,id:null,initialize:function(a,b){_.extend(this,Backbone.Events);_.bindAll(this,"check_session","process_session","load_session","login");b&&b.username&&b.password?(this.username=b.username,
this.password=b.password,Settings.DEMO?this.check_session():this.save({username:this.username,password:this.password},{success:this.check_session,error:this.check_session})):this.check_session()},check_session:function(){null===this.sessionid||null===this.username||null===this.password?(this.clear(),this.fetch({success:this.process_session})):(this.username=encodeURIComponent(options.username),this.load_session())},load_session:function(){this.sessionworkspace=new SessionWorkspace},process_session:function(a,
b){null===b||null==b.sessionid?(Saiku.ui.unblock(),this.form=Settings.DEMO?new DemoLoginForm({session:this}):new LoginForm({session:this}),this.form.render().open()):(this.sessionid=b.sessionid,this.roles=b.roles,this.isAdmin=b.isadmin,this.username=encodeURIComponent(b.username),this.language=b.language,"undefined"!=typeof this.language&&this.language!=Saiku.i18n.locale&&(Saiku.i18n.locale=this.language,Saiku.i18n.automatic_i18n()),this.load_session());return this},error:function(){$(this.form.el).dialog("open")},
login:function(a,b){var c=this;this.save({username:a,password:b},{dataType:"text",success:this.check_session,error:function(a,b){c.login_failed(b.responseText)}})},login_failed:function(a){this.form=new LoginForm({session:this});this.form.render().open();this.form.setError(a)},logout:function(){Saiku.ui.unblock();$("#header").empty().hide();$("#tab_panel").remove();Saiku.tabs=new TabSet;Saiku.toolbar.remove();Saiku.toolbar=new Toolbar;"undefined"!==typeof localStorage&&localStorage&&localStorage.clear();
this.set("id",_.uniqueId("queryaction_"));this.destroy({async:!1});this.clear();this.roles=this.password=this.username=this.sessionid=null;this.isAdmin=!1;this.destroy({async:!1});document.location.reload(!1);delete this.id},url:function(){return"session"}}),SessionWorkspace=Backbone.Model.extend({initialize:function(a,b){_.extend(this,Backbone.Events);_.bindAll(this,"process_datasources","prefetch_dimensions");this.initialized=!1;this.first=!0;"undefined"!==typeof localStorage&&localStorage&&(Settings.LOCALSTORAGE_EXPIRATION&&
0!==Settings.LOCALSTORAGE_EXPIRATION||localStorage.clear(),localStorage.getItem("expiration")&&localStorage.getItem("expiration")<=(new Date).getTime()?localStorage.clear():localStorage.getItem("saiku-version")&&localStorage.getItem("saiku-version")===Settings.VERSION||(localStorage.clear(),localStorage.setItem("saiku-version",Settings.VERSION)));Saiku.ui.block("Loading datasources....");this.fetch({success:this.process_datasources},{})},refresh:function(){"undefined"!==typeof localStorage&&localStorage&&
localStorage.clear();this.clear();"undefined"!==typeof localStorage&&localStorage&&localStorage.setItem("saiku-version",Settings.VERSION);this.fetch({success:this.process_datasources},{})},destroy:function(){"undefined"!==typeof localStorage&&localStorage&&localStorage.clear();return!1},process_datasources:function(a,b){if("undefined"!==typeof localStorage&&localStorage&&null===localStorage.getItem("session")){localStorage.setItem("session",JSON.stringify(b));var c=(new Date).getTime()+Settings.LOCALSTORAGE_EXPIRATION;
"undefined"!==typeof localStorage&&localStorage&&localStorage.setItem("expiration",c)}this.cube_navigation=_.template($("#template-cubes").html())({connections:b});this.cube={};this.connections=b;_.delay(this.prefetch_dimensions,20);this.initialized?Settings.INITIAL_QUERY||Saiku.tabs.add(new Workspace):($(Saiku.toolbar.el).prependTo($("#header")),$("#header").show(),Saiku.ui.unblock(),Saiku.tabs.render(),Saiku.events.trigger("session:new",{session:this}),Settings.INITIAL_QUERY||Saiku.tabs.add(new SplashScreen,
!1))},prefetch_dimensions:function(){for(var a=0,b=this.connections.length;a<b;a++)for(var c=this.connections[a],d=0,e=c.catalogs.length;d<e;d++)for(var f=c.catalogs[d],g=0,l=f.schemas.length;g<l;g++)for(var k=f.schemas[g],h=0,p=k.cubes.length;h<p;h++){var m=c.name+"/"+f.name+"/"+(""===k.name||null===k.name?"null":k.name)+"/"+encodeURIComponent(k.cubes[h].name);"undefined"!==typeof localStorage&&localStorage&&null!==localStorage.getItem("cube."+m)?this.cube[m]=new Cube(JSON.parse(localStorage.getItem("cube."+
m))):(this.cube[m]=new Cube({key:m}),!0===Settings.DIMENSION_PREFETCH&&this.cube[m].fetch())}!this.initialized&&Backbone.history&&(Backbone.history.start(),this.initialized=!0)},url:function(){return this.first?(this.first=!1,encodeURI(Saiku.session.username+"/discover")):encodeURI(Saiku.session.username+"/discover/refresh")}}),Member=Backbone.Model.extend({initialize:function(a,b){this.cube=b.cube;var c=b.dimension.split("/");this.hierarchy=decodeURIComponent(c[0]);this.level=decodeURIComponent(c[1])},
url:function(){return encodeURI(Saiku.session.username+"/discover/")+this.cube+"/hierarchies/"+encodeURIComponent(this.hierarchy)+"/levels/"+encodeURIComponent(this.level)}}),Saiku={toolbar:{},tabs:new TabSet,splash:new SplashScreen,session:null,events:_.extend({},Backbone.Events),routers:[],ui:{block:function(a){$(".processing_message").html(a);$(".processing_message").removeClass("i18n_translated").addClass("i18n");Saiku.i18n.translate();$(".processing,.processing_container").show()},unblock:function(){$(".processing,.processing_container, .blockOverlay").hide();
$(".blockUI").fadeOut("slow")}},log:function(a,b){console&&console.log&&(console.log("Logging for: "+a),b&&console.log(b))},error:function(a,b){console&&console.error&&(console.error("Logging for: "+a),console.error(b))},URLParams:{buildValue:function(a){return/^\s*$/.test(a)?null:/^(true|false)$/i.test(a)?"true"===a.toLowerCase():isFinite(a)?parseFloat(a):isFinite(Date.parse(a))?new Date(a):a},equals:function(){var a=Array.prototype.slice.call(arguments),b={},c,d=window.location.search.substr(1).split("\x26");
if(1<window.location.search.length)for(var e=0;e<d.length;e++)c=d[e].split("\x3d"),b[decodeURIComponent(c[0])]=1<c.length?this.buildValue(decodeURIComponent(c[1])):null;return _.isEqual(b,a[0])?!0:!1}},loadCSS:function(a,b){var c=window.document.createElement("link"),d=window.document.getElementsByTagName("script")[0];c.rel="stylesheet";c.href=a;c.media="only x";d.parentNode.insertBefore(c,d);setTimeout(function(){c.media=b||"all"});return c},loadJS:function(a,b){var c=window.document.createElement("script"),
d=window.document.getElementsByTagName("script")[0];c.src=a;c.async=!0;d.parentNode.insertBefore(c,d);b&&"function"===typeof b&&(c.onload=b);return c},toPattern:function(a,b){var c=("object"===typeof b?b.pattern:b).split(""),d=a.toString().replace(/[^0-9a-zA-Z]/g,""),e=0,f=c.length,g;for(g=0;g<f&&!(e>=d.length);g++)if("9"===c[g]&&d[e].match(/[0-9]/)||"A"===c[g]&&d[e].match(/[a-zA-Z]/)||"S"===c[g]&&d[e].match(/[0-9a-zA-Z]/))c[g]=d[e++];else if("9"===c[g]||"A"===c[g]||"S"===c[g])c=c.slice(0,g);return c.join("").substr(0,
g)}};Saiku.singleton=function(){var a;Saiku.singleton=function(){if(a)return a;a=this;this.set=function(a){this.data=a};this.get=function(){return this.data}};return Saiku.singleton}();Backbone.emulateHTTP=!1;Settings.BIPLUGIN||$(document).ready(function(){var a=new PluginCollection;a.fetch({success:function(){var b=a.size(),c=0;a.each(function(a){c+=1;jQuery.getScript(a.attributes.path);c==b&&(Saiku.session=new Session({},{username:Settings.USERNAME,password:Settings.PASSWORD}),Saiku.toolbar=new Toolbar)})}})});
var SaikuTimeLogger=function(a){this._element=$(a);this._timestamps=[];this._events=[]};SaikuTimeLogger.prototype.log=function(a){var b=(new Date).getTime();a||(a="Unknown");if(0<this._timestamps.length){var c=this._timestamps[this._timestamps.length-1];1<b-c&&this._element.append("\x3cdiv\x3e"+(b-c)+" ms "+a+" (previous: "+this._events[this._events.length-1]+" )\x3c/div\x3e")}this._timestamps.push(b);this._events.push(a)};
(function(a){var b;a:{try{document.createElement("$")}catch(c){b=c;break a}b=void 0}a.Base64||(a.Base64={encode:function(a){for(var c,f,g,l,k,h,p=0,m=a.length,z=Math.max,q="";p<m;){c=a.charCodeAt(p++)||0;f=a.charCodeAt(p++)||0;h=a.charCodeAt(p++)||0;if(255<z(c,f,h))throw b;g=c>>2&63;c=(c&3)<<4|f>>4&15;l=(f&15)<<2|h>>6&3;k=h&63;f?h||(k=64):l=k=64;q+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\x3d".charAt(g)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\x3d".charAt(c)+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\x3d".charAt(l)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\x3d".charAt(k)}return q}})})(this);
Backbone.sync=function(a,b,c){methodMap={create:"POST",read:"GET",update:"PUT","delete":"DELETE"};var d=methodMap[a],e=Settings.REST_URL+(_.isFunction(b.url)?b.url():b.url);"undefined"==typeof Settings.ERRORS&&(Settings.ERRORS=0);var f=function(){Settings.ERRORS++;Settings.ERRORS<Settings.ERROR_TOLERANCE?Saiku.session.logout():Saiku.ui.block("Communication problem with the server. Please reload the application...")};a=!0;!1===c.async&&(a=!1);var g="json";"undefined"!=typeof c.dataType&&(g=c.dataType);
var l="application/x-www-form-urlencoded";"undefined"!=typeof c.contentType&&(l=c.contentType);b=b.attributes;"undefined"!=typeof c.data&&(b=c.data);b={url:e,type:d,cache:!1,data:b,contentType:l,dataType:g,success:function(a,b,d){Settings.ERRORS=0;Saiku.ui.unblock();c.success(a,b,d)},statusCode:{0:function(){f()},401:function(){f()}},error:function(a,b,f){!isIE&&"undefined"!=typeof console&&console&&console.error&&(console.error("Error performing "+d+" on "+e),console.error(f));c.error&&c.error(a,
b,f)},async:a};!1===c.processData&&(b.processData=!1);if(Settings.BIPLUGIN&&!Settings.BIPLUGIN5||Backbone.emulateHTTP)if("PUT"===d||"DELETE"===d)Backbone.emulateHTTP&&(b.data._method=d),b.type="POST",b.beforeSend=function(a){a.setRequestHeader("X-HTTP-Method-Override",d)};$.ajax(b)};
var QueryRouter=Backbone.Router.extend({routes:{"query/open/*query_name":"open_query","query/open":"open_query_repository"},open_query:function(a){Settings.ACTION="OPEN_QUERY";var b;b=!Settings.BIPLUGIN5&&Settings.BIPLUGIN?(Settings.GET.SOLUTION?Settings.GET.SOLUTION+"/":"")+(Settings.GET.PATH&&"/"!=Settings.GET.PATH?Settings.GET.PATH+"/":"")+(Settings.GET.ACTION||""):a;var c=_.extend({file:b},Settings.PARAMS);(new Repository({},{dialog:{populate:function(a){if(a&&0<a.length){var e=new Query(c,{name:b});
Saiku.tabs.add(new Workspace({query:e,item:a[0]}))}else Saiku.tabs.add(new Workspace);Settings.INITIAL_QUERY=!1}}})).fetch({async:!1,data:{path:b}})},open_query_repository:function(){Toolbar.prototype.open_query()}});Saiku.routers.push(new QueryRouter);