Created
          January 27, 2014 18:04 
        
      - 
      
- 
        Save icholy/8654059 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var log = console.log.bind(console, "HeatMap:"); | |
| var HeatMap = Backbone.View.extend({ | |
| initialize: function (args) { | |
| log('initialize', args); | |
| this.workspace = args.workspace; | |
| this.id = _.uniqueId('heatmap_'); | |
| $(this.el).attr({ id: this.id }); | |
| _.bindAll(this, 'receive_data'); | |
| this.workspace.bind('query:result', this.receive_data); | |
| this.add_button(); | |
| }, | |
| receive_data: function (args) { log('receive_data', args); }, | |
| add_button: function () { | |
| var $toolbar_table = $(this.workspace.querytoolbar.el).find('ul.table'); | |
| debugger; | |
| var $heatmap_li = $('<li class="seperator_vertical"></li>'); | |
| var $heatmap_button = $( | |
| '<a href="#heatmap" class="heatmap button disabled_toolbar i18n" title="HeatMap"></a>' | |
| ).css({ | |
| 'background-image' : "url('js/saiku/plugins/Statistics/sigma.png')", | |
| 'background-repeat' : 'no-repeat', | |
| 'background-position' : '50% 50%', | |
| 'height' : '32px', | |
| 'margin-top' : '5px' | |
| }); | |
| $heatmap_li.append($heatmap_button); | |
| $toolbar_table.append($heatmap_li); | |
| } | |
| }); | |
| Saiku.events.bind('session:new', function (session) { | |
| log('session:new'); | |
| var new_workspace = function (args) { | |
| log('new_workspace'); | |
| if (typeof args.workspace.heatmap === 'undefined') { | |
| args.workspace.heatmap = new HeatMap({ workspace: args.workspace }); | |
| } | |
| }; | |
| var clear_workspace = function (args) { | |
| log('clear_workspace'); | |
| if (typeof args.workspace.heatmap === 'undefined') { | |
| return; | |
| } | |
| var $el = $(args.workspace.heatmap.el); | |
| if ($el.is(':visible')) { | |
| $el.parents().find('.workspace_results table').show(); | |
| $el.hide() | |
| // RESET PLUGIN STATE HERE | |
| } | |
| }; | |
| var i, tabs = Saiku.tabs._tabs; | |
| for (i = 0; i < tabs.length; i++) { | |
| new_workspace({ workspace: tabs[i] }); | |
| } | |
| Saiku.session.bind('workspace:new', new_workspace); | |
| Saiku.session.bind('workspace:clear', clear_workspace); | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment