<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Efficy Overflow Q&amp;A - Recent questions tagged useroptions</title>
<link>https://overflow.efficy.io/?qa=tag/useroptions</link>
<description>Powered by Question2Answer</description>
<item>
<title>User Option : Default Display Grid Density?</title>
<link>https://overflow.efficy.io/?qa=6450/user-option-default-display-grid-density</link>
<description>&lt;p&gt;Dear all, &lt;/p&gt;

&lt;p&gt;Since Efficy 11.3 Release Build r18130, a new functionnality &quot;grid density&quot; appears.&lt;br&gt;
The setting can be found in User Option : comfortable, intermediate, compact.&lt;/p&gt;

&lt;p&gt;It seems in the documentation, that we can set the default User Option from SYS_SETTINGS : &quot;gridDisplayDensity&quot; (cf EDN : &lt;a rel=&quot;nofollow&quot; href=&quot;https://help.efficy.io/edn/dev/cust_definegridcolumns&quot;&gt;&lt;/a&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://help.efficy.io/edn/dev/cust_definegridcolumns&quot;&gt;https://help.efficy.io/edn/dev/cust_definegridcolumns&lt;/a&gt;) &lt;/p&gt;

&lt;p&gt;I try to find in &lt;code&gt;SYS_SETTINGS&lt;/code&gt; the &quot;gridDisplayDensity&quot; option, but I cannot find it. &lt;br&gt;
Should we add it manually, if so where in sys_settings should we do that ?&lt;/p&gt;

&lt;p&gt;Best Regards&lt;/p&gt;
</description>
<category>Efficy Installation/Settings</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=6450/user-option-default-display-grid-density</guid>
<pubDate>Fri, 04 Feb 2022 13:30:07 +0000</pubDate>
</item>
<item>
<title>Implementing a UserOption feature through sys_storage and serverside scripts</title>
<link>https://overflow.efficy.io/?qa=5224/implementing-useroption-feature-sysstorage-serverside</link>
<description>&lt;p&gt;Hi guys, &lt;/p&gt;

&lt;p&gt;I recently needed to implement a session persistent user options feature in Efficy &lt;br&gt;
since sys_storage is the recommended way to do so I ve made a module that will allow you to set and get user options from a serverjs module.&lt;/p&gt;

&lt;p&gt;this is how to implement / use it : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/*
@import SUO from serverjs/storageUserOptions
*/

SUO.init({id: 123});      // optional: only if you  want to use options of another User (default is Efficy.currentUserId)

// for now there is no sys_storage named userOption_123 (yet)

var temp = SUO.get()    
// expected temp = &quot;&quot;;

SUO.set(&quot;myOption&quot;, 12);
// there is now a sys_storage named userOption_123 whose value is : &quot;{\&quot;myOption\&quot;: 12}&quot;    //---(string)

temp = SUO.get();
// expected temp = {&quot;myOption: 12&quot;}   //---(object)  

temp = SUO.get(&quot;myOption&quot;);
// expected temp = 12       //---(number)

SUO.set(&quot;myOption2&quot;, {
    mySubOption1: true,
    mySubOption2: &quot;subOptionValue2&quot;,
    mySubOption3: {
        id: 1
    }
});
// there is now a sys_storage named userOption_123 whose value is : (string)
// {
//     &quot;myOption&quot;: 12,
//     &quot;myOption2&quot;: {
//         &quot;mySubOption1&quot;: true,
//         &quot;mySubOption2&quot;: &quot;subOptionValue2&quot;,
//         &quot;mySubOption3&quot;: {
//             &quot;id&quot;: 1
//         }
//     }
// }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;this is the code of the serverjs/storageUserOptions module : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/*
@import $ from serverjs/jUtils
*/
return (function(){
    var options = {
        id: Efficy.currentUserId
    };

    function test(_options){
        return &quot;test&quot;
    }

    function init(_options){
        if (typeof _options === &quot;object&quot;){
            $.forEach($.keys(_options), function(_key){
                if (options.hasOwnProperty(_key)) options[_key] = _options[_key];
            });
        }

        return options;
    }

    function get(_optionName){
        var result;
        var data = _getStorageUserOptions();

        if (typeof _optionName === &quot;string&quot;) result = data[_optionName];
        else result = data;

        return result;
    }

    function set(_optionName, _optionValue){
        if(typeof _optionName !== &quot;string&quot;) throw new Error(&quot;storageUserOptions.set() invalid arguments&quot;);

        var data = {};
        data[_optionName] = _optionValue;

        _setStorageUserOptions(data);

        return;
    }

    function _setStorageUserOptions(_options){

        var result = _getStorageUserOptions();
        result = $.merge(result, _options);

        Efficy.setSysStorageValue(&quot;userOption_&quot; + options.id, JSON.stringify(result, null, &quot;\t&quot;));

        return result;
    }

    function _getStorageUserOptions(){
        var result = Efficy.getSysStorageValue(&quot;userOption_&quot; + options.id) || &quot;{}&quot;;

        try{
            result = JSON.parse(result);
        } catch(e){
            throw new Error([&quot;&quot;,
                &quot;_getStorageUserOption parse error&quot;, 
                &quot;id: &quot; + options.id,
                &quot;value: &quot; + result,
                &quot;message: &quot; + e.message
            ].join(&quot;&amp;lt;br/&amp;gt;&quot;));
        }

        return result;
    }

    var public = {
        test: test,
        init: init,
        set: set,
        get: get

    };

    return public;
})();
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and the serverjs/jUtils module that allow me to add some intresting polyfill (like object.keys, merge, ...) &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;return (function(){

    function forEach(_array, _iterator){
        var result;

        for (var i=0; i&amp;lt;_array.length; i++){
            result = _iterator.call(this, _array[i], i);
            if (result === false) break;
        }

        return result;
    }

    function each(_array, _iterator){
        var result;

        for (var i=0; i&amp;lt;_array.length; i++){
            result = _iterator.call(this, i, _array[i]);
            if (result === false) break;
        }
    }

    function merge(){
        var result = {};

        each(arguments, function(_index, _value){
            for(key in _value){
                if (!result[key]){
                    result[key] = _value[key];
                } else if (typeof result[key] === &quot;object&quot; &amp;amp;&amp;amp; typeof result[key].length === &quot;undefined&quot;) {
                    result[key] = merge(result[key], _value[key]);
                } else {
                    result[key] = _value[key];
                }
            }
        });

        return result;  
    }

    function getItem(_array, _searchFunction, _startIndex){
        _startIndex = _startIndex || 0;

        var result = undefined;

        forEach(_array, function(_value, _index){
            if (_searchFunction(_value, _index)){
                result = _value;
                return false;
            }
        });

        return result;
    }

    function format() {
        var args = arguments;
        var result = args[0].replace(/\$\d+/g, function (cap) {
            return args[1 + parseInt(cap.match(/\d+/), 10)];
        });
    }

    function indexOfObject(_array, _searchFunction){

        for (var i=0; i&amp;lt;_array.length; i++){
            if (_searchFunction(_array[i])) {
                return i;
            }
        }

        return -1;
    }

    function getFunctionName(_function){
        var result = _function.toString();
        result = result.substr('function '.length);
        result = result.substr(0, result.indexOf('('));
        return result;
    }

    var keys = (function() {
        'use strict';
        var hasOwnProperty = Object.prototype.hasOwnProperty,
          hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'),
          dontEnums = [
            'toString',
            'toLocaleString',
            'valueOf',
            'hasOwnProperty',
            'isPrototypeOf',
            'propertyIsEnumerable',
            'constructor'
          ],
          dontEnumsLength = dontEnums.length;

        return function(obj) {
          if (typeof obj !== 'function' &amp;amp;&amp;amp; (typeof obj !== 'object' || obj === null)) {
            throw new TypeError('Object.keys called on non-object');
          }

          var result = [], prop, i;

          for (prop in obj) {
            if (hasOwnProperty.call(obj, prop)) {
              result.push(prop);
            }
          }

          if (hasDontEnumBug) {
            for (i = 0; i &amp;lt; dontEnumsLength; i++) {
              if (hasOwnProperty.call(obj, dontEnums[i])) {
                result.push(dontEnums[i]);
              }
            }
          }
          return result;
        };
      }());

    var public = {
        merge: merge,
        forEach: forEach,
        each: each,
        getItem: getItem,
        format: format,
        indexOfObject: indexOfObject,
        getFunctionName: getFunctionName,
        keys: keys
    };

    return public;
})();
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=5224/implementing-useroption-feature-sysstorage-serverside</guid>
<pubDate>Tue, 21 Jan 2020 15:46:34 +0000</pubDate>
</item>
</channel>
</rss>