<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Efficy Overflow Q&amp;A - Recent questions tagged editentitygrid</title>
<link>https://overflow.efficy.io/?qa=tag/editentitygrid</link>
<description>Powered by Question2Answer</description>
<item>
<title>Document and Opportunity model : add property like 'EditEntityGridActi'</title>
<link>https://overflow.efficy.io/?qa=3721/document-opportunity-model-property-editentitygridacti</link>
<description>&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;Efficy version : 10.2&lt;/p&gt;

&lt;p&gt;In the TabContentProds (Edit window of Documents and Opportunities), I need that the client scripts in MacroEditS do some computations following the value of some fields of PRODUCTS&lt;br&gt;
I mean for example the have to do &lt;strong&gt;2+2 if PRODUCTS.FAMILY==1&lt;/strong&gt; or &lt;strong&gt;2*2 if PRODUCTS.FAMILY != 1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But, &lt;strong&gt;I do not want to&lt;/strong&gt; put the value of PRODUCTS.FAMILY in the html (example) :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;tr class=&quot;mission&quot; data-family=&amp;lt;#F=FAMILY;nospace=T&amp;gt; [...] &amp;lt;/tr&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and use it in MacroEditS like&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$('.mission').each(function() {
  var family = $(this).data('family');
})
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I would prefer to use the Model, is it possible to add &lt;strong&gt;'EditEntityGridProd'&lt;/strong&gt; like &lt;strong&gt;'EditEntityGridActi'&lt;/strong&gt; in &lt;strong&gt;'JsonEditModel.Docu/editEntityGrids'&lt;/strong&gt; ?&lt;/p&gt;

&lt;p&gt;Am I obliged to use &lt;strong&gt;'&amp;lt;%GetRelationGrid([...])%&amp;gt;'&lt;/strong&gt; in the Model ? This function tag is already used to generate the html grid in 'TabContentProds' so can I not generate this part of the model here ?&lt;/p&gt;

&lt;p&gt;Last question : How to access it in the script ?&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;// 1 because I will place it in the array after EditEntityGridActi
var ProductsData = Model('editEntityGrids[1]')
// or
var ProductsData = Model('editEntityGrids')[1]
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>How to</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=3721/document-opportunity-model-property-editentitygridacti</guid>
<pubDate>Fri, 07 Dec 2018 11:40:49 +0000</pubDate>
</item>
<item>
<title>Override js/editentitygrid/main.js</title>
<link>https://overflow.efficy.io/?qa=3541/override-js-editentitygrid-main-js</link>
<description>&lt;p&gt;Hi!&lt;/p&gt;

&lt;p&gt;I want to customize override the &quot;add&quot; function of this module but Efficy don't load the file to override the standard.&lt;/p&gt;

&lt;p&gt;I speak with the Efficy Support and they said me it's the better way to add the field &quot;NATURE&quot; in the Acti grid in Document Edit&lt;/p&gt;

&lt;p&gt;The customization works ! when I put this directly in the standard code it's works, the problem is just that Efficy don't load the file.&lt;br&gt;
I have already override some commands on this windows and it's work.&lt;/p&gt;

&lt;p&gt;I import it in require.config.js&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;require.overrideModule('editentitygrid/main');      // EFFICY DONT IMPORT IT
require.overrideModule('validation/editDocu');      // WORKS
require.overrideModule('commands/gridtoolsAddCmd'); // WORKS
require.overrideModule('commands/editCmd');         // WORKS
require.overrideModule('commands/editdetailsCmd');  // WORKS
require.overrideModule('commands/detailMenuCmd');   // WORKS
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The file have the same name and folder structure : js/editentitygrid/main.js (you can use ctrl+F for &quot;// OVERRIDE FUNCTION&quot; to view the customization)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;define([
    'require',
    'jquery',
    'class',
    'constants',
    'format',
    'html',
    'model',
    'microtemplate',
    'editentitygrid/dataSet'
], function(require, $, Class, Const, format, html, Model, microTemplate, DataSet){
    console.log(&quot;custom editentitygrid/main.js loaded&quot;)

    return Class.extend({

        init: function(EditEntityGrid, linkedEntities, separator) {
            if (!EditEntityGrid) {
                this.log('Initilization failed: EditEntityGrid must Exist');
            } else {
                this.name = EditEntityGrid.name;
                this.uniqueName = format('{editHandle}.$0', this.name);
                this.entity = EditEntityGrid.entity;
                this.detailZoneId = this.name;
                this.detailZone = $('.' + this.name).find('.contentList');
                this.detailZone.data('EditEntityGrids', this);
                this.detailZoneParent = this.detailZone.parent();
                this.separator = separator || '';
                this.templateName = EditEntityGrid.template;
                this.template = null;
                this.lineCount = 1;
                this.data = EditEntityGrid.data;
                this.dataset = new DataSet(EditEntityGrid.entity, (EditEntityGrid.linkToCurrentEntity) ? Model('editHandle') : 0, linkedEntities);
                $(window).on('unload', this.cancelAll.bind(this));
                this.loadExistingData(this.data);
                EditEntityGrid.instance = this;
                if (this.detailZone.length !== 1) {
                    this.log('Initilization failed: zone not found or present many times');
                } else {
                    this.log('Edit Entity Grid initilization complete');
                }
            }
        },

        loadExistingData: function (existingData) {
            var
                items = JSON.parse(localStorage.getItem(this.uniqueName)),
                alreadyLoadedKeys = [];
            if (items) { // data exist in localstorage
                $.each(items.datas, function (id, item) {
                    if (item) {
                        item.entity = this.entity;
                        this.add(item);
                        alreadyLoadedKeys.push(+item.key); // add key to already loaded list as an numeric value
                    }
                }.bind(this));
            }
            if (existingData) {
                $.each(existingData, function (id, data) {
                    if (!alreadyLoadedKeys.length || alreadyLoadedKeys.indexOf(+data.key) === -1) { // data don't exist in localstorage --&amp;gt; load database data.
                        if (!data.DONE.length) { // TRW: Load missing information
                            var url = 'consult?entity=' + this.entity + '&amp;amp;key=' + data.key + '&amp;amp;detail=' + this.entity + '&amp;amp;_MACROFILE=MacroConsult.txt&amp;amp;_MACRO=GetEntityDetails&amp;amp;norecent=T';
                            $.getJSON(url)
                                .done(function (json) {
                                    if (json) {
                                        if (window.__debug) {
                                            console.log(json)
                                        }
                                        data.SUBJECT = json.SUBJECT;
                                        data.D_BEGIN = json.D_BEGIN;
                                        data.MEMO = json.MEMO;
                                        data.DONE = json.DONE;
                                    }
                                })
                                .fail(function (jqxhr, textStatus, error) {
                                    if (window.__debug) {
                                        console.log(jqxhr, textStatus, error)
                                    }
                                });
                        }
                        data.entity = this.entity;
                        this.add(data);
                    }
                }.bind(this));
            }
        },

        mergeTemplate: function(template, args) {
            return microTemplate(template, {rec: args || {}});
        },
        // OVERRIDE FUNCTION
        add: function(args) {
            var
                $html,
                url;

                if(args) {
                    url = format('text!dialog?_macrofile=MacroEdit&amp;amp;_macro=$0&amp;amp;_nature=$1', this.templateName, args.NATURE);
                }
                else {
                    url = format('text!dialog?_macrofile=MacroEdit&amp;amp;_macro=$0', this.templateName);
                }

            require([url], function(template) {
                if (!args){
                    args = {};
                    args.OPENED = '1';
                }
                args.lineId = this.lineCount;
                args.entity = this.entity;
                $html = $(this.mergeTemplate(template, args));
                if (this.lineCount === 1) {
                    this.detailZone.empty().append($html);
                } else {
                    this.detailZone.append(this.separator);
                    this.detailZone.append($html);
                    $('body').animate({
                        scrollTop: $html.offset().top
                    }, 1000);
                }
                this.lineCount++;
            }.bind(this));
        },

        addData: function (lineId, datas) {
            this.dataset.add(lineId, datas);
        },

        saveToLocalStorage: function () {
            localStorage.removeItem(this.uniqueName);
            this.fetchData(true);
            localStorage.setItem(this.uniqueName, JSON.stringify(this.dataset));
        },

        commit: function (queue, callback) {
            this.fetchData();
            $.post(
                format('dialog?_macrofile=MacroAjax&amp;amp;_macro=runscript&amp;amp;file=libjson;$0&amp;amp;func=$1', &quot;serverscripts/EditEntityGrid.js&quot;, &quot;Commit&quot;),
                {json: JSON.stringify(this.dataset)}
            ).done( function(html) {
                var errorCount = 0;
                var results = JSON.parse(html);

                $.each(results, function(id, result) {
                    var $line = this.detailZone.find('[data-line=' + result.lineId + ']');
                    if (parseFloat(result.result, 10)) {
                        $line.attr('data-modified', false);
                        $line.attr('data-key', parseFloat(result.result, 10));
                        $line.removeClass('edit-entity-grid-error');
                        $line.find('.edit-entity-grid-error-msg').remove();
                    } else {
                        errorCount++;
                        $line.addClass('edit-entity-grid-error')
                                 .append($('&amp;lt;div class=&quot;row small-12 columns text-end edit-entity-grid-error-msg&quot;&amp;gt;&amp;lt;span class=&quot;i-not-done&quot;&amp;gt;' + result.result + '&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;'));
                    }
                }.bind(this));

                if ( errorCount === 0 ) {
                    console.log('no error');
                    localStorage.removeItem(this.uniqueName);
                    this.disableAllFields();
                    queue.requestComplete(true);
                }
            }.bind(this));
        },

        fetchData: function(allData) {
            var editEntities = this.detailZone.find('div.row[data-line]');
            $.each(editEntities, function (id, editEntity) {
                var $editEntity = $(editEntity);
                if (allData || $editEntity.attr('data-modified') === 'true') {
                    var data = (html.elementToJson($editEntity));
                    data.modified = $editEntity.attr('data-modified');
                    data.lineId = $editEntity.attr('data-line');
                    data.key = $editEntity.attr('data-key');
                    this.addData(data.lineId, data);
                }
            }.bind(this));
        },

        cancelAll: function() {
            localStorage.removeItem(this.uniqueName);
        },

        disableAllFields: function() {
            this.detailZone.detach();
        },

        enableAllFields: function() {
            this.detailZoneParent.append(this.detailZone);
        },

        log: function(msg) {
            if (typeof console === 'object' &amp;amp;&amp;amp; window.__debug) {
                console.log(msg);
            }
        }

    });
});
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Efficy/ Client side</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=3541/override-js-editentitygrid-main-js</guid>
<pubDate>Thu, 13 Sep 2018 16:04:23 +0000</pubDate>
</item>
</channel>
</rss>