PageRenderTime 70ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/bi-platform-v2-plugin/cdf/js/CoreComponents.js

http://pentaho-cdf.googlecode.com/
JavaScript | 2490 lines | 2019 code | 338 blank | 133 comment | 600 complexity | 8c6ea25757a5eda83faa2916a57617a3 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. BaseComponent = Base.extend({
  2. //type : "unknown",
  3. visible: true,
  4. clear : function() {
  5. $("#"+this.htmlObject).empty();
  6. },
  7. getAddIn: function (slot,addIn) {
  8. return Dashboards.getAddIn(this.type,slot,addIn);
  9. },
  10. hasAddIn: function (slot,addIn) {
  11. return Dashboards.hasAddIn(this.type,slot,addIn);
  12. },
  13. getValuesArray : function() {
  14. var jXML;
  15. if ( typeof(this.valuesArray) == 'undefined' || this.valuesArray.length == 0) {
  16. if(typeof(this.queryDefinition) != 'undefined'){
  17. var vid = (this.queryDefinition.queryType == "sql")?"sql":"none";
  18. if((this.queryDefinition.queryType == "mdx") && (!this.valueAsId)){
  19. vid = "mdx";
  20. } else if (this.queryDefinition.dataAccessId !== undefined && !this.valueAsId) {
  21. vid = 'cda';
  22. }
  23. QueryComponent.makeQuery(this);
  24. var myArray = new Array();
  25. for(p in this.result) if(this.result.hasOwnProperty(p)){
  26. switch(vid){
  27. case "sql":
  28. myArray.push([this.result[p][0],this.result[p][1]]);
  29. break;
  30. case "mdx":
  31. myArray.push([this.result[p][1],this.result[p][0]]);
  32. break;
  33. case 'cda':
  34. myArray.push([this.result[p][0],this.result[p][1]]);
  35. break;
  36. default:
  37. myArray.push([this.result[p][0],this.result[p][0]]);
  38. break;
  39. }
  40. }
  41. return myArray;
  42. } else {
  43. //go through parameter array and update values
  44. var p = new Array(this.parameters?this.parameters.length:0);
  45. for(var i= 0, len = p.length; i < len; i++){
  46. var key = this.parameters[i][0];
  47. var value = this.parameters[i][1] == "" || this.parameters[i][1] == "NIL" ? this.parameters[i][2] : Dashboards.getParameterValue(this.parameters[i][1]);
  48. p[i] = [key,value];
  49. }
  50. //execute the xaction to populate the selector
  51. var myself=this;
  52. if (this.url) {
  53. var arr = {};
  54. $.each(p,function(i,val){
  55. arr[val[0]]=val[1];
  56. });
  57. jXML = Dashboards.parseXActionResult(myself, Dashboards.urlAction(this.url, arr));
  58. } else {
  59. jXML = Dashboards.callPentahoAction(myself, this.solution, this.path, this.action, p,null);
  60. }
  61. //transform the result int a javascript array
  62. var myArray = this.parseArray(jXML, false);
  63. return myArray;
  64. }
  65. } else {
  66. return this.valuesArray;
  67. }
  68. },
  69. parseArray : function(jData,includeHeader){
  70. if(jData === null){
  71. return []; //we got an error...
  72. }
  73. if($(jData).find("CdaExport").size() > 0){
  74. return this.parseArrayCda(jData, includeHeader);
  75. }
  76. var myArray = new Array();
  77. var jHeaders = $(jData).find("COLUMN-HDR-ITEM");
  78. if (includeHeader && jHeaders.size() > 0 ){
  79. var _a = new Array();
  80. jHeaders.each(function(){
  81. _a.push($(this).text());
  82. });
  83. myArray.push(_a);
  84. }
  85. var jDetails = $(jData).find("DATA-ROW");
  86. jDetails.each(function(){
  87. var _a = new Array();
  88. $(this).children("DATA-ITEM").each(function(){
  89. _a.push($(this).text());
  90. });
  91. myArray.push(_a);
  92. });
  93. return myArray;
  94. },
  95. parseArrayCda : function(jData,includeHeader){
  96. //ToDo: refactor with parseArray?..use as parseArray?..
  97. var myArray = new Array();
  98. var jHeaders = $(jData).find("ColumnMetaData");
  99. if (jHeaders.size() > 0 ){
  100. if(includeHeader){//get column names
  101. var _a = new Array();
  102. jHeaders.each(function(){
  103. _a.push($(this).attr("name"));
  104. });
  105. myArray.push(_a);
  106. }
  107. }
  108. //get contents
  109. var jDetails = $(jData).find("Row");
  110. jDetails.each(function(){
  111. var _a = new Array();
  112. $(this).children("Col").each(function(){
  113. _a.push($(this).text());
  114. });
  115. myArray.push(_a);
  116. });
  117. return myArray;
  118. },
  119. setAddInOptions: function(slot, addIn,options) {
  120. if(!this.addInOptions) {
  121. this.addInOptions = {};
  122. }
  123. if (!this.addInOptions[slot]) {
  124. this.addInOptions[slot] = {};
  125. }
  126. this.addInOptions[slot][addIn] = options
  127. },
  128. getAddInOptions: function(slot,addIn) {
  129. var opts = null;
  130. try {
  131. opts = this.addInOptions[slot][addIn];
  132. } catch (e) {
  133. /* opts is still null, no problem */
  134. }
  135. /* opts is falsy if null or undefined */
  136. return opts || {};
  137. }
  138. });
  139. var XactionComponent = BaseComponent.extend({
  140. update : function() {
  141. var myself=this;
  142. try {
  143. if (typeof(this.iframe) == 'undefined' || !this.iframe) {
  144. // go through parameter array and update values
  145. var p = new Array(this.parameters?this.parameters.length:0);
  146. for(var i= 0, len = p.length; i < len; i++){
  147. var key = this.parameters[i][0];
  148. var value = this.parameters[i][1] == "" ? this.parameters[i][2] : Dashboards.getParameterValue(this.parameters[i][1]);
  149. if(this.value == "NIL"){
  150. this.value = this.parameters[i][2];
  151. }
  152. p[i] = [key,value];
  153. }
  154. if (typeof(this.serviceMethod) == 'undefined' || this.serviceMethod == 'ServiceAction') {
  155. var jXML = Dashboards.callPentahoAction(myself,this.solution, this.path, this.action, p,null);
  156. if(jXML != null){
  157. $('#'+myself.htmlObject).html(jXML.find("ExecuteActivityResponse:first-child").text());
  158. }
  159. } else {
  160. var html = Dashboards.pentahoServiceAction(this.serviceMethod, 'html', this.solution, this.path, this.action, p, null);
  161. $('#'+myself.htmlObject).html(html);
  162. }
  163. } else {
  164. var xactionIFrameHTML = "<iframe id=\"iframe_"+ this.htmlObject + "\"" +
  165. " frameborder=\"0\"" +
  166. " height=\"100%\"" +
  167. " width=\"100%\" />";
  168. var iframe = $(xactionIFrameHTML);
  169. var url = webAppPath + "/ViewAction?wrapper=false" +
  170. "&solution=" + this.solution +
  171. "&path=" + this.path +
  172. "&action="+ this.action;
  173. // Add args
  174. var p = new Array(this.parameters.length);
  175. for(var i= 0, len = p.length; i < len; i++){
  176. var arg = "&" + encodeURIComponent(this.parameters[i][0]) + "=";
  177. var val = "";
  178. if (this.parameters[i][1] == "") {
  179. val = encodeURIComponent(this.parameters[i][2]);
  180. } else {
  181. val = encodeURIComponent(Dashboards.getParameterValue(this.parameters[i][1]));
  182. if(val == "NIL"){
  183. val = encodeURIComponent(this.parameters[i][2])
  184. }
  185. }
  186. url += arg + val;
  187. }
  188. if (!this.loading) {
  189. this.loading = true;
  190. Dashboards.incrementRunningCalls();
  191. }
  192. iframe.load(function(){
  193. if (this.contentWindow.document.body.innerHTML){
  194. myself.loading = false;
  195. Dashboards.decrementRunningCalls();
  196. }
  197. });
  198. $("#"+this.htmlObject).empty().append(iframe);
  199. iframe[0].contentWindow.location = url;
  200. }
  201. } catch (e) {
  202. // don't cause the rest of CDF to fail if xaction component fails for whatever reason
  203. }
  204. }
  205. });
  206. var SelectBaseComponent = BaseComponent.extend({
  207. visible: false,
  208. update: function () {
  209. var ph = $("#" + this.htmlObject);
  210. var myArray = this.getValuesArray(),
  211. isMultiple = false;
  212. selectHTML = "<select";
  213. // set size
  214. if (this.size != undefined) {
  215. selectHTML += " size='" + this.size + "'";
  216. }
  217. if (this.type.toLowerCase().indexOf("selectmulti") != -1) {
  218. if (typeof(this.isMultiple) == 'undefined' || this.isMultiple == true) {
  219. selectHTML += " multiple";
  220. isMultiple = true;
  221. } else
  222. if (!this.isMultiple && this.size == undefined) {
  223. selectHTML += " size='" + myArray.length + "'";
  224. }
  225. }
  226. if (this.externalPlugin == "chosen") {
  227. selectHTML += " class='chzn-select'";
  228. }
  229. selectHTML += ">";
  230. var firstVal,
  231. currentVal = Dashboards.ev(Dashboards.getParameterValue(this.parameter)),
  232. currentIsValid = false;
  233. var hasCurrentVal = typeof currentVal != undefined;
  234. //var vid = this.valueAsId == false ? false : true;
  235. var vid = !!this.valueAsId;
  236. var hasValueSelected = false;
  237. var isSelected = false;
  238. var currentValArray = [];
  239. if(currentVal instanceof Array || (typeof(currentVal) == "object" && currentVal.join)) {
  240. currentValArray = currentVal;
  241. } else if(typeof(currentVal) == "string"){
  242. currentValArray = currentVal.split("|");
  243. }
  244. for (var i = 0, len = myArray.length; i < len; i++) {
  245. if (myArray[i] != null && myArray[i].length > 0) {
  246. var ivid = vid || myArray[i][0] == null;
  247. var value, label;
  248. if (myArray[i].length > 1) {
  249. value = "" + myArray[i][ivid ? 1 : 0];
  250. label = "" + myArray[i][1];
  251. } else {
  252. value = "" + myArray[i][0];
  253. label = "" + myArray[i][0];
  254. }
  255. if (i == 0) {
  256. firstVal = value;
  257. }
  258. if (jQuery.inArray( value, currentValArray) > -1) {
  259. currentIsValid = true;
  260. }
  261. selectHTML += "<option value = '" + Dashboards.escapeHtml(value) + "' >" + Dashboards.escapeHtml(label) + "</option>";
  262. }
  263. }
  264. selectHTML += "</select>";
  265. ph.html(selectHTML);
  266. /* If the current value for the parameter is invalid or empty, we need
  267. * to pick a sensible default. If there is a defaultIfEmpty value,
  268. * we use that; otherwise, we use the first value in the selector.
  269. * An "invalid" value is, of course, one that's not in the values array.
  270. */
  271. if (isMultiple ? !currentIsValid && currentVal !== '' : !currentIsValid) {
  272. var replacementValue = (this.defaultIfEmpty)? firstVal : null;
  273. $("select", ph).val(replacementValue);
  274. Dashboards.setParameter(this.parameter,replacementValue);
  275. Dashboards.processChange(this.name);
  276. } else {
  277. $("select", ph).val(currentValArray);
  278. }
  279. if( this.externalPlugin == "chosen" ){
  280. ph.find("select.chzn-select").chosen();
  281. }
  282. var myself = this;
  283. $("select", ph).change(function () {
  284. Dashboards.processChange(myself.name);
  285. });
  286. }
  287. });
  288. var SelectComponent = SelectBaseComponent.extend({
  289. defaultIfEmpty: true,
  290. getValue : function() {
  291. return $("#"+this.htmlObject + " select").val();
  292. }
  293. });
  294. var SelectMultiComponent = SelectBaseComponent.extend({
  295. getValue : function() {
  296. return $("#"+this.htmlObject + " select").val();
  297. }
  298. });
  299. var JFreeChartComponent = BaseComponent.extend({
  300. update : function() {
  301. var xactionFile = (this.chartDefinition.queryType == 'cda')? "jfreechart-cda.xaction" : "jfreechart.xaction";
  302. this.callPentahoAction(xactionFile);
  303. },
  304. getParameters: function() {
  305. var cd = this.chartDefinition;
  306. // Merge the stuff with a chartOptions element
  307. if (cd == undefined){
  308. Dashboards.log("Fatal - No chartDefinition passed","error");
  309. return;
  310. }
  311. // If the user filled titleKey get the title value from language files
  312. if (typeof cd.titleKey !== "undefined" && typeof Dashboards.i18nSupport !== "undefined" && Dashboards.i18nSupport != null) {
  313. cd.title = Dashboards.i18nSupport.prop(cd.titleKey);
  314. }
  315. //set parameters string if using cda
  316. var cdaParameterString = null;
  317. if(cd.queryType == "cda"){
  318. if ($.isArray(this.parameters)){
  319. var param;
  320. for(var i = 0; i < this.parameters.length; i++){
  321. param = this.parameters[i];
  322. if($.isArray(param) && param.length >= 2){
  323. var name = param[0];
  324. var value = param[1]; //TODO: in pho dashboard designer static parameters may be in the form [["name", "", "value" ] ... ]
  325. if(value){
  326. value = doCsvQuoting(value, '='); //quote if needed for '='
  327. }
  328. if(i == 0) cdaParameterString = "";
  329. else cdaParameterString += ";";
  330. cdaParameterString += doCsvQuoting(name + "=" + value, ';'); //re-quote for ';'
  331. }
  332. }
  333. }
  334. }
  335. var cd0 = cd.chartOptions != undefined ? $.extend({},Dashboards.ev(cd.chartOptions), cd) : cd;
  336. // go through parameters array and update values
  337. var parameters = [];
  338. for(p in cd0){
  339. var key = p;
  340. var value = typeof cd0[p]=='function'?cd0[p]():cd0[p];
  341. // alert("key: " + key + "; Value: " + value);
  342. parameters.push([key,value]);
  343. }
  344. if(cdaParameterString != null){
  345. parameters.push(["cdaParameterString", cdaParameterString]);
  346. }
  347. return parameters;
  348. },
  349. callPentahoAction: function(action) {
  350. // increment runningCalls
  351. Dashboards.incrementRunningCalls();
  352. var myself = this;
  353. // callback async mode
  354. Dashboards.callPentahoAction(myself,"cdf", "components", action, this.getParameters(),function(jXML){
  355. if(jXML != null){
  356. if(myself.chartDefinition.caption != undefined){
  357. myself.buildCaptionWrapper($(jXML.find("ExecuteActivityResponse:first-child").text()),action);
  358. }
  359. else {
  360. $('#'+myself.htmlObject).html(jXML.find("ExecuteActivityResponse:first-child").text());
  361. }
  362. }
  363. Dashboards.decrementRunningCalls();
  364. });
  365. },
  366. buildCaptionWrapper: function(chart,cdfComponent){
  367. var exportFile = function(type,cd){
  368. var xactionFile = (cd.queryType == 'cda')? "jtable-cda.xaction" : "jtable.xaction";
  369. var obj = $.extend({
  370. solution: "cdf",
  371. path: "components",
  372. action: xactionFile,
  373. exportType: type
  374. },cd);
  375. Dashboards.post(webAppPath + '/content/pentaho-cdf/Export',obj);
  376. };
  377. var myself = this;
  378. var cd = myself.chartDefinition;
  379. var captionOptions = $.extend({
  380. title:{
  381. title: cd.title != undefined ? cd.title : "Details",
  382. oclass: 'title'
  383. },
  384. chartType:{
  385. title: "Chart Type",
  386. show: function(){
  387. return cd.chartType != 'function' && ( cd.chartType == "BarChart" || cd.chartType == "PieChart")
  388. },
  389. icon: function(){
  390. return cd.chartType == "BarChart" ? webAppPath + '/content/pentaho-cdf/resources/style/images/pie_icon.png': webAppPath + '/content/pentaho-cdf/resources/style/images/bar_icon.png';
  391. },
  392. oclass: 'options',
  393. callback: function(){
  394. cd.chartType = cd.chartType == "BarChart" ? "PieChart" : "BarChart";
  395. myself.update();
  396. }
  397. },
  398. excel: {
  399. title: "Excel",
  400. icon: webAppPath + '/content/pentaho-cdf/resources/style/images/excel_icon.png',
  401. oclass: 'options',
  402. callback: function(){
  403. exportFile("excel",cd);
  404. }
  405. },
  406. csv: {
  407. title: "CSV",
  408. icon: webAppPath + '/content/pentaho-cdf/resources/style/images/csv_icon.gif',
  409. oclass: 'options',
  410. callback: function(){
  411. exportFile("csv",cd);
  412. }
  413. },
  414. zoom: {
  415. title:'Zoom',
  416. icon: webAppPath + '/content/pentaho-cdf/resources/style/images/magnify.png',
  417. oclass: 'options',
  418. callback: function(){
  419. Dashboards.incrementRunningCalls();
  420. var parameters = myself.getParameters();
  421. var width = 200,height = 200;
  422. var urlTemplate,parameterName = "";
  423. for(p in parameters){
  424. if(parameters[p][0] == 'width'){
  425. width += parameters[p][1];
  426. parameters[p] = ['width',width]
  427. };
  428. if(parameters[p][0] == 'height'){
  429. height += parameters[p][1];
  430. parameters[p] = ['height',height]
  431. };
  432. if(parameters[p][0] == 'parameterName'){
  433. parameterName = parameters[p][1];
  434. parameters[p] = ['parameterName','parameterValue']
  435. };
  436. if(parameters[p][0] == 'urlTemplate'){
  437. urlTemplate = parameters[p][1];
  438. parameters[p] = ['urlTemplate',"javascript:chartClick('" + myself.name +"','{parameterValue}');"]
  439. };
  440. }
  441. myself.zoomCallBack = function(value){
  442. eval(urlTemplate.replace("{" + parameterName + "}",value));
  443. };
  444. Dashboards.callPentahoAction(myself,"cdf", "components", cdfComponent, parameters,function(jXML){
  445. if(jXML != null){
  446. var openWindow = window.open(webAppPath + "/content/pentaho-cdf/js/captify/zoom.html","_blank",'width=' + (width+10) + ',height=' + (height+10));
  447. var maxTries = 10;
  448. var loadChart = function(){
  449. if(openWindow.loadChart != undefined)openWindow.loadChart(jXML.find("ExecuteActivityResponse:first-child").text())
  450. else if(maxTries> 0) {
  451. maxTries-=1;
  452. setTimeout(loadChart,500);
  453. }
  454. };
  455. loadChart();
  456. }
  457. Dashboards.decrementRunningCalls();
  458. });
  459. }
  460. },
  461. details:{
  462. title:'Details',
  463. icon:webAppPath + '/content/pentaho-cdf/resources/style/images/table.png',
  464. oclass: 'options',
  465. callback: function(){
  466. myself.pivotDefinition = {
  467. jndi: cd.jndi,
  468. catalog:cd.catalog,
  469. query:cd.query
  470. };
  471. PivotLinkComponent.openPivotLink(myself);
  472. }
  473. }
  474. }, cd.caption);
  475. var captionId = myself.htmlObject + 'caption';
  476. var caption = $('<div id="' + captionId + '" ></div>');
  477. chart.attr("id",myself.htmlObject + 'image');
  478. chart.attr("rel",myself.htmlObject + "caption");
  479. chart.attr("class","captify");
  480. for(o in captionOptions){
  481. var show = captionOptions[o].show == undefined || (typeof captionOptions[o].show=='function'?captionOptions[o].show():captionOptions[o].show) ? true : false;
  482. if (this.chartDefinition.queryType != "mdx" && captionOptions[o].title == "Details") {
  483. show = false;
  484. };
  485. if(show){
  486. var icon = captionOptions[o].icon != undefined ? (typeof captionOptions[o].icon=='function'?captionOptions[o].icon():captionOptions[o].icon) : undefined;
  487. var op = icon != undefined ? $('<image id ="' + captionId + o + '" src = "' + icon + '"></image>') : $('<span id ="' + captionId + o + '">' + captionOptions[o].title +'</span>');
  488. op.attr("class",captionOptions[o].oclass != undefined ? captionOptions[o].oclass : "options");
  489. op.attr("title",captionOptions[o].title);
  490. caption.append(op);
  491. }
  492. };
  493. $("#" + myself.htmlObject).empty();
  494. var bDetails = $('<div class="caption-details">Details</div>');
  495. $("#" + myself.htmlObject).append(bDetails);
  496. $("#" + myself.htmlObject).append(chart);
  497. $("#" + myself.htmlObject).append(caption);
  498. $('img.captify').captify($.extend({
  499. bDetails:bDetails,
  500. spanWidth: '95%',
  501. hideDelay:3000,
  502. hasButton:false,
  503. opacity:'0.5'
  504. }, cd.caption));
  505. //Add events after captify has finished.
  506. bDetails.one('capityFinished',function(e,wrapper){
  507. var chartOffset = chart.offset();
  508. var bDetailsOffset = bDetails.offset();
  509. if(chart.length > 1){
  510. bDetails.bind("mouseenter",function(){
  511. $("#" + myself.htmlObject + 'image').trigger('detailsClick',[this]);
  512. });
  513. bDetails.css("left",bDetails.position().left + $(chart[1]).width() - bDetails.width() - 5);
  514. bDetails.css("top",bDetails.position().top + $(chart[1]).height() - bDetails.height() );
  515. //Append map after image
  516. $(chart[1]).append(chart[0]);
  517. }
  518. for(o in captionOptions)
  519. if(captionOptions[o].callback != undefined)
  520. $("#" + captionId + o).bind("click",captionOptions[o].callback);
  521. });
  522. }
  523. });
  524. var DialComponent = JFreeChartComponent.extend({
  525. update : function() {
  526. var cd = this.chartDefinition;
  527. if (cd == undefined){
  528. Dashboards.log("Fatal - No chartDefinition passed","error");
  529. return;
  530. }
  531. cd.chartType = 'DialChart';
  532. var intervals = cd.intervals;
  533. var colors = cd.colors;
  534. if(colors != undefined && intervals.length != colors.length){
  535. Dashboards.log("Fatal - Number of intervals differs from number of colors","error");
  536. return;
  537. }
  538. this.callPentahoAction(cd.queryType == 'cda' ? "jfreechartdial-cda.xaction" : "jfreechartdial.xaction");
  539. }
  540. });
  541. var OpenFlashChartComponent = JFreeChartComponent.extend({
  542. callPentahoAction: function() {
  543. Dashboards.incrementRunningCalls();
  544. var myself = this;
  545. Dashboards.callPentahoAction(myself,"cdf", "components", "openflashchart.xaction", this.getParameters(),function(jXML){
  546. if(jXML != null){
  547. var result = jXML.find("ExecuteActivityResponse:first-child").text().replace(/openflashchart/g,webAppPath + "/openflashchart");
  548. getDataFuntion = result.match(/getData.*\(\)/gi);
  549. $("#"+myself.htmlObject).html(result);
  550. }
  551. Dashboards.decrementRunningCalls();
  552. });
  553. OpenFlashChartComponent.prototype.onClick = function(value) {
  554. if(getDataFuntion != null && myself.chartDefinition.urlTemplate != undefined && myself.chartDefinition.parameterName != undefined){
  555. myself.data = myself.data != undefined ? myself.data : eval('(' + eval(getDataFuntion[0]) + ')');
  556. if(myself.data.x_axis != undefined){
  557. var urlTemplate = myself.chartDefinition.urlTemplate.replace("{" + myself.chartDefinition.parameterName + "}",myself.data.x_axis.labels.labels[value]);
  558. eval(urlTemplate);
  559. }
  560. }
  561. };
  562. }
  563. });
  564. var TrafficComponent = BaseComponent.extend({
  565. update : function() {
  566. var cd = this.trafficDefinition;
  567. if (cd == undefined){
  568. Dashboards.log("Fatal - No trafficDefinition passed","error");
  569. return;
  570. }
  571. var intervals = cd.intervals;
  572. if (intervals == undefined){
  573. cd.intervals = [-1,1];
  574. }
  575. // go through parametere array and update values
  576. var parameters = [];
  577. for(p in cd){
  578. var key = p;
  579. var value = typeof cd[p]=='function'?cd[p]():cd[p];
  580. // alert("key: " + key + "; Value: " + value);
  581. parameters.push([key,value]);
  582. }
  583. // increment runningCalls
  584. Dashboards.incrementRunningCalls();
  585. var myself = this;
  586. // callback async mode
  587. Dashboards.callPentahoAction(myself,"cdf", "components", "traffic.xaction", parameters,
  588. function(result){
  589. var value = $(result).find("VALUE").text();
  590. var i = $("<img>").attr("src",value<=cd.intervals[0]?Dashboards.TRAFFIC_RED:(value>=cd.intervals[1]?Dashboards.TRAFFIC_GREEN:Dashboards.TRAFFIC_YELLOW));
  591. $('#'+myself.htmlObject).html(i);
  592. if(cd.showValue != undefined && cd.showValue == true){
  593. var tooltip = "Value: " + value + " <br /><img align='middle' src='" + Dashboards.TRAFFIC_RED + "'/> &le; " + cd.intervals[0] + " &lt; <img align='middle' src='" + Dashboards.TRAFFIC_YELLOW + "'/> &lt; " + cd.intervals[1] + " &le; <img align='middle' src='" + Dashboards.TRAFFIC_GREEN + "'/> <br/>" + (tooltip != undefined?tooltip:"");
  594. $('#'+myself.htmlObject).attr("title",tooltip + ( myself._tooltip != undefined? myself._tooltip:"")).tooltip({
  595. delay:0,
  596. track: true,
  597. fade: 250
  598. });
  599. }
  600. Dashboards.decrementRunningCalls();
  601. });
  602. }
  603. });
  604. var TimePlotComponent = BaseComponent.extend({
  605. reset: function(){
  606. this.timeplot = undefined;
  607. this.chartDefinition.dateRangeInput = this.InitialDateRangeInput;
  608. this.listeners = this.InitialListeners;
  609. },
  610. update : function() {
  611. var cd = this.chartDefinition;
  612. this.InitialListeners = this.InitialListeners == undefined ? this.listeners : this.InitialListeners;
  613. this.InitialDateRangeInput = this.InitialDateRangeInput == undefined ? cd.dateRangeInput : this.InitialDateRangeInput;
  614. if(cd.updateOnDateRangeInputChange != true && this.timeplot!= undefined && cd.dateRangeInput != undefined){
  615. if(this.updateTimeplot != false && this.timeplot._plots.length > 0 ){
  616. var lastEventPlot = this.timeplot._plots[this.timeplot._plots.length -1];
  617. if(lastEventPlot._id == "eventPlot")
  618. lastEventPlot._addSelectEvent(Dashboards.getParameterValue(this.startDateParameter)+ " 00:00:00",Dashboards.getParameterValue(this.endDateParameter)+ " 23:59:59",
  619. lastEventPlot._eventSource,"iso8601",this.geometry._earliestDate,this.geometry._latestDate);
  620. }
  621. return;
  622. }
  623. if(cd.dateRangeInput != undefined && this.timeplot == undefined){
  624. cd.dateRangeInput = Dashboards.getComponent(cd.dateRangeInput);
  625. this.startDateParameter = cd.dateRangeInput.parameter[0];
  626. this.endDateParameter = cd.dateRangeInput.parameter[1];
  627. this.listeners = this.listeners == undefined ? [] : this.listeners;
  628. this.listeners = this.listeners.concat(this.startDateParameter).concat(this.endDateParameter);
  629. }
  630. if (typeof Timeplot != "undefined" && Dashboards.timePlotColors == undefined ){
  631. Dashboards.timePlotColors = [new Timeplot.Color('#820000'),
  632. new Timeplot.Color('#13E512'), new Timeplot.Color('#1010E1'),
  633. new Timeplot.Color('#E532D1'), new Timeplot.Color('#1D2DE1'),
  634. new Timeplot.Color('#83FC24'), new Timeplot.Color('#A1D2FF'),
  635. new Timeplot.Color('#73F321')];
  636. }
  637. var timePlotTimeGeometry = new Timeplot.DefaultTimeGeometry({
  638. gridColor: "#000000",
  639. axisLabelsPlacement: "top",
  640. gridType: "short",
  641. yAxisColor: "rgba(255,255,255,0)",
  642. gridColor: "rgba(100,100,100,1)"
  643. });
  644. var timePlotValueGeometry = new Timeplot.DefaultValueGeometry({
  645. gridColor: "#000000",
  646. min: 0,
  647. axisLabelsPlacement: "left",
  648. gridType: "short",
  649. valueFormat : function (value){
  650. return toFormatedString(value);
  651. }
  652. });
  653. var timePlotEventSource = new Timeplot.DefaultEventSource();
  654. var eventSource2 = new Timeplot.DefaultEventSource();
  655. var timePlot;
  656. var obj = this;
  657. if (cd == undefined){
  658. Dashboards.log("Fatal - No chart definition passed","error");
  659. return;
  660. }
  661. // Set default options:
  662. if (cd.showValues == undefined){
  663. cd.showValues = true;
  664. }
  665. var cols = typeof cd['columns']=='function'?cd['columns']():cd['columns'];
  666. if (cols == undefined || cols.length == 0){
  667. Dashboards.log("Fatal - No 'columns' property passed in chartDefinition","error");
  668. return;
  669. }
  670. // Write the title
  671. var title = $('<div></div>');
  672. if(cd.title != undefined){
  673. title.append('<span style="text-transform: lowercase;">' + cd.title + '&nbsp; &nbsp; &nbsp;</span>');
  674. }
  675. var plotInfo = [];
  676. for(var i = 0,j=0; i<cols.length; i++,j++){
  677. j = j > 7 ? 0 : j;
  678. title.append('<span id="' + obj.name + 'Plot' + i + 'Header" style="color:' + Dashboards.timePlotColors[j].toHexString() + '">'+cols[i]+' &nbsp;&nbsp;</span>');
  679. var plotInfoOpts = {
  680. id: obj.name + "Plot" + i,
  681. name: cols[i],
  682. dataSource: new Timeplot.ColumnSource(timePlotEventSource,i + 1),
  683. valueGeometry: timePlotValueGeometry,
  684. timeGeometry: timePlotTimeGeometry,
  685. lineColor: Dashboards.timePlotColors[j],
  686. showValues: cd.showValues,
  687. hideZeroToolTipValues: cd.hideZeroToolTipValues != undefined ? cd.hideZeroToolTipValues : false,
  688. showValuesMode: cd.showValuesMode != undefined ? cd.showValuesMode : "header",
  689. toolTipFormat: function (value,plot){
  690. return plot._name + " = " + toFormatedString(value);
  691. },
  692. headerFormat: function (value,plot){
  693. return plot._name + " = " + toFormatedString(value) + "&nbsp;&nbsp;";
  694. }
  695. };
  696. if ( cd.dots == true){
  697. plotInfoOpts.dotColor = Dashboards.timePlotColors[j];
  698. }
  699. if ( cd.fill == true){
  700. plotInfoOpts.fillColor = Dashboards.timePlotColors[j].transparency(0.5);
  701. }
  702. plotInfo.push(new Timeplot.createPlotInfo(plotInfoOpts));
  703. }
  704. // support for events
  705. var eventSource2 = undefined;
  706. var eventSourcePlot = undefined;
  707. if(cd.dateRangeInput != undefined || (cd.events && cd.events.show == true)){
  708. this.rangeColor = "00FF00";
  709. eventSource2 = new Timeplot.DefaultEventSource();
  710. eventSourcePlot = Timeplot.createPlotInfo({
  711. id: cd.dateRangeInput != undefined ? "eventPlot" : "events",
  712. eventSource: eventSource2,
  713. timeGeometry: timePlotTimeGeometry,
  714. lineColor: "#FF0000",
  715. rangeColor: this.rangeColor,
  716. getSelectedRegion: function(start,end){
  717. myself.updateDateRangeInput(start,end);
  718. }
  719. });
  720. plotInfo.push(eventSourcePlot);
  721. }
  722. $("#"+this.htmlObject).html(title);
  723. $("#"+this.htmlObject).append("<div class='timeplot'></div>");
  724. if(cd.height > 0){
  725. $("#" + this.htmlObject + " > div.timeplot").css("height",cd.height);
  726. }
  727. if(cd.width > 0){
  728. $("#" + this.htmlObject + " > div.timeplot").css("width",cd.width);
  729. }
  730. timeplot = Timeplot.create($("#"+this.htmlObject+" > div.timeplot")[0], plotInfo);
  731. obj.timeplot = timeplot;
  732. obj.geometry = timePlotTimeGeometry;
  733. // go through parametere array and update values
  734. var parameters = [];
  735. for(p in cd){
  736. var key = p;
  737. var value = typeof cd[p]=='function'?cd[p]():cd[p];
  738. // parameters.push(encodeURIComponent(key)+"="+encodeURIComponent(value));
  739. parameters.push(key+"="+value);
  740. }
  741. var allData = undefined;
  742. var timePlotEventSourceUrl = webAppPath + "/ViewAction?solution=cdf&path=components&action=timelinefeeder.xaction&" + parameters.join('&');
  743. var myself = this;
  744. if(cd.events && cd.events.show == true){
  745. // go through parametere array and update values
  746. var parameters = [];
  747. for(p in cd.events){
  748. var key = p;
  749. var value = typeof cd.events[p]=='function'?cd.events[p]():cd.events[p];
  750. parameters.push(key+"="+value);
  751. }
  752. var eventUrl = webAppPath + "/ViewAction?solution=cdf&path=components&action=timelineeventfeeder.xaction&" + parameters.join('&');
  753. timeplot.loadText(timePlotEventSourceUrl,",", timePlotEventSource, null,null,function(range){
  754. timeplot.loadJSON(eventUrl,eventSource2,function(data){
  755. data.events = myself.filterEvents(data.events, range);
  756. if(cd.dateRangeInput){
  757. var lastEventPlot = timeplot._plots[timeplot._plots.length -1];
  758. if(lastEventPlot._id == "eventPlot")
  759. lastEventPlot._addSelectEvent(Dashboards.getParameterValue(obj.startDateParameter) + " 00:00:00",Dashboards.getParameterValue(obj.endDateParameter)+ " 23:59:59",
  760. eventSource2,"iso8601",timePlotTimeGeometry._earliestDate,timePlotTimeGeometry._latestDate);
  761. }
  762. })
  763. });
  764. }
  765. else
  766. timeplot.loadText(timePlotEventSourceUrl,",", timePlotEventSource,null,null,function(){
  767. if(cd.dateRangeInput){
  768. var lastEventPlot = timeplot._plots[timeplot._plots.length -1];
  769. if(lastEventPlot._id == "eventPlot")
  770. lastEventPlot._addSelectEvent(Dashboards.getParameterValue(obj.startDateParameter) + " 00:00:00",Dashboards.getParameterValue(obj.endDateParameter)+ " 23:59:59",
  771. eventSource2,"iso8601",timePlotTimeGeometry._earliestDate,timePlotTimeGeometry._latestDate);
  772. }
  773. });
  774. },
  775. filterEvents : function (events, range) {
  776. var result = [];
  777. var min = MetaLayer.toDateString(new Date(range.earliestDate));
  778. var max = MetaLayer.toDateString(new Date(range.latestDate));
  779. for(i = 0; i < events.length; i++){
  780. if(events[i].start >= min && ((events[i].end == undefined && events[i].start <= max) || events[i].end <= max)){
  781. result.push(events[i]);
  782. }
  783. }
  784. return result;
  785. },
  786. updateDateRangeInput: function(start,end){
  787. var toDateString = function(d){
  788. var currentMonth = "0" + (d.getMonth() + 1);
  789. var currentDay = "0" + (d.getDate());
  790. return d.getFullYear() + "-" + (currentMonth.substring(currentMonth.length-2, currentMonth.length)) + "-" + (currentDay.substring(currentDay.length-2, currentDay.length));
  791. };
  792. if(this.chartDefinition.dateRangeInput != undefined ){
  793. if(start > end){
  794. var aux = start;
  795. start = end;
  796. end = aux;
  797. }
  798. Dashboards.setParameter(this.startDateParameter, toDateString(start));
  799. Dashboards.setParameter(this.endDateParameter , toDateString(end));
  800. this.updateTimeplot = false;
  801. Dashboards.update(this.chartDefinition.dateRangeInput);
  802. Dashboards.fireChange(this.startDateParameter,toDateString(start));
  803. this.updateTimeplot = true;
  804. }
  805. }
  806. });
  807. var TextComponent = BaseComponent.extend({
  808. update : function() {
  809. $("#"+this.htmlObject).html(this.expression());
  810. }
  811. });
  812. var TextInputComponent = BaseComponent.extend({
  813. update: function(){
  814. selectHTML = "<input";
  815. selectHTML += " type=test id='" + this.name + "' name='" + this.name +
  816. "' + value='" +
  817. Dashboards.getParameterValue(this.parameter) +
  818. (this.charWidth ? ("' + size='" + this.charWidth) : "") +
  819. (this.maxChars ? ("' + maxlength='" + this.maxChars) : "") +
  820. "'>";
  821. $("#" + this.htmlObject).html(selectHTML);
  822. var myself = this;
  823. $("#" + this.name).change(function(){
  824. Dashboards.processChange(myself.name);
  825. }).keyup(function(event){
  826. if (event.keyCode == 13) {
  827. Dashboards.processChange(myself.name);
  828. }
  829. });
  830. },
  831. getValue : function() {
  832. return $("#"+this.name).val();
  833. }
  834. });
  835. // Start by setting a sane i18n default to datepicker
  836. $(function(){$.datepicker.setDefaults($.datepicker.regional[''])});
  837. var DateInputComponent = BaseComponent.extend({
  838. update: function(){
  839. var format = (this.dateFormat == undefined || this.dateFormat == null)? 'yy-mm-dd' : this.dateFormat;
  840. var myself = this;
  841. var startDate, endDate;
  842. if(this.startDate == 'TODAY') startDate = new Date();
  843. else if(this.startDate) startDate = $.datepicker.parseDate( format, this.startDate);
  844. if(this.endDate == 'TODAY') endDate = new Date();
  845. else if(this.endDate) endDate = $.datepicker.parseDate( format, this.endDate);
  846. //ToDo: stretch interval to catch defaultValue?..
  847. //Dashboards.getParameterValue(this.parameter))
  848. $("#" + this.htmlObject).html($("<input/>").attr("id", this.name).attr("value", Dashboards.getParameterValue(this.parameter)).css("width", "80px"));
  849. $(function(){
  850. $("#" + myself.htmlObject + " input").datepicker({
  851. dateFormat: format,
  852. changeMonth: true,
  853. changeYear: true,
  854. minDate: startDate,
  855. maxDate: endDate,
  856. onSelect: function(date, input){
  857. Dashboards.processChange(myself.name);
  858. }
  859. });
  860. // Add JQuery DatePicker standard localization support only if the dashboard is localized
  861. if (typeof Dashboards.i18nSupport !== "undefined" && Dashboards.i18nSupport != null) {
  862. $("#" + myself.htmlObject + " input").datepicker('option', $.datepicker.regional[Dashboards.i18nCurrentLanguageCode]);
  863. }
  864. });
  865. },
  866. getValue : function() {
  867. return $("#"+this.name).val();
  868. }
  869. });
  870. var DateRangeInputComponent = BaseComponent.extend({
  871. update : function() {
  872. var dr;
  873. if (this.singleInput == undefined || this.singleInput == true){
  874. dr = $("<input/>").attr("id",this.name).attr("value",Dashboards.getParameterValue(this.parameter[0]) + " > " + Dashboards.getParameterValue(this.parameter[1]) ).css("width","170px");
  875. $("#"+this.htmlObject).html(dr);
  876. } else {
  877. dr = $("<input/>").attr("id",this.name).attr("value",Dashboards.getParameterValue(this.parameter[0])).css("width","80px");
  878. $("#"+this.htmlObject).html(dr);
  879. dr.after($("<input/>").attr("id",this.name + "2").attr("value",Dashboards.getParameterValue(this.parameter[1])).css("width","80px"));
  880. if(this.inputSeparator != undefined){
  881. dr.after(this.inputSeparator);
  882. }
  883. }
  884. var offset = dr.offset();
  885. var myself = this;
  886. var earliestDate = this.earliestDate != undefined ? Dashboards.getParameterValue(this.earliestDate) : Date.parse('-1years');
  887. var latestDate = this.latestDate != undefined ? Dashboards.getParameterValue(this.latestDate) : Date.parse('+1years');
  888. var leftOffset = this.leftOffset != undefined ? this.leftOffset : 0;
  889. var topOffset = this.topOffset != undefined ? this.topOffset : 15;
  890. var changed, closed;
  891. function triggerWhenDone() {
  892. if(changed && closed) {
  893. myself.fireInputChange(myself.startValue,myself.endValue);
  894. changed = closed = false;
  895. }
  896. };
  897. $(function(){
  898. $("#" + myself.htmlObject + " input").daterangepicker({
  899. posX: offset.left + leftOffset,
  900. posY: offset.top + topOffset,
  901. earliestDate: earliestDate,
  902. latestDate: latestDate,
  903. dateFormat: 'yy-mm-dd',
  904. onOpen: function() {
  905. changed = closed = false;
  906. myself.startValue = null;
  907. myself.endValue = null;
  908. },
  909. onDateSelect: function(rangeA, rangeB) {
  910. changed = true;
  911. myself.storeChanges(rangeA, rangeB);
  912. triggerWhenDone();
  913. },
  914. onClose: function() {
  915. closed = true;
  916. triggerWhenDone();
  917. }
  918. });
  919. });
  920. },
  921. fireInputChange : function(start, end){
  922. //TODO: review this!
  923. if(this.preChange){
  924. this.preChange(start, end);
  925. }
  926. if(this.parameter)
  927. {
  928. if( this.parameter.length == 2) Dashboards.setParameter(this.parameter[1], end);
  929. if( this.parameter.length > 0) Dashboards.fireChange(this.parameter[0], start);
  930. }
  931. if(this.postChange){
  932. this.postChange(start, end);
  933. }
  934. },
  935. storeChanges : function(start,end){
  936. this.startValue = start;
  937. this.endValue = end;
  938. }
  939. },
  940. {
  941. fireDateRangeInputChange : function(name, rangeA, rangeB){
  942. // WPG: can we just use the parameter directly?
  943. var object = Dashboards.getComponentByName(name);
  944. if(!(typeof(object.preChange)=='undefined')){
  945. object.preChange(rangeA, rangeB);
  946. }
  947. var parameters = eval(name + ".parameter");
  948. // set the second date and fireChange the first
  949. Dashboards.setParameter(parameters[1], rangeB);
  950. Dashboards.fireChange(parameters[0],rangeA);
  951. if(!(typeof(object.postChange)=='undefined')){
  952. object.postChange(rangeA, rangeB);
  953. }
  954. }
  955. }
  956. );
  957. var MonthPickerComponent = BaseComponent.extend({
  958. update : function() {
  959. var selectHTML = this.getMonthPicker(this.name, this.size, this.initialDate, this.minDate, this.maxDate, this.months);
  960. $("#" + this.htmlObject).html(selectHTML);
  961. var myself = this;
  962. $("#"+this.name).change(function() {
  963. Dashboards.processChange(myself.name);
  964. });
  965. },
  966. getValue : function() {
  967. var value = $("#" + this.name).val()
  968. var year = value.substring(0,4);
  969. var month = parseInt(value.substring(5,7) - 1);
  970. var d = new Date(year,month,1);
  971. // rebuild picker
  972. var selectHTML = this.getMonthPicker(this.name, this.size, d, this.minDate, this.maxDate, this.months);
  973. $("#" + this.htmlObject).html(selectHTML);
  974. var myself = this;
  975. $("#"+this.name).change(function() {
  976. Dashboards.processChange(myself.name);
  977. });
  978. return value;
  979. },
  980. getMonthPicker : function(object_name, object_size, initialDate, minDate, maxDate, monthCount) {
  981. var selectHTML = "<select";
  982. selectHTML += " id='" + object_name + "'";
  983. if (minDate == undefined){
  984. minDate = new Date();
  985. minDate.setYear(1980);
  986. }
  987. if (maxDate == undefined){
  988. maxDate = new Date();
  989. maxDate.setYear(2060);
  990. }
  991. // if monthCount is not defined we'll use everything between max and mindate
  992. if(monthCount == undefined || monthCount == 0) {
  993. var monthsToAdd = (maxDate.getFullYear() - minDate.getFullYear())*12;
  994. monthCount = (maxDate.getMonth() - minDate.getMonth()) + monthsToAdd;
  995. }
  996. //set size
  997. if (object_size != undefined){
  998. selectHTML += " size='" + object_size + "'";
  999. }
  1000. var currentDate = new Date(+initialDate);
  1001. currentDate.setMonth(currentDate.getMonth()- monthCount/2 - 1);
  1002. for(var i= 0; i <= monthCount; i++){
  1003. currentDate.setMonth(currentDate.getMonth() + 1);
  1004. if(currentDate >= minDate && currentDate <= maxDate)
  1005. {
  1006. selectHTML += "<option value = '" + currentDate.getFullYear() + "-" + this.zeroPad(currentDate.getMonth()+1,2) + "'";
  1007. if(currentDate.getFullYear() == initialDate.getFullYear() && currentDate.getMonth() == initialDate.getMonth()){
  1008. selectHTML += "selected='selected'"
  1009. }
  1010. selectHTML += "' >" + Dashboards.monthNames[currentDate.getMonth()] + " " +currentDate.getFullYear() + "</option>";
  1011. }
  1012. }
  1013. selectHTML += "</select>";
  1014. return selectHTML;
  1015. },
  1016. zeroPad : function(num,size) {
  1017. var n = "00000000000000" + num;
  1018. return n.substring(n.length-size,n.length);
  1019. }
  1020. });
  1021. var ToggleButtonBaseComponent = BaseComponent.extend({
  1022. update: function(){
  1023. var myArray = this.getValuesArray();
  1024. selectHTML = "";
  1025. //default
  1026. var currentVal = Dashboards.getParameterValue(this.parameter);
  1027. currentVal = (typeof currentVal == 'function') ? currentVal() : currentVal;
  1028. var isSelected = false;
  1029. var currentValArray = [];
  1030. if(currentVal instanceof Array || (typeof(currentVal) == "object" && currentVal.join)) {
  1031. currentValArray = currentVal;
  1032. } else if(typeof(currentVal) == "string"){
  1033. currentValArray = currentVal.split("|");
  1034. }
  1035. // check to see if current selected values are in the current values array. If not check to see if we should default to the first
  1036. var vid = this.valueAsId==false?0:1;
  1037. var hasCurrentVal = false;
  1038. outer:
  1039. for(var i = 0; i < currentValArray.length; i++){
  1040. for(var y = 0; y < myArray.length; y++) {
  1041. if (currentValArray[i] == myArray[y][vid]) {
  1042. hasCurrentVal = true;
  1043. break outer;
  1044. }
  1045. }
  1046. }
  1047. // if there will be no selected value, but we're to default if empty, select the first
  1048. if(!hasCurrentVal && this.defaultIfEmpty){
  1049. currentValArray = [myArray[0][vid]];
  1050. this.currentVal = currentValArray;
  1051. Dashboards.setParameter(this.parameter,currentValArray);
  1052. Dashboards.processChange(this.name);
  1053. }
  1054. // (currentValArray == null && this.defaultIfEmpty)? firstVal : null
  1055. selectHTML += "<ul class='"+ ((this.verticalOrientation)? "toggleGroup vertical":"toggleGroup horizontal")+"'>"
  1056. for (var i = 0, len = myArray.length; i < len; i++) {
  1057. selectHTML += "<li class='"+ ((this.verticalOrientation)? "toggleGroup vertical":"toggleGroup horizontal")+"'><label><input onclick='ToggleButtonBaseComponent.prototype.callAjaxAfterRender(\"" + this.name + "\")'";
  1058. isSelected = false;
  1059. for (var j = 0, valLength = currentValArray.length; j < valLength; j++) {
  1060. isSelected = currentValArray[j] == myArray[i][vid];
  1061. if(isSelected) {
  1062. break;
  1063. }
  1064. }
  1065. if (this.type == 'radio' || this.type == 'radioComponent'){
  1066. if ((i == 0 && !hasCurrentVal) ||
  1067. (hasCurrentVal && (myArray[i][vid] == currentVal ))) {
  1068. selectHTML += " CHECKED";
  1069. }
  1070. selectHTML += " type='radio'";
  1071. }else{
  1072. if ((i == 0 && !hasCurrentVal) ||
  1073. (hasCurrentVal && isSelected)) {
  1074. selectHTML += " CHECKED";
  1075. }
  1076. selectHTML += " type='checkbox'";
  1077. }
  1078. selectHTML += "class='" + this.name +"' name='" + this.name +"' value='" + myArray[i][vid] + "' /> " + myArray[i][1] + "</label></li>" + ((this.separator == undefined || this.separator == null || this.separator == "null")?"":this.separator);
  1079. }
  1080. selectHTML += "</ul>"
  1081. // update the placeholder
  1082. $("#" + this.htmlObject).html(selectHTML);
  1083. this.currentVal = null;
  1084. },
  1085. callAjaxAfterRender: function(name){
  1086. setTimeout(function(){
  1087. Dashboards.processChange(name)
  1088. },1);
  1089. }
  1090. });
  1091. var RadioComponent = ToggleButtonBaseComponent.extend({
  1092. getValue : function() {
  1093. if (this.currentVal != 'undefined' && this.currentVal != null) {
  1094. return this.currentVal;
  1095. } else {
  1096. return $("#"+this.htmlObject + " ."+this.name+":checked").val()
  1097. }
  1098. }
  1099. });
  1100. var CheckComponent = ToggleButtonBaseComponent.extend({
  1101. getValue : function() {
  1102. if (this.currentVal != 'undefined' && this.currentVal != null) {
  1103. return this.currentVal;
  1104. } else {
  1105. var a = new Array()
  1106. $("#"+this.htmlObject + " ."+this.name + ":checked").each(function(i,val){
  1107. a.push($(this).val());
  1108. });
  1109. return a;
  1110. }
  1111. }
  1112. });
  1113. var MultiButtonComponent = ToggleButtonBaseComponent.extend({
  1114. indexes: [],//used as static
  1115. update: function(){
  1116. var myArray = this.getValuesArray();
  1117. this.cachedArray = myArray;
  1118. var cssWrapperClass= "pentaho-toggle-button pentaho-toggle-button-up "+ ((this.verticalOrientation)? "pentaho-toggle-button-vertical" : "pentaho-toggle-button-horizontal");
  1119. selectHTML = "";
  1120. var firstVal;
  1121. var valIdx = this.valueAsId ? 1 : 0;
  1122. var lblIdx = 1;
  1123. if (this.isMultiple == undefined) this.isMultiple = false;
  1124. var ph = $("<div>");
  1125. for (var i = 0, len = myArray.length; i < len; i++){
  1126. var value = myArray[i][valIdx],
  1127. label = myArray[i][lblIdx],
  1128. classes = cssWrapperClass + this.getExtraCss(i,len,this.verticalOrientation),
  1129. selector;
  1130. value = (value == null ? null : value.replace('"','&quot;' ));
  1131. label = (label == null ? null : label.replace('"','&quot;' ));
  1132. if(i == 0){
  1133. firstVal = value;
  1134. }
  1135. selectHTML = "<div class='" + classes +"'><button name='" + this.name + "'>" + label + "</button >" +"</div>";
  1136. selector = $(selectHTML);
  1137. // We wrap the click handler in a self-executing function so that we can capture 'i'.
  1138. var myself = this;
  1139. (function(index){ selector.click(function(){
  1140. MultiButtonComponent.prototype.clickButton(myself.htmlObject, myself.name, index, myself.isMultiple, myself.verticalOrientation);
  1141. });}(i));
  1142. ph.append(selector);
  1143. if (!(this.separator == undefined || this.separator == null || this.separator == "null") && i != myArray.length - 1) {
  1144. ph.append(this.separator);
  1145. }
  1146. }
  1147. ph.appendTo($("#" + this.htmlObject).empty());
  1148. //default
  1149. var currentVal = Dashboards.ev(Dashboards.getParameterValue(this.parameter));
  1150. var isSelected = false;
  1151. var currentValArray;
  1152. if(currentVal instanceof Array || (typeof(currentVal) == "object" && currentVal.join)) {
  1153. currentValArray = currentVal;
  1154. } else {
  1155. currentValArray = currentVal.toString().split("|");
  1156. }
  1157. var foundDefault = false;
  1158. this.clearSelections(this.htmlObject, this.name, this.verticalOrientation);
  1159. for (var i = 0; i < myArray.length; i++) {
  1160. isSelected = false;
  1161. for (var j = 0, valLength = currentValArray.length; j < valLength; j++) {
  1162. isSelected = currentValArray[j] == myArray[i][valIdx];
  1163. if(isSelected) {
  1164. break;
  1165. }
  1166. }
  1167. if ( ( $.isArray(currentVal) && isSelected || isSelected)
  1168. || (myArray[i][valIdx] == currentVal || myArray[i][lblIdx] == currentVal) ) {
  1169. MultiButtonComponent.prototype.clickButton(this.htmlObject, this.name, i, this.isMultiple, this.verticalOrientation, true);
  1170. foundDefault = true;
  1171. if(!this.isMultiple) {
  1172. break;
  1173. }
  1174. }
  1175. }
  1176. if(((!foundDefault && !this.isMultiple) || (!foundDefault && this.isMultiple && this.defaultIfEmpty)) && myArray.length > 0){
  1177. //select first value
  1178. if((currentVal == null || currentVal == "" || (typeof(currentVal) == "object" && currentVal.length == 0)) && this.parameter){
  1179. Dashboards.fireChange(this.parameter, (this.isMultiple) ? [firstVal] : firstVal);
  1180. }
  1181. MultiButtonComponent.prototype.clickButton(this.htmlObject, this.name, 0, this.isMultiple, this.verticalOrientation, true);
  1182. }
  1183. // set up hovering
  1184. $(".pentaho-toggle-button").hover(function() {
  1185. $(this).addClass("pentaho-toggle-button-up-hovering");
  1186. }, function() {
  1187. $(this).removeClass("pentaho-toggle-button-up-hovering");
  1188. });
  1189. // set up hovering when inner button is hovered
  1190. $(".pentaho-toggle-button button").hover(function() {
  1191. $(this).parent().addClass("pentaho-toggle-button-up-hovering");
  1192. }, function() {
  1193. // don't remove it, since it's inside the outer div it will handle that
  1194. });
  1195. },
  1196. getValue: function(){
  1197. if(this.isMultiple){
  1198. var indexes = MultiButtonComponent.prototype.getSelectedIndex(this.name);
  1199. var a = new Array();
  1200. // if it is not an array, handle that too
  1201. if (indexes.length == undefined) {
  1202. a.push(this.getValueByIdx(indexes));
  1203. } else {
  1204. for(var i=0; i < indexes.length; i++){
  1205. a.push(this.getValueByIdx(indexes[i]));
  1206. }
  1207. }
  1208. return a;
  1209. }
  1210. else {
  1211. return this.getValueByIdx(MultiButtonComponent.prototype.getSelectedIndex(this.name));
  1212. }
  1213. },
  1214. getValueByIdx: function(idx){
  1215. return this.cachedArray[idx][this.valueAsId ? 1 : 0];
  1216. },
  1217. getSelecetedCss: function(verticalOrientation) {
  1218. return "pentaho-toggle-button pentaho-toggle-button-down "+ ((verticalOrientation)? "pentaho-toggle-button-vertical" : "pentaho-toggle-button-horizontal");
  1219. },
  1220. getUnselectedCss: function(verticalOrientation) {
  1221. return "pentaho-toggle-button pentaho-toggle-button-up "+ ((verticalOrientation)? "pentaho-toggle-button-vertical" : "pentaho-toggle-button-horizontal");
  1222. },
  1223. //static MultiButtonComponent.prototype.clickButton
  1224. // This method should be broken up so the UI state code is reusable outside of event processing
  1225. clickButton: function(htmlObject, name, index, isMultiple, verticalOrientation, updateUIOnly){
  1226. var cssWr

Large files files are truncated, but you can click here to view the full file