(function(){ TabInteractionManager = function (config){ //---------------------------------------------------------------// //----------------------Member Variables-------------------------// //---------------------------------------------------------------// //This variable will store the global reference for this class within its context var go_this = this; var interactions = config.interactions; var componentsMapById={}; function init(){ //console.log("interactions: ",interactions, " components: ",components); var componentCnt = 0, numComponents = config.components.length; while(componentCnt < numComponents){ componentsMapById[config.components[componentCnt].id] = config.components[componentCnt]['instance']; componentCnt++; }//while(componentCnt < numComponents) if($.isArray(interactions)){ manageInteractions(); } }//function init function manageInteractions(){ //{type:"selectionChange",source:"1",targets:["4"],action:"updateFilter"} var sourceCntrl, interactionCnt =0, numInteractions = interactions.length, currInteraction; while(interactionCnt < numInteractions){ currInteraction = interactions[interactionCnt]; currInteraction['sourceInstance'] = componentsMapById[currInteraction['source']]; sourceCntrl = currInteraction['sourceInstance']; var targetCntrl, targetCnt =0, numTargets = currInteraction.targets.length; currInteraction['targetInstances'] = []; while(targetCnt < numTargets){ currInteraction['targetInstances'].push(componentsMapById[currInteraction.targets[targetCnt]]); targetCntrl = currInteraction['targetInstances'][currInteraction['targetInstances'].length-1]; if(currInteraction['type'] == "pointClick"){ sourceCntrl.on('pointClick',onPointClick (currInteraction, targetCntrl)); }else if(currInteraction['type'] == "selectionChanged"){ sourceCntrl.on('selectionChanged', onSelectionChange(currInteraction,targetCntrl)); }else if(currInteraction['type'] == "contentReady"){ sourceCntrl.on('contentReady',onContentReady(currInteraction, targetCntrl)); }else if (currInteraction['type'] == "rowClick"){ sourceCntrl.on('rowClick',onRowClick(currInteraction, targetCntrl)); } targetCnt++; }//while(targetCnt < numTargets) interactionCnt++; }//while(interactionCnt < numInteractions) }//manageInteractions() //---------------------------- Event Handlers -------------------------// function onPointClick (interactionDef, targetCntrl){ return function (e) { var specification = {fieldNameExpr:"argumentField", prefix:"",suffix:"",valueExpr:"argument"}; //merge this default with the user supplied object if(interactionDef['specification']){ // Merge object2 into object1, recursively $.extend( true, specification, interactionDef['specification']); } if(interactionDef['action']== "updateTitle"){ targetCntrl["option"]('title', specification['prefix'] + e.target[specification['valueExpr']] + specification['suffix']); } if(interactionDef['action']== "updateGridColTitle"){ var colId = specification['colId']?specification['colId']:0; targetCntrl.columnOption(colId, 'caption', specification['prefix'] + e.selectedItem[specification['valueExpr']] + specification['suffix']); } if(interactionDef['action']== "updateFilterAndReload"){ var paramName = e.target.getOptions()[specification['fieldNameExpr']]; var paramValue = e.target[specification['valueExpr']]; updateFilterAndReload (targetCntrl, {field:paramName, value:paramValue}); //cancel the event from bubbling up and getting to the seriesClick event //e.jQueryEvent.cancel = true; } }; }//function onPointClick function onRowClick(interactionDef, targetCntrl){ return function (e) { console.log("e: ", e); var specification = {}; //merge this default with the user supplied object if(interactionDef['specification']){ // Merge object2 into object1, recursively $.extend( true, specification, interactionDef['specification']); } if(interactionDef['action']== "updateFilterAndReload"){ var paramName = specification['field']?specification['field']:specification['valueExpr']; var paramValue = e.data[specification['valueExpr']]; updateFilterAndReload (targetCntrl, {field:paramName, value:paramValue}); } }; }//function onRowClick function onSelectionChange (interactionDef, targetCntrl){ return function (e) { //"this" --> is the component/widget; we are listening to this event in the context of this component //"this" and "e.component" are one and the same in this case //create a default specification object var specification = {prefix:"", suffix:"",valueExpr:e.component['option']('valueExpr'), displayExpr:e.component['option']('displayExpr')}; //merge this default with the user supplied object if(interactionDef['specification']){ // Merge object2 into object1, recursively $.extend( true, specification, interactionDef['specification']); } if(interactionDef['action']== "updateTitle"){ targetCntrl["option"]('title', specification['prefix'] + e.selectedItem[specification['valueExpr']] + specification['suffix']); } if(interactionDef['action']== "updateGridColTitle"){ var colId = specification['colId']?specification['colId']:0; targetCntrl.columnOption(colId, 'caption', specification['prefix'] + e.selectedItem[specification['valueExpr']] + specification['suffix']); } if(interactionDef['action']== "updateFilterAndReload"){ var paramName = e.component['option']('valueExpr'); var paramValue = e.selectedItem[paramName]; updateFilterAndReload (targetCntrl, {field:paramName, value:paramValue}); } }; }//function onSelectionChange function onContentReady(interactionDef, targetCntrl){ return function (e){ var specification = $.extend( true, {}, interactionDef['specification']); if(interactionDef['action']== "renderSparkline"){ var rowCnt = 0, numRows = targetCntrl.totalCount(); while(rowCnt < numRows){ var cellJqObj = targetCntrl.getCellElement(rowCnt, specification['dataField']); if(cellJqObj.length > 0){ var wdgtContJqObj = $('.widgetCont',cellJqObj); if(wdgtContJqObj.length > 0){ var values = targetCntrl.cellValue(rowCnt,specification['dataField']).split(","); specification.dataSource = values; specification.winlossThreshold = ((values.reduce(function (a,b){return parseFloat(a)+parseFloat(b)}, 0))/values.length); $(wdgtContJqObj[0]).dxSparkline(specification); }//if(wdgtContJqObj.length > 0) }//if(cellJqObj.length > 0) rowCnt++; }//while(rowCnt < numRows) }//if(interactionDef['action']== "renderSparkline") };//return function..... }//function onContentReady //----------------------- Private Functions -----------------------------// function updateFilterAndReload (cntrlToUpdate, filter){ cntrlToUpdate.interactionFiltersManager.addFilter(filter); var updatedRemoteQueryStr = cntrlToUpdate.url + "&" + cntrlToUpdate.query + "&" + cntrlToUpdate.interactionFiltersManager.getFiltersAsStr(); var updatedDataSource = commonClassFactory.createDataSource (updatedRemoteQueryStr, cntrlToUpdate.dataTemplate, cntrlToUpdate.argumentField, cntrlToUpdate.dataPostProcessFn, cntrlToUpdate.dataReshapeFn); cntrlToUpdate["option"]('dataSource', updatedDataSource); }//function updateFilterAndReload //----------------------- Event Subscriptions -------------------------// function subscribeToDesiredEvents(config){ }//function subscribeToDesiredEvents //----------------------- Public Function -----------------------------// this.subscribeToDesiredEvents = subscribeToDesiredEvents; init(); return this; };//Dashboard = function })();//anonym function -- IFFE