<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Efficy Overflow Q&amp;A - Recent questions tagged modules</title>
<link>https://overflow.efficy.io/?qa=tag/modules</link>
<description>Powered by Question2Answer</description>
<item>
<title>How to use modules features in Dialog pages</title>
<link>https://overflow.efficy.io/?qa=2416/how-to-use-modules-features-in-dialog-pages</link>
<description>&lt;p&gt;Hi, &lt;/p&gt;

&lt;p&gt;Recently I had to implement a feature in Efficy that would allow the user to interact with some custom data through different pages. Those pages were not related to any entity nor records of the CRM. &lt;/p&gt;

&lt;p&gt;the use of dialogs appeared to me to be the best practice, so my problematic was to open an empty page (dialog) that would allow me to use the data-msg and data-channel and commands features in custom modules. This post is here to explain how to make this works all together.&lt;/p&gt;

&lt;p&gt;Behold, you will need a good understanding of the modules overrides techniques, and how macros works.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First step : create your page template&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;so there is a test2.htm template that I ve put in : &lt;br&gt;
customs\Test\pages\dialog\test2.htm&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;%SetBookmark()%&amp;gt;
&amp;lt;%LoadMacros('MacroLibrary;MacroDialog')%&amp;gt;
&amp;lt;%Macro('Doctype')%&amp;gt;
&amp;lt;html lang=&quot;&amp;lt;%GetLanguage(lowercase=T)%&amp;gt;&quot; dir=&quot;&amp;lt;%OnLanguage(ar='rtl', else='ltr')%&amp;gt;&quot;&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;test&amp;lt;/title&amp;gt;
    &amp;lt;%Macro('MetaHead')%&amp;gt;
    &amp;lt;%UseStyleSheet(page='%%OnLanguage(ar=&quot;efficy-rtl&quot;, else=&quot;efficy&quot;)')%&amp;gt;
    &amp;lt;%UseScript('../lib/js/vendor/modernizr.js', fixedline=T, fixedpath=T)%&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body onload=&quot;Loaded()&quot; data-keep-size&amp;gt;
&amp;lt;div class=&quot;row dialog-wrapper&quot; data-channel=&quot;dialog/main&quot;&amp;gt;
    &amp;lt;div class=&quot;small-12 columns&quot;&amp;gt;
        &amp;lt;h3 class=&quot;section-title&quot;&amp;gt;&amp;lt;%GetLabel('My dialog is awesome')%&amp;gt;&amp;lt;/h3&amp;gt;

        &amp;lt;div class=&quot;toolbar medium&quot; data-channel=&quot;dialog/main&quot;&amp;gt;

            &amp;lt;button class=&quot;action i-add&quot; data-msg=&quot;msgAddChart&quot; type=&quot;button&quot;&amp;gt;&amp;lt;/button&amp;gt;

        &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;!--&amp;lt;/body&amp;gt;--&amp;gt;
&amp;lt;%Macro('DialogScriptsRequire')%&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;some explaination:&lt;/p&gt;

&lt;p&gt;As you can see I already add a data-channel class in my wrapper and a data-msg in my button. (it's not a guide step by step, it s more a file by file^^)&lt;/p&gt;

&lt;p&gt;the MacroLibrary file and MacroDialog are the 2 only macro files I wanted to need to make it work but feel free to use some more for your personnal customs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2nd step : Override MacroDialog&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The DialogScriptsRequire is loaded in the body to respect the architecture and async loads spirit.&lt;/p&gt;

&lt;p&gt;this is what you ll find in my MacroDialogCustomFile : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;MainJsModuleCustom {[custom/main/dialog]}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will allow me to completely override the main dialog module.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;RequireConfigCustom {[
    &amp;lt;%UseScript('custom/js/config/require.config.js')%&amp;gt;
]}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;since I will need to override some module I will need to edit my custom require.config file so I need my dialog to know that the custom file has to be loaded.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3rd step : override the main/dialog module&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Implement the main/dialog module now : this is what i ve put in my custom/main/dialog.js file : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;define([
    'domReady!',
    'jquery',
    'class',
    'windowManager',
    'config/foundation',
    'custom/commands/dialogCmd',
    'commandPublisher'
], function (doc, $, Class, WindowManager, Foundation, DialogCmd, CommandPublisher) {

    var dialog = new (Class.extend({

        start: function() {
            console.log(&quot;Custom module dialog.js started&quot;);
            window.__debug = true;
            $(document).foundation();
            WindowManager.start();
            DialogCmd.start();
            CommandPublisher.start();
        },

        stop: function() {
            WindowManager.stop();
        }

    }))();

    // Auto start when loaded via data-main
    dialog.start();

    return dialog;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;you will probably recognize the standard dialog module with more modules : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;custom/commands/dialogCmd : a full custom modules that will be in&lt;br&gt;
charge to have all the commands I need (just a test function in my&lt;br&gt;
example)&lt;/li&gt;
&lt;li&gt;commandPublisher : the module that will transform a data-channel/data-msg classes in events emitters&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;these modules are started on start and I ve added a console log and a __debug = true to monitor in firebug that my code is well loaded.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;step 4 : create a custom/commands/dialogCmd module&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is my dialogCmd minimum code : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;define([
    'jquery',
    'constants',
    'model',
    'browser',
    'commandListener',
    'format',
    'url'
], function($, Const, Model, Browser, CommandListener, format, Url) {
    console.log(&quot;custom module dialogCmd loaded&quot;);

    function test(){
        alert(&quot;test ok&quot;);
    }

    var commands = {
        &quot;msgTest&quot; : test,
    };

    return new CommandListener(Const.VIEW_CHANNEL + 'dialog/main', commands);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;the only required modules here are : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;constants &lt;/li&gt;
&lt;li&gt;commandListerner&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;the rest is here because I like those modules and I did intend to use it later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5th step : double check...&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;you will need to check in your console when your dialog is loaded that you will have this :&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://overflow.efficy.com/?qa=blob&amp;amp;qa_blobid=5308775186027742225&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;

&lt;p&gt;but right now you won't cause you probably have not edit your require.config.js file there is the line you will have to add :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;require.overrideModule('commands/dialogCmd');
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I know you are not overriding any existing module but, if it's stupid and it works... it's not supid.&lt;/p&gt;

&lt;p&gt;I am pretty sure plenty of optimizition are makable, feel free to answer this post to improve the solution I ve found.&lt;/p&gt;

&lt;p&gt;Cheers, May ficy be with you folks&lt;/p&gt;
</description>
<category>Efficy/ Client side</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=2416/how-to-use-modules-features-in-dialog-pages</guid>
<pubDate>Tue, 28 Mar 2017 16:25:22 +0000</pubDate>
</item>
</channel>
</rss>