dynamic-table
Version:
Dynamic HTML grid
4 lines (3 loc) • 2.42 kB
JavaScript
/* dynamic-table - v0.0.0 - 2016-02-23
Copyright (c) 2016 Ross Basarevych; Licensed MIT */
;var dtModule=angular.module("dynamicTable",[]);dtModule.provider("dynamicTable",function(){var a=null,b={row_id_column:null,mapper:null,sort_column:null,sort_dir:"asc",page_number:1,page_size:15,page_sizes:[15,30,50,100,0],table_class:"table table-striped table-hover table-condensed",loader_image:"img/loader.gif",strings:{DT_BANNER_LOADING:"Loading... Please wait",DT_BANNER_EMPTY:"Nothing found",DT_BANNER_ERROR:"Error loading table",DT_BUTTON_PAGE_SIZE:"Page size",DT_BUTTON_COLUMNS:"Columns",DT_BUTTON_REFRESH:"Refresh",DT_BUTTON_OK:"OK",DT_BUTTON_CLEAR:"Clear",DT_BUTTON_CANCEL:"Cancel",DT_TITLE_FILTER_WINDOW:"Filter",DT_LABEL_ALL_ENTRIES:"All",DT_LABEL_CURRENT_PAGE:"Current page",DT_LABEL_ALL_PAGES:"All pages",DT_LABEL_PAGE_OF_1:"Page",DT_LABEL_PAGE_OF_2:"of #",DT_LABEL_FILTER_LIKE:"Strings like",DT_LABEL_FILTER_EQUAL:"Values equal to",DT_LABEL_FILTER_BETWEEN_START:"Values greater than or equal to",DT_LABEL_FILTER_BETWEEN_END:"Values less than or equal to",DT_LABEL_FILTER_NULL:"Include rows with empty value in this column",DT_LABEL_TRUE:"True",DT_LABEL_FALSE:"False",DT_DATE_TIME_FORMAT:"YYYY-MM-DD HH:mm:ss"}};this.$get=["$filter","$rootScope","$timeout",function(c,d,e){if(a){var f=b.strings;$.each(f,function(d,e){b.strings[d]=c(a)(d)})}var g=function(a){this.element=null,this.plugin=null,this.event=null,this.statusCode=null,this.options=a,this.init=function(c){if(!this.plugin){var d=b;$.extend(d,a),this.options=d,this.element=$(c),this.plugin=this.element.dynamicTable(this.options);var f=this;this.element.on("dt.loading",function(a){e(function(){f.event="loading"})}),this.element.on("dt.loaded",function(a){e(function(){f.event="loaded",f.statusCode=200})}),this.element.on("dt.selected",function(a){e(function(){f.event="selected"})}),this.element.on("dt.deselected",function(a){e(function(){f.event="deselected"})}),this.element.on("dt.http-error",function(a,b){e(function(){f.event="http-error",f.statusCode=b.status})})}}};return function(a){return new g(a)}}],this.setTranslationFilter=function(b){a=b}}),dtModule.directive("dynamicTable",[function(){return{restrict:"A",scope:{ctrl:"=dynamicTable"},link:function(a,b,c){"undefined"==typeof c.id&&console.log("DynamicTable expects id attribute to be set"),angular.isDefined(a.ctrl)&&angular.isDefined(a.ctrl.init)&&a.ctrl.init(b)}}}]);