dojox/grid/enhanced/plugins/Cookie.js

  • Provides:

    • dojox.grid.enhanced.plugins.Cookie
  • Requires:

    • dojox.grid.enhanced._Plugin in common
    • dojo.cookie in common in project dojo
    • dojox.grid._RowSelector in common
    • dojox.grid.cells._base in common
  • dojox.grid.enhanced.plugins.Cookie

    • type
      Function
    • chains:
      • dojox.grid.enhanced._Plugin: (prototype)
      • dojox.grid.enhanced._Plugin: (call)
    • summary
      This plugin provides a way to persist some grid features in cookie.
      Default persistable features are:
      column width:	"columnWidth" (handler name)
      column order:	"columnOrder"
      sorting order:	"sortOrder"
      
      Grid users can define new persistable features
      by calling the following before grid is initialized (that is, during "preInit");
      	grid.addCookieHandler({
      		name: "a name for the new persistable feature",
      		onLoad: function(savedObject, grid){
      			//load the cookie.
      		},
      		onSave: function(grid){
      			//save the cookie.
      		}
      	});
    • parameters:
      • grid: (typeof )
      • args: (typeof )
    • source: [view]
         this.grid = grid;
         args = (args && dojo.isObject(args)) ? args : {};
         this.cookieProps = args.cookieProps;
         this._cookieHandlers = [];
         this._mixinGrid();

         
         //Column width & simple sorting & column reorder are base grid features, so they must be supported.
         this.addCookieHandler({
          name: "columnWidth",
          onLoad: _loadColWidth,
          onSave: _saveColWidth
         });
         this.addCookieHandler({
          name: "columnOrder",
          onLoad: _loadColumnOrder,
          onSave: _saveColumnOrder
         });
         this.addCookieHandler({
          name: "sortOrder",
          onLoad: _loadSortOrder,
          onSave: _saveSortOrder
         });

         
         dojo.forEach(this._cookieHandlers, function(handler){
          if(args[handler.name] === false){
           handler.enable = false;
          }
         }, this);
  • dojox.grid.enhanced.plugins.Cookie.name

    • type
      String
    • summary
      Plugin name
  • dojox.grid.enhanced.plugins.Cookie._cookieEnabled

    • summary
  • dojox.grid.enhanced.plugins.Cookie.destroy

    • summary
  • dojox.grid.enhanced.plugins.Cookie._mixinGrid

    • type
      Function
    • source: [view]
         var g = this.grid;
         g.addCookieHandler = dojo.hitch(this, "addCookieHandler");
         g.removeCookie = dojo.hitch(this, "removeCookie");
         g.setCookieEnabled = dojo.hitch(this, "setCookieEnabled");
         g.getCookieEnabled = dojo.hitch(this, "getCookieEnabled");
    • summary
  • dojox.grid.enhanced.plugins.Cookie._saveCookie

    • type
      Function
    • source: [view]
         if(this.getCookieEnabled()){
          var cookie = {},
           chs = this._cookieHandlers,
           cookieProps = this.cookieProps,
           cookieKey = _cookieKeyBuilder(this.grid);
          for(var i = chs.length-1; i >= 0; --i){
           if(chs[i].enabled){
            //Do the real saving work here.
            cookie[chs[i].name] = chs[i].onSave(this.grid);
           }
          }
          cookieProps = dojo.isObject(this.cookieProps) ? this.cookieProps : {};
          dojo.cookie(cookieKey, dojo.toJson(cookie), cookieProps);
         }else{
          this.removeCookie();
         }
    • summary
  • dojox.grid.enhanced.plugins.Cookie.onPreInit

    • type
      Function
    • source: [view]
         var grid = this.grid,
          chs = this._cookieHandlers,
          cookieKey = _cookieKeyBuilder(grid),
          cookie = dojo.cookie(cookieKey);
         if(cookie){
          cookie = dojo.fromJson(cookie);
          for(var i = 0; i < chs.length; ++i){
           if(chs[i].name in cookie && chs[i].enabled){
            //Do the real loading work here.
            chs[i].onLoad(cookie[chs[i].name], grid);
           }
          }
         }
         this._cookie = cookie || {};
         this._cookieStartedup = true;
    • summary
  • dojox.grid.enhanced.plugins.Cookie.addCookieHandler

    • type
      Function
    • parameters:
      • args: (typeof Object)
        An object with the following structure:
        
        	{
        		name: &quot;some-string&quot;,
        		onLoad: /* void */ function(/* object */partOfCookie, /* EDG */grid){...},
        		onSave: /* object */ function(/* EDG */grid){...}
        	}
    • source: [view]
         if(args.name){
          var dummy = function(){};
          args.onLoad = args.onLoad || dummy;
          args.onSave = args.onSave || dummy;
          if(!("enabled" in args)){
           args.enabled = true;
          }
          for(var i = this._cookieHandlers.length - 1; i >= 0; --i){
           if(this._cookieHandlers[i].name == args.name){
            this._cookieHandlers.splice(i, 1);
           }
          }
          this._cookieHandlers.push(args);
          if(this._cookieStartedup && args.name in this._cookie){
           args.onLoad(this._cookie[args.name], this.grid);
          }
         }
    • summary
      If a grid plugin wants cookie service, call this.
      This must be called during preInit.
  • dojox.grid.enhanced.plugins.Cookie.removeCookie

    • type
      Function
    • source: [view]
         var key = _cookieKeyBuilder(this.grid);
         dojo.cookie(key, null, {expires: -1});
    • summary
      Remove cookie for this grid.
  • dojox.grid.enhanced.plugins.Cookie.setCookieEnabled

    • type
      Function
    • parameters:
      • cookieName: (typeof String)
        Name of a cookie handler if provided, otherwise for all cookies.
      • enabled: (typeof Boolean)
    • source: [view]
         if(arguments.length == 2){
          var chs = this._cookieHandlers;
          for(var i = chs.length - 1; i >= 0; --i){
           if(chs[i].name === cookieName){
            chs[i].enabled = !!enabled;
           }
          }
         }else{
          this._cookieEnabled = !!cookieName;
          if(!this._cookieEnabled){ this.removeCookie(); }
         }
    • summary
      A setter to enable|disable cookie support for a particular Grid feature.
  • dojox.grid.enhanced.plugins.Cookie.getCookieEnabled

    • type
      Function
    • parameters:
      • cookieName: (typeof String)
        Name of a cookie handler if provided, otherwise for all cookies.
    • source: [view]
         if(dojo.isString(cookieName)){
          var chs = this._cookieHandlers;
          for(var i = chs.length - 1; i >= 0; --i){
           if(chs[i].name == cookieName){ return chs[i].enabled; }
          }
          return false;
         }
         return this._cookieEnabled;
    • summary
      A getter to check cookie support of a particular Grid feature.
  • dojox.grid.enhanced.plugins.Cookie._cookie

    • summary
  • dojox.grid.enhanced.plugins.Cookie._cookieStartedup

    • summary
  • dojox.grid.enhanced.plugins.Cookie.grid

    • summary
  • dojox.grid.enhanced.plugins.Cookie.cookieProps

    • summary
  • dojox.grid.enhanced.plugins.Cookie._cookieHandlers

    • summary
  • viewDef.cells"

    • summary
  • viewDef

    • type
      Object
    • summary
  • dojox.grid.enhanced.plugins

    • type
      Object
    • summary
  • dojox.grid.enhanced

    • type
      Object
    • summary
  • dojox.grid

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary