0 votes

Hi!

I want to customize override the "add" function of this module but Efficy don't load the file to override the standard.

I speak with the Efficy Support and they said me it's the better way to add the field "NATURE" in the Acti grid in Document Edit

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.
I have already override some commands on this windows and it's work.

I import it in require.config.js

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

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

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

    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 --> load database data.
                        if (!data.DONE.length) { // TRW: Load missing information
                            var url = 'consult?entity=' + this.entity + '&key=' + data.key + '&detail=' + this.entity + '&_MACROFILE=MacroConsult.txt&_MACRO=GetEntityDetails&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&_macro=$0&_nature=$1', this.templateName, args.NATURE);
                }
                else {
                    url = format('text!dialog?_macrofile=MacroEdit&_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&_macro=runscript&file=libjson;$0&func=$1', "serverscripts/EditEntityGrid.js", "Commit"),
                {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($('<div class="row small-12 columns text-end edit-entity-grid-error-msg"><span class="i-not-done">' + result.result + '</span></div>'));
                    }
                }.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' && window.__debug) {
                console.log(msg);
            }
        }

    });
});
asked in Efficy/ Client side by (245 points)

Please log in or register to answer this question.

1,169 questions
1,427 answers
1,718 comments
325 users