CallBackery

 view release on metacpan or  search on metacpan

lib/CallBackery/qooxdoo/callbackery/source/class/callbackery/ui/MsgBox.js  view on Meta::CPAN

                height : height
            });
            let label = text.toString();

            if (!html) {
                /* we are always rich to get line breaking, but we do NOT
                   allow any HTML tags to execute unless requested */
                var map = {
                    '>': '>',
                    '<': '&lt;',
                    '&': '&amp;'
                };
                label = label.replace(/[<>&]/g,function(m){return map[m]});
            }
            this.__body.setLabel(label);
            this.open();
        },


        /**
         * Create a button which is at least 40 pixel wide
         *
         * @param lab {String} label
         * @param ico {Icon} icon
         * @return {Button} button widget
         */
        __mk_btn : function(key, label) {
            var b = this.__btn[key] = new qx.ui.form.Button(label).set({ minWidth : 60 });
            this.__btnBox.add(b);
            b.addListener('execute',function(){
                this.fireDataEvent('choice',key);
                this.close();
            },this);
        },

        __show_btn: function(btns, icons){
            for (var key in this.__btn){
                this.__btn[key].setVisibility('excluded');
            }
            btns.forEach(function(key){
                this.__btn[key].setVisibility('visible');
                if (icons && icons.button && icons.button[key]) {
                    this.__btn[key].setIcon(icons[key]);
                }
                else {
                    this.__btn[key].setIcon(null);
                }
            },this);
        },

        __setIcons: function(icons) {
            if (icons && icons.caption) {
                this.setIcon(icons.caption);
            }
            if (icons && icons.body) {
                this.__body.setIcon(icons);
            }
        },

        /**
         * Open the Error popup
         *
         * @param title {String} title
         * @param text {String} body
         * @param html {Boolean} allow HTML if true
         * @param icons {Map} of body, button, and title icon strings
         * @param size {Map} of width and height
         * @return {void} 
         */
        error : function(title, text, html, icons, size) {
            this.__setIcons(icons);
            this.__show_btn(['ok'], icons);
            this.__open(title, text, html, size);
            return this;
        },


        /**
         * Show server error message
         *
         * @param exc {Map} callAsync exception
         * @param icons {Map} of title and body icon strings
         * @param icons {Map} of body, button, and title icon strings
         * @param size {Map} of width and height
         * @return {void} 
         */
        exc : function(exc, icons, size) {
            this.__setIcons(icons);
            this.__show_btn(['ok'], icons);
            //var trace = '';
            //if (exc.code == 2 && console.log){
            //    qx.dev.StackTrace.getStackTrace().forEach(function(row){
            //        console.log('stack trace:' + row);
            //    },this);
            // }

            // no HTML
            this.__open(this.tr('RPC Error %1', exc.code), this.xtr(exc.message), false);
            return this;
        },


        /**
         * Open the Info popup
         *
         * @param title {String} title
         * @param text {String} body
         * @param html {Boolean} allow HTML if true
         * @param icons {Map} of body, button, and title icon strings
         * @return {void} 
         */
        info : function(title, text, html, icons, size) {
            this.__setIcons(icons);
            this.__show_btn(['ok'], icons);
            this.__open(title, text, html, size);
            return this;
        },


        /**
         * Open the Warning popup with optional callback
         *
         * @param title {String} window title
         * @param text {String} content
         * @param html {Boolean} allow HTML if true
         * @param icons {Map} of body, button, and title icon strings
         * @param size {Map} of width and height
         * @return {void} 
         */
        warn : function(title, text, html, icons, size) {
            this.__setIcons(icons);
            this.__show_btn(['cancel','apply'], icons);
            this.__open(title, text, html, size);
            return this;
        },
        /**
         * Open the Warning popup with optional callback
         *
         * @param title {String} window title
         * @param text {String} content
         * @param html {Boolean} allow HTML if true
         * @param icons {Map} of body, button, and title icon strings
         * @param size {Map} of width and height
         * @return {void} 
         */
        yesno : function(title, text, html, icons, size) {
            this.__setIcons(icons);
            this.__show_btn(['yes','no'], icons);
            this.__open(title, text, html, size);
            return this;
        }

        ,

        /**
         * Session-expired prompt: a single Reload action.
         *
         * @param title {String} window title
         * @param text {String} content
         * @return {void}
         */
        sessionExpired : function(title, text) {
            this.__show_btn(['reload']);
            this.__open(title, text, false);
            return this;
        },

        /**
         * Communication-problem prompt: Retry (re-issue) or Reload (fresh page).
         *
         * @param title {String} window title
         * @param text {String} content
         * @return {void}
         */
        commError : function(title, text) {
            this.__show_btn(['retry','reload']);
            this.__open(title, text, false);
            return this;
        }
    }
});



( run in 0.799 second using v1.01-cache-2.11-cpan-364913b4093 )