{"size": 2527, "ext": "js", "max_stars_repo_path": "public/Content/angular-export-table/export/table-export-directive.js", "max_stars_repo_name": "dhac95/newAppTest", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "public/Content/angular-export-table/export/table-export-directive.js", "max_issues_repo_name": "dhac95/newAppTest", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "public/Content/angular-export-table/export/table-export-directive.js", "max_forks_repo_name": "dhac95/newAppTest", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.3229166667, "max_line_length": 93, "alphanum_fraction": 0.5488721805}
/**
 * Created by mmasuyama on 9/2/2015.
 */

var tableExportCtrl = function($element, $attrs, $document) {
  var ctrl = this;

    var elementScope = $element.isolateScope();

    ctrl.disableClick = $element[0].innerHTML.match("te-option");

    var defaultOptions = {
        type: 'pdf',
        escape: false,
        tableName: 'table'
    };

    function exportTable() {
        ctrl.tableElement.tableExport({
            type: elementScope.ctrl.exportOptions.type || defaultOptions.type,
            escape: elementScope.ctrl.exportOptions.escape || defaultOptions.escape,
            tableName: elementScope.ctrl.exportOptions.tableName || defaultOptions.tableName
        })
    }

    function setProperty (obj, param, value) {
        Object.defineProperty(ctrl[obj], param, {
            value: value,
            writable: true,
            configurable: true,
            enumerable: true
        })
    }


    if(elementScope.ctrl.tableSelector) {
        ctrl.tableElement = $('#'+elementScope.ctrl.tableSelector);
        //ctrl.tableElement = document.getElementById(elementScope.ctrl.tableSelector).value;
    }

    //TODO allow to define diiferents methods
    $element.on('click', function(e){
        if(!ctrl.disableClick){
            exportTable();
        }
    });

    //TODO allow to define differents tags (button, select, input, etc)


    //exports

    angular.extend(ctrl,{
        defaultOptions : defaultOptions,
        exportTableFn : exportTable,
        setProperty : setProperty
    })
};

var compileExportTable = function($element, $attrs, transcludeFn) {

};

angular.module('ceibo.components.table.export', [])
  .controller('tableExportCtrl', tableExportCtrl)
  .directive('tableExport', function(){
      return {
          //require: 'table',
          scope: {
              /**
               * options : {
               *     formats : {
               *        pdf: //boolean,
               *        xls: //boolean
               *     }
               * }
               *
               *
               **/
              exportOptions: '=',
              /*
                selector : { selectorType: selector }
               */

              tableSelector: '=' //selector that this element is refering refers.

          }, //isolate or not
          restrict : 'AEC', //A = attribute, C = class, E = Element
          controller: 'tableExportCtrl as ctrl',
          compile: compileExportTable,
          bindToController: true //true or false
      }
  })

;
