November Happy Hour will be moved to Thursday December 5th.

Dijit/Dojo Gadget runs button multiple times

Vote:
 

I made a edit-gadget with some buttons to trigger subscription mail.

So if I trigger a mail to be sent out everything works fine, but if you then start to navigate around pagetree it will trigger the button push on every context change, so that means the same email gets sent out multiple times.

I`ve tride different approachs like disconnecting the button, connecting the button-event from the JS instead of the HTML etc.

Any good fixes? :)

#116101
Jan 23, 2015 9:38
Vote:
 

Can you share some code with us?

#116118
Jan 23, 2015 12:57
Vote:
 
<div>
    <div class="epi-gadgetInnerToolbar" data-dojo-attach-point="toolbar">        
        <button data-dojo-type="dijit/form/Button" 
                data-dojo-attach-point="norwegian" 
                data-dojo-props="intermediateChanges:true">Norsk</button>
        <button data-dojo-type="dijit/form/Button" 
                data-dojo-attach-point="english" 
                data-dojo-props="intermediateChanges:true">Engelsk</button>
        <button data-dojo-type="dijit/form/Button" 
                data-dojo-attach-point="dual" 
                data-dojo-props="intermediateChanges:true" title="" >Begge språk</button>
    </div>
    <div>
        <input type="text" data-dojo-attach-point="Mail" style="margin-left: 10px; margin-right: 5px;"/>
        <button data-dojo-type="dijit/form/Button" 
            data-dojo-attach-point="test" 
            data-dojo-props="intermediateChanges:true">Send test mail</button>
    </div>
    <div>
        <textarea rows="2" readonly="true" data-dojo-attach-point="Content" style="width: 100%; height: 100px"></textarea>
    </div>
    <div style="display: none" data-dojo-type="epi-cms/component/ContentQueryGrid" data-dojo-attach-point="contentQuery" />
    
</div>
define([
    "dojo/_base/declare",
    "dojo/dom-geometry",
    "dijit/_TemplatedMixin",
    "dijit/_Container",
    "dijit/layout/_LayoutWidget",
    "dijit/_WidgetsInTemplateMixin",

    "epi-cms/component/ContentQueryGrid",
    "dojo/text!./CustomSearch.html"],
    function (// Dojo        
        declare,
        domGeometry,
    // Dijit    
        _TemplatedMixin,
        _Container,
        _LayoutWidget,
        _WidgetsInTemplateMixin,
    // EPi CMS    
        ContentQueryGrid,
        template) {
        return declare([
            _Container,
            _LayoutWidget,
            _TemplatedMixin,
            _WidgetsInTemplateMixin
        ],
        {
            templateString: template,
            postCreate: function() {
                this.connect(this.norwegian, "onClick", this._NorwegianQuery);
                this.connect(this.english, "onClick", this._EnglishQuery);
                this.connect(this.dual, "onClick", this._DualQuery);
                this.connect(this.test, "onClick", this._TestQuery);
            },
            resize: function(newSize) {
                this.inherited(arguments);
                var toolbarSize = domGeometry.getMarginBox(this.toolbar);
                var gridSize = { w: newSize.w, h: newSize.h - toolbarSize.h };
                this.contentQuery.resize(gridSize);
            },

            _NorwegianQuery: function() {
                var contextService = epi.dependency.resolve("epi.shell.ContextService");
                var currentContext = contextService.currentContext;
                this.contentQuery.set("queryParameters", { queryText: "no", CurrentPage: currentContext.id });
                this.contentQuery.set("queryName", "CustomQuery");
                this.Content.value = "Mail sendt til norske abonnenter for siden " + currentContext.name;
                this.disconnect(this.norwegian, "onClick", this._NorwegianQuery);
            },

            _EnglishQuery: function() {
                var contextService = epi.dependency.resolve("epi.shell.ContextService");
                var currentContext = contextService.currentContext;
                this.contentQuery.set("queryParameters", { queryText: "en", CurrentPage: currentContext.id });
                this.contentQuery.set("queryName", "CustomQuery");
                this.Content.value = "Mail sendt til engelske abonnenter for siden " + currentContext.name;
            },

            _DualQuery: function() {
                var contextService = epi.dependency.resolve("epi.shell.ContextService");
                var currentContext = contextService.currentContext;
                this.contentQuery.set("queryParameters", { queryText: "dual", CurrentPage: currentContext.id });
                this.contentQuery.set("queryName", "CustomQuery");
                this.Content.value = "Mail sendt til alle abonnenter for siden " + currentContext.name;
            },

            _TestQuery: function() {
                var mail = this.Mail.value;
                var contextService = epi.dependency.resolve("epi.shell.ContextService");
                var currentContext = contextService.currentContext;
                this.contentQuery.set("queryParameters", { queryText: "test", CurrentPage: currentContext.id, Mail: mail });
                this.contentQuery.set("queryName", "CustomQuery");
                this.Content.value = "Test mail sendt til " + mail + " for siden " + currentContext.name + " på engelsk og norsk";
            },
            contextChanged: function(context, callerData) {
                alert("context change " + context.name);
            }
    });
    });



The service  that picks up the event works fine :)

#116124
Jan 23, 2015 13:43
Vote:
 

I posted the post on the wrong username :)

I do not care about the context change, but I tried to test to see if it was that part that fucked up the code.
I am new to dijit/dojo, and pieced this togthere from stuff I found on the internet.

#116128
Jan 23, 2015 13:53
Vote:
 

I am not 100% shore but I would try to remove intermediateChanges:true from the button element, can't really see why you need the button to be auto updated with that property. I am no DOJO expert, but it is worth a try ;-)

good luck!

#116152
Jan 24, 2015 19:40
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.