var Jade;
(function (Jade) {
    class Collection {
        constructor(data = null) {
            this.m_innerList = [];
            if (data != null) {
                if (!_.isArray(data)) {
                    data = [data];
                }
                this.m_innerList = data;
            }
        }
        get innerList() {
            return this.m_innerList;
        }
        get count() {
            return this.innerList.length;
        }
        onChange() {
        }
        add(item) {
            if (this.contains(item)) {
                return;
            }
            this.innerList[this.m_innerList.length] = item;
            this.onChange();
            return true;
        }
        addRange(items) {
            if (_.isArray(items) && items.length > 0) {
                _.each(items, (item, index) => {
                    this.add(item);
                });
            }
        }
        contains(item) {
            var result = false;
            this.each((itemToCompare, index) => {
                if (item === itemToCompare) {
                    result = true;
                    return false;
                }
            });
            return result;
        }
        clear() {
            this.m_innerList = [];
            this.onChange();
        }
        each(callback) {
            var abort = false;
            _.each(this.innerList, (item, index) => {
                if (abort === false) {
                    abort = callback(item, index) === false;
                }
                return !abort;
            });
        }
        first() {
            return _.first(this.innerList);
        }
        item(index) {
            var result = null;
            if (index < this.count) {
                result = this.innerList[index];
            }
            return result;
        }
        indexOf(item) {
            return _.indexOf(this.innerList, item);
        }
        insert(item, index) {
            var result = false;
            if (this.count >= index && index > -1) {
                this.innerList.splice(index, 0, item);
                result = true;
                this.onChange();
            }
            return result;
        }
        insertRange(items, insertIndex) {
            if (insertIndex == undefined) {
                insertIndex = 0;
            }
            if (_.isArray(items) && items.length > 0) {
                items.reverse();
                _.each(items, (item, index) => {
                    this.insert(items[index], insertIndex);
                });
            }
            else {
                throw "The parameter 'items' is typed as Array<T> but the value provided is not derived of this type.";
            }
        }
        move(item, index) {
            var removed = null;
            if (this.count <= index) {
                return;
            }
            removed = this.remove(item);
            if (index != null) {
                this.insert(removed, index);
            }
            else {
                this.add(removed);
            }
        }
        last() {
            return _.last(this.innerList);
        }
        remove(item) {
            let index = this.indexOf(item);
            let result = null;
            if (index > -1) {
                result = this.removeAt(index);
            }
            return result;
        }
        removeAt(index) {
            var result = null;
            if (this.count > index) {
                result = this.innerList.splice(index, 1)[0];
                this.onChange();
            }
            else {
                throw "Index " + index + " exceeds the bounds of the array!";
            }
            return result;
        }
        removeAtIndices(indices) {
            var result = [];
            var sortNumeric = (array) => {
                array.sort((item1, item2) => {
                    return item2 - item1;
                });
            };
            if (_.isArray(indices) && indices.length > 0) {
                sortNumeric(indices);
                _.each(indices, (index) => {
                    result[result.length] = this.removeAt(indices[index]);
                });
            }
            return result;
        }
        reverse() {
            this.innerList.reverse();
            this.onChange();
        }
        reverseCopy() {
            return new Collection(this.innerList.slice(0).reverse());
        }
        sort(fn) {
            this.innerList.sort(fn);
            this.onChange();
        }
        toArray() {
            return this.m_innerList.slice(0);
        }
        transform(callback) {
            var result = [];
            this.each(function (item) {
                let transform = callback(item);
                if (transform != null) {
                    result[result.length] = transform;
                }
                ;
            });
            return result;
        }
        getByType(type) {
            let result = new Collection();
            this.each((item) => {
                if (item instanceof type) {
                    result.add(item);
                }
            });
            return result;
        }
    }
    Jade.Collection = Collection;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class Ajax {
        static onBeforeSend(callback) {
            this._onBeforeSend.add(callback);
        }
        static onSuccess(callback) {
            this._onSuccess.add(callback);
        }
        static onError(callback) {
            this._onError.add(callback);
        }
        static onComplete(callback) {
            this._onComplete.add(callback);
        }
        static call(options) {
            var ajaxEvents = {
                beforeSend: function (jqXHR, settings) {
                    if (_.isFunction(options.beforeSend)) {
                        options.beforeSend.apply(this, arguments);
                    }
                    Ajax._onBeforeSend.each((callback) => {
                        callback({
                            xhr: jqXHR,
                            settings: settings,
                            status: null
                        });
                    });
                },
                success: function (data, textStatus, jqXHR) {
                    if (_.isFunction(options.success)) {
                        options.success.apply(this, arguments);
                    }
                    Ajax._onSuccess.each((callback) => {
                        callback({
                            xhr: jqXHR,
                            settings: null,
                            status: textStatus
                        });
                    });
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    jqXHR.errorHandled = false;
                    if (_.isFunction(options.error)) {
                        options.error.apply(this, arguments);
                    }
                    Ajax._onError.each((callback) => {
                        callback({
                            xhr: jqXHR,
                            settings: null,
                            status: textStatus
                        });
                    });
                    if (!jqXHR.errorHandled) {
                        new Jade.AjaxErrorHandler({
                            config: this,
                            jqXHR: jqXHR
                        });
                    }
                },
                complete: function (jqXHR, textStatus) {
                    if (_.isFunction(options.complete)) {
                        options.complete.apply(this, arguments);
                    }
                    Ajax._onComplete.each((callback) => {
                        callback({
                            xhr: jqXHR,
                            settings: null,
                            status: textStatus
                        });
                    });
                    if (!jqXHR.suppressEvent) {
                        Jade.Application
                            .instance
                            .contexts
                            .global
                            .events
                            .publish("Ajax:Request:Complete");
                    }
                }
            };
            return $.ajax($.extend({}, options, ajaxEvents));
        }
    }
    Ajax._onBeforeSend = new Jade.Collection();
    Ajax._onSuccess = new Jade.Collection();
    Ajax._onError = new Jade.Collection();
    Ajax._onComplete = new Jade.Collection();
    Jade.Ajax = Ajax;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class AjaxErrorHandler {
        constructor(options) {
            this._options = _.extend({
                config: null,
                jqXHR: null
            }, options);
            if (this.isRedirect()) {
                return;
            }
            if (this.isHeaderError()) {
                return;
            }
            if (this._options != null && this.options.config != null) {
                this._context = this.options.config.contextData;
            }
            this.parseData();
            this.notify();
        }
        get options() {
            return this._options;
        }
        get context() {
            return this._context;
        }
        parseData() {
            var options = this.options;
            try {
                this._data = options.jqXHR.responseJSON;
            }
            catch (ex) {
                this._data = [];
            }
        }
        notify() {
            var isErrorDataAnArray = _.isArray(this._data);
            var fieldErrors = _.filter(this._data, (item) => {
                return item.key != null;
            });
            var fieldlessErrors = _.filter(this._data, (item) => {
                return item.key == null;
            });
            var hasFieldErrors = isErrorDataAnArray && fieldErrors.length > 0;
            var hasFieldlessErrors = isErrorDataAnArray && fieldlessErrors.length > 0;
            var isErrorObject = _.has(this._data, "message");
            var isRequestAborted = this.options.jqXHR.statusText === "abort";
            if (this.hasControl()) {
                this.context.control.enable();
            }
            if (hasFieldErrors && this.hasContext()) {
            }
            if (hasFieldlessErrors) {
                this.showErrorsDialog(fieldlessErrors);
                return;
            }
            if (isErrorObject) {
                this.showErrorsDialog(this._data);
                return;
            }
            if (!hasFieldErrors && !hasFieldlessErrors && !isErrorObject && !isRequestAborted) {
                this.showCatchAllErrorDialog();
            }
        }
        hasFieldErrors() {
            return this._data != null
                && _.isArray(this._data)
                && _.find(this._data, (item) => {
                    return item.key != null;
                });
        }
        hasContext() {
            return this.context != null;
        }
        hasContainer() {
            return this.hasContext()
                && this.context().container != null;
        }
        hasControl() {
            return this.hasContext()
                && this.context.control != null
                && this.context.control.length > 0;
        }
        isRedirect() {
            var redirect = this.options
                .jqXHR
                .getResponseHeader('Http-Redirect');
            if (redirect != null) {
                window.location.href = redirect;
            }
            return redirect != null;
        }
        isHeaderError() {
            var errorMessage = this.options
                .jqXHR
                .getResponseHeader('error-message');
            if (errorMessage != null) {
                Jade.UI.MessageDialog.open({
                    dialogStyle: Jade.UI.MessageDialogStyle.Error,
                    dialogButtons: Jade.UI.MessageDialogButtonStyle.OK,
                    title: "Application Error",
                    message: errorMessage,
                    select: (e) => {
                        e.close();
                    }
                });
            }
            return errorMessage != null;
        }
        showErrorsDialog(errors) {
            if (!_.isArray(errors)) {
                errors = [{ message: errors.message }];
            }
            Jade.UI.ErrorDialog.open({
                dialogStyle: Jade.UI.MessageDialogStyle.Error,
                dialogButtons: Jade.UI.MessageDialogButtonStyle.OK,
                title: "Application Error",
                errors: errors,
                select: (e) => {
                    e.close();
                }
            });
        }
        showCatchAllErrorDialog() {
            Jade.UI.MessageDialog.open({
                dialogStyle: Jade.UI.MessageDialogStyle.Error,
                dialogButtons: Jade.UI.MessageDialogButtonStyle.OK,
                title: "Application Error",
                message: `The system is unable to complete your request due to an unspecified error.<br/><br/>,
                            Please try the operation again and contact your system administrator if the problem persists.`,
                select: (e) => {
                    e.close();
                }
            });
        }
    }
    Jade.AjaxErrorHandler = AjaxErrorHandler;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    Jade.nameof = (name) => name;
    class Application {
        constructor(options) {
            if (Application.m_instance != null) {
                return;
            }
            this.m_options = new Jade.StateBag(options);
            this.m_contexts = new Jade.ContextManager();
            this.m_behaviors = new Jade.BehaviorModuleCollection();
            Application.m_instance = this;
            window[this.name] = this;
            this.onInit(options);
        }
        get behaviors() {
            return this.m_behaviors;
        }
        get id() {
            return this.m_id || this.name;
        }
        set id(value) {
            this.m_id = value;
        }
        static get instance() {
            return this.internalInstance;
            ;
        }
        static get internalInstance() {
            return Application.m_instance;
        }
        static set internalInstance(value) {
            Application.m_instance = value;
        }
        static get hasStarted() {
            return Application.m_hasStarted;
        }
        get name() {
            return this.options.get("name");
        }
        get virtualDirectory() {
            return this.options.get("virtualDirectory");
        }
        get imagePaths() {
            return this.options.get("imagePaths");
        }
        get contexts() {
            return this.m_contexts;
        }
        get options() {
            return this.m_options;
        }
        static onStart(callback) {
            if (Application.hasStarted) {
                callback();
                return;
            }
            Application.m_startFunctions[Application.m_startFunctions.length] = callback;
        }
        onInit(options) {
            this.executeStartUpFunctions();
            this.captureBrowserResizeEvent();
        }
        executeStartUpFunctions() {
            _.each(Application.m_startFunctions, (callback) => {
                callback(this);
            });
            Application.m_hasStarted = true;
        }
        captureBrowserResizeEvent() {
            $(window).resize(_.debounce(() => {
                Jade.Application
                    .instance
                    .contexts
                    .global
                    .events
                    .publish("Window:Resized");
            }, 100));
        }
    }
    Application.m_instance = null;
    Application.m_hasStarted = false;
    Application.m_startFunctions = [];
    Jade.Application = Application;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class Arithmetic {
        static round(number, roundToNearest) {
            return Math.floor(Math.round(number / roundToNearest)) * roundToNearest;
        }
        static roundUp(number, roundToNearest) {
            return Math.ceil(number / roundToNearest) * roundToNearest;
        }
        static roundDown(number, roundToNearest) {
            return Math.floor(number / roundToNearest) * roundToNearest;
        }
        static randomInteger(min, max) {
            return Math.floor(Math.random() * (max - min + 1) + min);
        }
    }
    Jade.Arithmetic = Arithmetic;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class Attribute {
        static get root() {
            return "___attributes___";
        }
        get name() {
            return;
        }
        static define(callback) {
            return function (constr) {
                return class extends constr {
                    constructor(...args) {
                        super(...args);
                        if (this[Attribute.root] == undefined) {
                            this[Attribute.root] = {};
                        }
                        callback(this);
                    }
                };
            };
        }
    }
    Jade.Attribute = Attribute;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    let DiskUnits;
    (function (DiskUnits) {
        DiskUnits[DiskUnits["Bytes"] = 0] = "Bytes";
        DiskUnits[DiskUnits["KB"] = 1] = "KB";
        DiskUnits[DiskUnits["MB"] = 2] = "MB";
        DiskUnits[DiskUnits["GB"] = 3] = "GB";
        DiskUnits[DiskUnits["TB"] = 4] = "TB";
    })(DiskUnits = Jade.DiskUnits || (Jade.DiskUnits = {}));
    class Convert {
        static BytesToUnits(bytes, roundUnitsUnder = DiskUnits.MB) {
            let unit = DiskUnits.Bytes;
            let value = 0;
            let formattedValue = "";
            if (bytes == null) {
                return "";
            }
            _.each(Jade.Enum.GetValues(DiskUnits), (value, index) => {
                if (bytes / Math.pow(1024, index) < 1024) {
                    unit = index;
                    return false;
                }
            });
            value = bytes / Math.pow(1024, unit);
            if (unit < roundUnitsUnder) {
                formattedValue = `${Math.round(value)}`;
            }
            else {
                formattedValue = `${kendo.toString(value, "0.00")}`;
            }
            return `${formattedValue} ${Jade.Enum.GetName(DiskUnits, unit)}`;
        }
    }
    Jade.Convert = Convert;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class Enum {
        static GetNames(enumeration) {
            let keys = Object.keys(enumeration);
            return keys.slice(keys.length / 2, keys.length - 1);
        }
        static GetValues(enumeration) {
            let keys = Object.keys(enumeration);
            let result = [];
            keys = keys.slice(0, (keys.length / 2) - 1);
            _.each(keys, (key) => {
                result[result.length] = enumeration[enumeration[key]];
            });
            return result;
        }
        static GetName(enumeration, value) {
            let names = Enum.GetNames(enumeration);
            let values = Enum.GetValues(enumeration);
            let result = names[values.indexOf(value)];
            return result;
        }
    }
    Jade.Enum = Enum;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    let HttpVerb;
    (function (HttpVerb) {
        HttpVerb["GET"] = "GET";
        HttpVerb["DELETE"] = "DELETE";
        HttpVerb["POST"] = "POST";
        HttpVerb["PUT"] = "PUT";
    })(HttpVerb = Jade.HttpVerb || (Jade.HttpVerb = {}));
    let BrowserEvent;
    (function (BrowserEvent) {
        BrowserEvent["CLICK"] = "click";
        BrowserEvent["CHANGE"] = "change";
        BrowserEvent["DOUBLECLICK"] = "dblclick";
        BrowserEvent["MOUSEDOWN"] = "mousedown";
        BrowserEvent["MOUSEUP"] = "mouseup";
        BrowserEvent["MOUSEOVER"] = "mouseover";
        BrowserEvent["MOUSEENTER"] = "mouseenter";
        BrowserEvent["MOUSELEAVE"] = "mouseleave";
        BrowserEvent["KEYDOWN"] = "keydown";
        BrowserEvent["KEYUP"] = "keyup";
        BrowserEvent["KEYPRESS"] = "keypress";
        BrowserEvent["RESIZE"] = "resize";
        BrowserEvent["FOCUS"] = "focus";
        BrowserEvent["BLUR"] = "blur";
        BrowserEvent["SCROLL"] = "scroll";
    })(BrowserEvent = Jade.BrowserEvent || (Jade.BrowserEvent = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class EventMap {
        constructor() {
            this.m_map = {};
        }
        fire(eventName, ...args) {
            if (this.hasKey(eventName)) {
                this.handlers(eventName).forEach((handler) => {
                    handler.apply(this, args);
                });
            }
        }
        add(eventName, fn) {
            this.ensureKey(eventName);
            this.addHandler(eventName, fn);
        }
        hasKey(key) {
            return this.m_map[key] != null;
        }
        ensureKey(key) {
            if (!this.hasKey(key)) {
                this.m_map[key] = [];
            }
        }
        addHandler(eventName, fn) {
            this.m_map[eventName][this.m_map[eventName].length] = fn;
        }
        handlers(eventName) {
            let result = [];
            if (this.hasKey(eventName)) {
                result = this.m_map[eventName];
            }
            return result;
        }
    }
    Jade.EventMap = EventMap;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class Events {
        static get BrowserResizedEvent() {
            return "Browser:Resized";
        }
        static get BrowserFocusedEvent() {
            return "Browser:Focused";
        }
    }
    Jade.Events = Events;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class Guid {
        static new() {
            return UUID.genV4().toString();
        }
        static empty() {
            return "00000000-0000-0000-0000-000000000000".slice(0);
        }
    }
    Jade.Guid = Guid;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    let IconSetSizeSpecificDirectory;
    (function (IconSetSizeSpecificDirectory) {
        IconSetSizeSpecificDirectory["x16"] = "16x16";
        IconSetSizeSpecificDirectory["x24"] = "24x24";
        IconSetSizeSpecificDirectory["x32"] = "32x32";
        IconSetSizeSpecificDirectory["x48"] = "48x48";
        IconSetSizeSpecificDirectory["x64"] = "64x64";
        IconSetSizeSpecificDirectory["x128"] = "128x128";
        IconSetSizeSpecificDirectory["x256"] = "256x256";
        IconSetSizeSpecificDirectory["x512"] = "512x512";
        IconSetSizeSpecificDirectory["misc"] = "misc";
    })(IconSetSizeSpecificDirectory = Jade.IconSetSizeSpecificDirectory || (Jade.IconSetSizeSpecificDirectory = {}));
    class IconSet {
        constructor(options) {
            this.m_options = null;
            this.m_options = options;
        }
        get ID() {
            return this.options.id;
        }
        get rootPath() {
            return this.options.rootPath;
        }
        get options() {
            return this.m_options;
        }
        resolve(icon, sizeSpecificDirectory) {
            if (icon == null) {
                return null;
            }
            return Jade.Path.resolve(`${this.rootPath}/${sizeSpecificDirectory}/${icon}`);
        }
        static add(data) {
            this.m_list[data.id] = new IconSet(data);
        }
        static get(id) {
            return this.m_list[id];
        }
        static remove(id) {
            delete this.m_list[id];
        }
    }
    IconSet.m_list = {};
    Jade.IconSet = IconSet;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class Instance {
        static isEmptyObject(item) {
            for (let key in item) {
                if (item.hasOwnProperty(key)) {
                    return false;
                }
            }
            return true;
        }
    }
    Jade.Instance = Instance;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class InterfaceGuard {
        static get root() {
            return "___interfaces___";
        }
        static is(target, ...guards) {
            let result = false;
            if (target != null) {
                this.iterateGuards(guards, (guard) => {
                    let is = this.hasInterface(target, guard.signature.id);
                    if (!is) {
                        result = false;
                        return false;
                    }
                    else {
                        result = true;
                    }
                });
            }
            return result;
        }
        static isAny(target, ...guards) {
            let result = false;
            if (target != null) {
                this.iterateGuards(guards, (guard) => {
                    let is = this.hasInterface(target, guard.signature.id);
                    if (!is) {
                        result = true;
                        return false;
                    }
                });
            }
            return result;
        }
        static anyImplement(targets, type) {
            let result = false;
            let guard = new type();
            _.each(targets, (target) => {
                let implemented = target != null && this.hasInterface(target, guard.signature.id);
                if (implemented) {
                    result = true;
                    return false;
                }
            });
            return result;
        }
        static allImplement(targets, type) {
            let result = targets.length > 0;
            let guard = new type();
            _.each(targets, (target) => {
                let implemented = target != null && this.hasInterface(target, guard.signature.id);
                if (!implemented) {
                    result = false;
                    return false;
                }
            });
            return result;
        }
        static register(registration) {
            if (registration.instance[InterfaceGuard.root] == null) {
                registration.instance[InterfaceGuard.root] = {};
            }
            if (registration.instance[InterfaceGuard.root][registration.guard.signature.id] == null) {
                registration.instance[InterfaceGuard.root][registration.guard.signature.id] = registration.guard;
            }
        }
        static implement(...guards) {
            return this.define((context) => {
                this.iterateGuards(guards, (guard) => {
                    InterfaceGuard.register({
                        instance: context,
                        guard: guard
                    });
                });
            });
        }
        static define(callback) {
            return function (constr) {
                return class extends constr {
                    constructor(...args) {
                        super(...args);
                        callback(this);
                    }
                };
            };
        }
        static iterateGuards(guards, callback) {
            _.each(guards, (guard) => {
                callback(new guard());
            });
        }
        static hasInterfaces(target) {
            return target[InterfaceGuard.root] != null;
        }
        static hasInterface(target, interfaceId) {
            return this.hasInterfaces(target) && target[InterfaceGuard.root][interfaceId] != null;
        }
    }
    Jade.InterfaceGuard = InterfaceGuard;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class Json {
        static tryParse(target) {
            let result = null;
            try {
                result = this.parse(target);
            }
            catch (_a) {
                result = null;
            }
            return result;
        }
        static parse(target) {
            return JSON.parse(target);
        }
        static stringify(target) {
            JSON.stringify(target);
        }
    }
    Jade.Json = Json;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    let KeyCode;
    (function (KeyCode) {
        KeyCode[KeyCode["Backspace"] = 8] = "Backspace";
        KeyCode[KeyCode["Tab"] = 9] = "Tab";
        KeyCode[KeyCode["Enter"] = 13] = "Enter";
        KeyCode[KeyCode["Shift"] = 16] = "Shift";
        KeyCode[KeyCode["Ctrl"] = 17] = "Ctrl";
        KeyCode[KeyCode["Alt"] = 18] = "Alt";
        KeyCode[KeyCode["Pause"] = 19] = "Pause";
        KeyCode[KeyCode["CapsLock"] = 20] = "CapsLock";
        KeyCode[KeyCode["Escape"] = 27] = "Escape";
        KeyCode[KeyCode["Space"] = 32] = "Space";
        KeyCode[KeyCode["End"] = 35] = "End";
        KeyCode[KeyCode["Home"] = 36] = "Home";
        KeyCode[KeyCode["ArrowLeft"] = 37] = "ArrowLeft";
        KeyCode[KeyCode["ArrowUp"] = 38] = "ArrowUp";
        KeyCode[KeyCode["ArrowRight"] = 39] = "ArrowRight";
        KeyCode[KeyCode["ArrowDown"] = 40] = "ArrowDown";
        KeyCode[KeyCode["Insert"] = 45] = "Insert";
        KeyCode[KeyCode["Delete"] = 46] = "Delete";
        KeyCode[KeyCode["Key0"] = 48] = "Key0";
        KeyCode[KeyCode["Key1"] = 49] = "Key1";
        KeyCode[KeyCode["Key2"] = 50] = "Key2";
        KeyCode[KeyCode["Key3"] = 51] = "Key3";
        KeyCode[KeyCode["Key4"] = 52] = "Key4";
        KeyCode[KeyCode["Key5"] = 53] = "Key5";
        KeyCode[KeyCode["Key6"] = 54] = "Key6";
        KeyCode[KeyCode["Key7"] = 55] = "Key7";
        KeyCode[KeyCode["Key8"] = 56] = "Key8";
        KeyCode[KeyCode["Key9"] = 57] = "Key9";
        KeyCode[KeyCode["KeyA"] = 65] = "KeyA";
        KeyCode[KeyCode["KeyB"] = 66] = "KeyB";
        KeyCode[KeyCode["KeyC"] = 67] = "KeyC";
        KeyCode[KeyCode["KeyD"] = 68] = "KeyD";
        KeyCode[KeyCode["KeyE"] = 69] = "KeyE";
        KeyCode[KeyCode["KeyF"] = 70] = "KeyF";
        KeyCode[KeyCode["KeyG"] = 71] = "KeyG";
        KeyCode[KeyCode["KeyH"] = 72] = "KeyH";
        KeyCode[KeyCode["KeyI"] = 73] = "KeyI";
        KeyCode[KeyCode["KeyJ"] = 74] = "KeyJ";
        KeyCode[KeyCode["KeyK"] = 75] = "KeyK";
        KeyCode[KeyCode["KeyL"] = 76] = "KeyL";
        KeyCode[KeyCode["KeyM"] = 77] = "KeyM";
        KeyCode[KeyCode["KeyN"] = 78] = "KeyN";
        KeyCode[KeyCode["KeyO"] = 79] = "KeyO";
        KeyCode[KeyCode["KeyP"] = 80] = "KeyP";
        KeyCode[KeyCode["KeyQ"] = 81] = "KeyQ";
        KeyCode[KeyCode["KeyR"] = 82] = "KeyR";
        KeyCode[KeyCode["KeyS"] = 83] = "KeyS";
        KeyCode[KeyCode["KeyT"] = 84] = "KeyT";
        KeyCode[KeyCode["KeyU"] = 85] = "KeyU";
        KeyCode[KeyCode["KeyV"] = 86] = "KeyV";
        KeyCode[KeyCode["KeyW"] = 87] = "KeyW";
        KeyCode[KeyCode["KeyX"] = 88] = "KeyX";
        KeyCode[KeyCode["KeyY"] = 89] = "KeyY";
        KeyCode[KeyCode["KeyZ"] = 90] = "KeyZ";
        KeyCode[KeyCode["Pad0"] = 96] = "Pad0";
        KeyCode[KeyCode["Pad1"] = 97] = "Pad1";
        KeyCode[KeyCode["Pad2"] = 98] = "Pad2";
        KeyCode[KeyCode["Pad3"] = 99] = "Pad3";
        KeyCode[KeyCode["Pad4"] = 100] = "Pad4";
        KeyCode[KeyCode["Pad5"] = 101] = "Pad5";
        KeyCode[KeyCode["Pad6"] = 102] = "Pad6";
        KeyCode[KeyCode["Pad7"] = 103] = "Pad7";
        KeyCode[KeyCode["Pad8"] = 104] = "Pad8";
        KeyCode[KeyCode["Pad9"] = 105] = "Pad9";
        KeyCode[KeyCode["PadMultiply"] = 106] = "PadMultiply";
        KeyCode[KeyCode["PadAdd"] = 107] = "PadAdd";
        KeyCode[KeyCode["PadSubtract"] = 109] = "PadSubtract";
        KeyCode[KeyCode["PadPoint"] = 110] = "PadPoint";
        KeyCode[KeyCode["PadDivide"] = 111] = "PadDivide";
        KeyCode[KeyCode["F01"] = 112] = "F01";
        KeyCode[KeyCode["F02"] = 113] = "F02";
        KeyCode[KeyCode["F03"] = 114] = "F03";
        KeyCode[KeyCode["F04"] = 115] = "F04";
        KeyCode[KeyCode["F05"] = 116] = "F05";
        KeyCode[KeyCode["F06"] = 117] = "F06";
        KeyCode[KeyCode["F07"] = 118] = "F07";
        KeyCode[KeyCode["F08"] = 119] = "F08";
        KeyCode[KeyCode["F09"] = 120] = "F09";
        KeyCode[KeyCode["F10"] = 121] = "F10";
        KeyCode[KeyCode["F11"] = 122] = "F11";
        KeyCode[KeyCode["F12"] = 123] = "F12";
        KeyCode[KeyCode["NumLock"] = 144] = "NumLock";
        KeyCode[KeyCode["ScrollLock"] = 145] = "ScrollLock";
        KeyCode[KeyCode["SemiColon"] = 186] = "SemiColon";
        KeyCode[KeyCode["EqualSign"] = 187] = "EqualSign";
        KeyCode[KeyCode["Comma"] = 188] = "Comma";
        KeyCode[KeyCode["Dash"] = 189] = "Dash";
        KeyCode[KeyCode["Period"] = 190] = "Period";
        KeyCode[KeyCode["ForwardSlash"] = 191] = "ForwardSlash";
        KeyCode[KeyCode["GraveAccent"] = 192] = "GraveAccent";
        KeyCode[KeyCode["OpenBracket"] = 219] = "OpenBracket";
        KeyCode[KeyCode["BackSlash"] = 220] = "BackSlash";
        KeyCode[KeyCode["CloseBracket"] = 221] = "CloseBracket";
        KeyCode[KeyCode["SingleQuote"] = 222] = "SingleQuote";
    })(KeyCode = Jade.KeyCode || (Jade.KeyCode = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class LocalStorage {
        static get(key) {
            return localStorage.getItem(key);
        }
        static getOf(key) {
            let value = this.get(key);
            let result = null;
            try {
                result = JSON.parse(value);
            }
            catch (_a) {
            }
            return result;
        }
        static set(key, value) {
            let storedValue = value;
            if (storedValue == null) {
                return;
            }
            localStorage.setItem(key, JSON.stringify(value));
        }
        static exists(key) {
            let result = false;
            for (let i = 0; i < localStorage.length; i++) {
                if (localStorage.key(i) === key) {
                    result = true;
                    break;
                }
            }
            return result;
        }
        static subscribe(eventName, fn) {
            this.ensureListener();
            this.m_events.add(eventName, fn);
        }
        static ensureListener() {
            if (this.m_eventListener != null) {
                return;
            }
            this.m_eventListener = (e) => {
                this.m_events.fire(e.key, e);
            };
            window.addEventListener("storage", this.m_eventListener);
        }
    }
    Jade.LocalStorage = LocalStorage;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class MappedCollection extends Jade.Collection {
        constructor(options) {
            super(options.data);
            this.m_map = {};
            this.m_key = null;
            this.m_key = options.key;
            _.each(this.innerList, (item) => {
                this.map[item[this.key]] = item;
            });
        }
        get map() {
            return this.m_map;
        }
        get key() {
            return this.m_key;
        }
        add(item) {
            if (this.contains(item)) {
                return;
            }
            this.innerList[this.innerList.length] = item;
            this.map[item[this.key]] = item;
            this.onChange();
            return true;
        }
        contains(item) {
            return this.map.hasOwnProperty(item[this.key]);
        }
        clear() {
            this.m_map = {};
            super.clear();
        }
        get(id) {
            return this.map[id];
        }
        insert(item, index) {
            var result = false;
            if (this.count >= index && index > -1) {
                this.innerList.splice(index, 0, item);
                this.m_map[item[this.key]] = item;
                result = true;
                this.onChange();
            }
            return result;
        }
        removeAt(index) {
            var result = null;
            if (this.count > index) {
                result = this.innerList.splice(index, 1)[0];
                delete this.m_map[result[this.key]];
                this.onChange();
            }
            else {
                throw "Index " + index + " exceeds the bounds of the array!";
            }
            return result;
        }
        reverseCopy() {
            return new Jade.MappedCollection({
                key: this.key,
                data: this.innerList.slice(0).reverse()
            });
        }
    }
    Jade.MappedCollection = MappedCollection;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class Path {
        static resolve(path, qs) {
            let vd = Jade.Application.instance.virtualDirectory || "";
            let result = null;
            if (path == null) {
                return;
            }
            result = path;
            if (this.isVirtual(path) && vd !== null) {
                result = vd + path.substr(1);
            }
            if (qs != null) {
                result += "?" + $.param(qs);
            }
            return result;
        }
        static resolveImage(name, imagePathId) {
            let result = "";
            let imagePath = Jade.Application.instance.imagePaths[imagePathId];
            if (imagePath != null) {
                result = Path.resolve(`${imagePath}/${name}`);
            }
            return result;
        }
        static addIconSet(path, imagePathId) {
            if (!Jade.Application.instance.imagePaths.hasOwnProperty(imagePathId)) {
                Jade.Application.instance.imagePaths[imagePathId] = Path.resolve(path);
            }
        }
        static getFileNameWithoutExtension(path) {
            return path.substr(0, path.lastIndexOf("."));
        }
        static getFileExtension(path) {
            var index = path.lastIndexOf(".");
            return path.substr(index, path.length - index);
        }
        static isVirtual(path) {
            return path.indexOf("~/") === 0;
        }
    }
    Jade.Path = Path;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class StateBag extends Backbone.DeepModel {
        constructor(options) {
            super(options);
            this.m_doNotSerialize = new Jade.Collection();
        }
        get doNotSerialize() {
            return this.m_doNotSerialize;
        }
        get(id, defaultValue = undefined) {
            let result = super.get(id);
            if (result == null && defaultValue !== undefined) {
                result = defaultValue;
            }
            return result;
        }
        add(id, value) {
            var setValue = {};
            setValue[id] = value;
            this.set(setValue);
        }
        extend(...items) {
            let result = this.toJSON();
            _.each(items, (item) => {
                result = _.extend(result, item);
            });
            this.set(result);
            this.toJSON();
            return result;
        }
        toJSON(options) {
            let clone = _.clone(this.attributes);
            let result = {};
            _.each(_.keys(clone), (key) => {
                if (!this.doNotSerialize.contains(key) && !Jade.String.startsWith(key, "$")) {
                    result[key] = clone[key];
                }
                else {
                    result[key] = null;
                }
            });
            result = JSON.stringify(result);
            result = JSON.parse(result);
            this.doNotSerialize.each((key) => {
                result[key] = this.get(key);
            });
            return result;
        }
    }
    Jade.StateBag = StateBag;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class Store {
        constructor() {
            this.m_dictionary = {};
        }
        set(item) {
            let uid = this.getUid(item);
            this.m_dictionary[uid] = item;
        }
        get(key) {
            let result = undefined;
            if (this.hasKey(key)) {
                result = this.m_dictionary[this.getUid(key)];
            }
            return result;
        }
        remove(key) {
            if (this.hasKey(key)) {
                delete this.m_dictionary[this.getUid(key)];
            }
        }
        hasKey(key) {
            let result = true;
            let uid = this.getUid(key);
            if (this.m_dictionary.hasOwnProperty(uid)) {
                result = true;
            }
            return result;
        }
        getUid(key) {
            if (key.hasOwnProperty("____objectID____")) {
                return key.__objectID__;
            }
            else {
                let uid = UUID.genV4().toString();
                Object.defineProperty(key, "____objectID____", {
                    "configurable": false,
                    "enumerable": false,
                    "get": (function (__objectID__) {
                        return function () { return __objectID__; };
                    })(uid),
                    "set": function () {
                        throw new Error("Property ____objectID____ is read-only.");
                    }
                });
                return key.____objectID____;
            }
        }
    }
    Jade.Store = Store;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class String {
        static template(value) {
            return value.join("");
        }
        static format(text, ...params) {
            var result = text;
            _.each(params, (value, index) => {
                result = result.replace(new RegExp("\\{" + index + "\\}", "gm"), value);
            });
            return result;
        }
        static isNullOrWhiteSpace(value) {
            return value == null || (_.isString(value) && value.match(/^\s*$/) !== null);
        }
        static startsWith(value, searchText, caseInsensitive = true) {
            let result = false;
            if (caseInsensitive) {
                result = value.toLowerCase().indexOf(searchText.toLowerCase()) === 0;
            }
            else {
                result = value.indexOf(searchText) === 0;
            }
            return result;
        }
        static toTitleCase(text, options) {
            let result = text || "";
            options = options || {
                lowers: [],
                uppers: []
            };
            result = result.replace(/([^\W_]+[^\s-]*) */g, (value) => {
                return value.charAt(0).toUpperCase() + value.substr(1).toLowerCase();
            });
            options.lowers.forEach(lower => {
                result = result.replace(new RegExp(`\\s${lower}\\s`, 'g'), match => {
                    return match.toLowerCase();
                });
            });
            options.uppers.forEach(upper => {
                result = result.replace(new RegExp(`\\b${upper}\\b`, 'g'), match => {
                    return match.toUpperCase();
                });
            });
            return result;
        }
    }
    Jade.String = String;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class Type {
        static getType(name) {
            if (name == null) {
                return null;
            }
            let pieces = name.split(".");
            let source = window;
            _.each(pieces, (piece) => {
                source = source[piece];
            });
            return source ? source : null;
        }
    }
    Jade.Type = Type;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class ObservableCollection extends Jade.Collection {
        constructor(data = null, callbacks = {}) {
            super(data);
            this.m_callbacks = {};
            this.m_callbacks = callbacks;
        }
        add(item) {
            var result = false;
            this.executeChange("Add", item, this.count - 1, () => {
                result = super.add(item);
            });
            return result;
        }
        insert(item, index) {
            var result = false;
            if (this.count < index || index < 0) {
                return result;
            }
            this.executeChange("Insert", item, index, () => {
                result = super.insert(item, index);
            });
            return result;
        }
        removeAt(index) {
            var result = null;
            if (this.count < index || index < 0) {
                return result;
            }
            this.executeChange("Remove", this.item(index), index, () => {
                result = super.removeAt(index);
            });
            return result;
        }
        clear() {
            _.forEachRight(this.toArray(), (item, index) => {
                this.removeAt(index);
            });
        }
        executeChange(event, item, index, operation) {
            let argsBefore = null;
            let argsAfter = null;
            argsBefore = new Jade.ObservableCollectionBeforeChangeEventArgs("onBeforeChange", this.item(index), index);
            this.trigger(argsBefore);
            if (argsBefore.canceled) {
                return;
            }
            argsBefore = new Jade.ObservableCollectionBeforeChangeEventArgs(`onBefore${event}`, this.item(index), index);
            this.trigger(argsBefore);
            if (argsBefore.canceled) {
                return;
            }
            if (_.isFunction(operation)) {
                operation();
            }
            argsAfter = new Jade.ObservableCollectionChangeEventArgs(`onAfter${event}`, item, index);
            this.trigger(argsAfter);
            argsAfter = new Jade.ObservableCollectionChangeEventArgs("onAfterChange", item, index);
            this.trigger(argsAfter);
        }
        trigger(args) {
            var fn = this.m_callbacks[args.type];
            if (_.isFunction(fn)) {
                fn(args);
            }
        }
    }
    Jade.ObservableCollection = ObservableCollection;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class ObservableCollectionChangeEventArgs {
        constructor(type, item, index) {
            this.m_type = null;
            this.m_item = null;
            this.m_index = null;
            this.m_type = type;
            this.m_item = item;
            this.m_index = index;
        }
        get type() {
            return this.m_type;
        }
        get item() {
            return this.m_item;
        }
        get index() {
            return this.m_index;
        }
    }
    Jade.ObservableCollectionChangeEventArgs = ObservableCollectionChangeEventArgs;
    class ObservableCollectionBeforeChangeEventArgs extends ObservableCollectionChangeEventArgs {
        constructor(type, item, index) {
            super(type, item, index);
            this.m_canceled = false;
        }
        get canceled() {
            return this.m_canceled;
        }
        cancel() {
            this.m_canceled = true;
        }
    }
    Jade.ObservableCollectionBeforeChangeEventArgs = ObservableCollectionBeforeChangeEventArgs;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class ObservableMappedCollection extends Jade.MappedCollection {
        constructor(options) {
            super({ key: options.key, data: options.data });
            this.m_callbacks = {};
            this.m_callbacks = options.callbacks || {};
        }
        add(item) {
            var result = false;
            this.executeChange("Add", item, this.count - 1, () => {
                result = super.add(item);
            });
            return result;
        }
        insert(item, index) {
            var result = false;
            if (this.count < index || index < 0) {
                return result;
            }
            this.executeChange("Insert", item, index, () => {
                result = super.insert(item, index);
            });
            return result;
        }
        removeAt(index) {
            var result = null;
            if (this.count < index || index < 0) {
                return result;
            }
            this.executeChange("Remove", this.item(index), index, () => {
                result = super.removeAt(index);
            });
            return result;
        }
        clear() {
            this.reverseCopy().each((item, index) => {
                let targetIndex = this.indexOf(item);
                this.executeChange("Remove", item, targetIndex, () => {
                    super.removeAt(targetIndex);
                });
            });
        }
        executeChange(event, item, index, operation) {
            let argsBefore = null;
            let argsAfter = null;
            argsBefore = new Jade.ObservableCollectionBeforeChangeEventArgs("onBeforeChange", this.item(index), index);
            this.trigger(argsBefore);
            if (argsBefore.canceled) {
                return;
            }
            argsBefore = new Jade.ObservableCollectionBeforeChangeEventArgs(`onBefore${event}`, this.item(index), index);
            this.trigger(argsBefore);
            if (argsBefore.canceled) {
                return;
            }
            if (_.isFunction(operation)) {
                operation();
            }
            argsAfter = new Jade.ObservableCollectionChangeEventArgs(`onAfter${event}`, item, index);
            this.trigger(argsAfter);
            argsAfter = new Jade.ObservableCollectionChangeEventArgs("onAfterChange", item, index);
            this.trigger(argsAfter);
        }
        trigger(args) {
            var fn = this.m_callbacks[args.type];
            if (_.isFunction(fn)) {
                fn(args);
            }
        }
    }
    Jade.ObservableMappedCollection = ObservableMappedCollection;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class BehaviorExecutionArgs {
        constructor(options) {
            this.m_options = new Jade.StateBag(options);
        }
        get options() {
            return this.m_options;
        }
        isWellFormed() {
            return false;
        }
    }
    Jade.BehaviorExecutionArgs = BehaviorExecutionArgs;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class Behavior {
        constructor(options = {}) {
            this.m_options = new Jade.StateBag(options);
        }
        get options() {
            return this.m_options;
        }
        onExecute(e) {
        }
        execute(e) {
            let args = this.getExecutionArguments(e);
            if (args.isWellFormed() && this.meetLoadConditions(args)) {
                this.onExecute(args);
            }
        }
        meetLoadConditions(e) {
            return true;
        }
        getExecutionArguments(e) {
            return null;
        }
    }
    Jade.Behavior = Behavior;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class BehaviorModule {
        constructor(options = {}) {
            this.m_behaviors = null;
            this.m_behaviors = new Jade.Collection();
            this.onSetup();
            this.onRegisterBehaviors();
        }
        get type() {
            return null;
        }
        get behaviors() {
            return this.m_behaviors;
        }
        onRegisterBehaviors() {
        }
        onSetup() {
        }
    }
    Jade.BehaviorModule = BehaviorModule;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class BehaviorModuleCollection extends Jade.Collection {
        getByModuleType(type) {
            let result = new BehaviorModuleCollection();
            this.each((behaviorModule) => {
                if (behaviorModule.type === type) {
                    result.add(behaviorModule);
                }
            });
            return result;
        }
    }
    Jade.BehaviorModuleCollection = BehaviorModuleCollection;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class AjaxBehaviorExecutionArgs extends Jade.BehaviorExecutionArgs {
        get xhr() {
            return this.options.get("xhr");
        }
        get settings() {
            return this.options.get("request.behavior");
        }
        get event() {
            return this.options.get("event");
        }
        isWellFormed() {
            return this.xhr != null && this.event != null;
        }
        getSetting(fqn, defaultValue = null) {
            return this.options.get(Jade.String.format("request.behavior.settings.{0}", fqn), defaultValue);
        }
    }
    Jade.AjaxBehaviorExecutionArgs = AjaxBehaviorExecutionArgs;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class AjaxBehavior extends Jade.Behavior {
        onExecute(e) {
            switch (e.event) {
                case "send":
                    this.onAjaxSend(e);
                    break;
                case "success":
                    this.onAjaxSuccess(e);
                    break;
                case "error":
                    this.onAjaxError(e);
                    break;
                case "complete":
                    this.onAjaxComplete(e);
                    break;
            }
        }
        onAjaxSend(e) {
        }
        onAjaxSuccess(e) {
        }
        onAjaxError(e) {
        }
        onAjaxComplete(e) {
        }
        getExecutionArguments(e) {
            return new Jade.AjaxBehaviorExecutionArgs(e);
        }
        meetLoadConditions(e) {
            return true;
        }
    }
    Jade.AjaxBehavior = AjaxBehavior;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class AjaxBehaviorForException extends Jade.AjaxBehavior {
        onAjaxError(e) {
            toastr.error("An unexpected error has occured.<br/><br/>If the issue persists contact your system administrator.");
        }
        meetsLoadConditions(e) {
            return true;
        }
    }
    Jade.AjaxBehaviorForException = AjaxBehaviorForException;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class AjaxBehaviorForRuleViolation extends Jade.AjaxBehavior {
        onAjaxError(e) {
            setTimeout(() => {
            }, 1000);
        }
        meetsExecuteConditions(e) {
            return e.xhr.status == 400 && e.xhr.getResponseHeader("Violation-Type") === "Rule";
        }
    }
    Jade.AjaxBehaviorForRuleViolation = AjaxBehaviorForRuleViolation;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class AjaxBehaviorForValidation extends Jade.AjaxBehavior {
        onAjaxComplete(e) {
            let container = e.getSetting("ui.container");
            container.prop("disabled", true);
        }
        onAjaxError(e) {
            if (this.meetsErrorConditions(e)) {
                this.addError(e);
            }
        }
        onAjaxSend(e) {
            let container = e.getSetting("ui.container");
            this.clearErrors(e);
            _.delay(() => {
                container.prop("disabled", true);
            }, 250);
        }
        meetsExecuteConditions(e) {
            return e.getSetting("ui.container") != null;
        }
        meetsErrorConditions(e) {
            return e.xhr.status == 400 && e.xhr.getResponseHeader("Violation-Type") === "ModelState";
        }
        clearErrors(e) {
            let container = e.getSetting("ui.container");
            container
                .find(AjaxBehaviorForValidation.CSS_SELECTOR)
                .each((idx, element) => {
                let $element = $(element);
                $element.removeClass(AjaxBehaviorForValidation.CSS_CLASS);
                Tipped.remove($element);
            });
        }
        addError(e) {
            let errors = null;
            let tooltipList = null;
            let summaryList = null;
            let json = e.xhr.responseJSON;
            if (!_.isPlainObject(json)) {
                return;
            }
            errors = new Jade.Collection(json);
            tooltipList = new Jade.Collection();
            summaryList = new Jade.Collection();
            errors.each((item) => {
                if (item.key === 0) {
                    summaryList.add(item);
                }
                else {
                    tooltipList.add(item);
                }
            });
            this.showToolTip(e, tooltipList);
            this.showSummary(e, summaryList);
        }
        showToolTip(e, list) {
            let container = e.getSetting("ui.container");
            list.each((index, item) => {
                let element = container
                    .find("LABEL[data-validation-for=" + item.key + "]")
                    .addClass(AjaxBehaviorForValidation.CSS_CLASS);
                Tipped.create(element, item.message, {
                    skin: "white",
                    border: {
                        color: '#660000',
                        size: 1,
                        opacity: 1
                    },
                    fontSize: "12px",
                    hook: {
                        target: 'rightmiddle',
                        tooltip: 'lefttop'
                    },
                    maxWidth: 300
                });
            });
        }
        showSummary(e, list) {
            let message = "";
            if (list.count === 0) {
                return;
            }
            list.each((item) => {
                message += item.message;
            });
        }
    }
    AjaxBehaviorForValidation.CSS_CLASS = "-jadejs-validation-failure-label";
    AjaxBehaviorForValidation.CSS_SELECTOR = Jade.String.format(".{0}", AjaxBehaviorForValidation.CSS_CLASS);
    Jade.AjaxBehaviorForValidation = AjaxBehaviorForValidation;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class AjaxBehaviorModule extends Jade.BehaviorModule {
        onSetup() {
            Jade.Ajax.onBeforeSend((e) => {
                this.execute(e);
            });
            Jade.Ajax.onComplete((e) => {
                this.execute(e);
            });
            Jade.Ajax.onError((e) => {
                this.execute(e);
            });
            Jade.Ajax.onSuccess((e) => {
                this.execute(e);
            });
        }
        onRegisterBehavior() {
            this.behaviors.add(new Jade.AjaxBehaviorForException());
            this.behaviors.add(new Jade.AjaxBehaviorForRuleViolation());
            this.behaviors.add(new Jade.AjaxBehaviorForValidation());
        }
        execute(e) {
            this.behaviors.each((behavior) => {
                behavior.execute(e);
            });
        }
    }
    Jade.AjaxBehaviorModule = AjaxBehaviorModule;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class Command {
        constructor(props) {
            this.m_props = new Jade.StateBag();
            this.m_state = new Jade.StateBag();
            this.m_uid = null;
            this.m_uid = UUID.genV4().toString();
            this.m_state = new Jade.StateBag();
            this.setDefaultValuesForProps(props);
            this.onInit();
        }
        get UID() {
            return this.m_uid;
        }
        get ID() {
            return this.props.get("id");
        }
        get state() {
            return this.m_state;
        }
        get props() {
            return this.m_props;
        }
        get label() {
            return this.props.get("label");
        }
        set label(value) {
            this.props.set("label", value);
        }
        get enabled() {
            return this.props.get("enabled");
        }
        set enabled(value) {
            this.props.set("enabled", value);
        }
        get visible() {
            return this.props.get("visible");
        }
        set visible(value) {
            this.props.set("visible", value);
        }
        get icon() {
            return this.props.get("icon");
        }
        set icon(value) {
            this.props.set("icon", value);
        }
        get tooltip() {
            return this.props.get("tooltip", this.label);
        }
        set tooltip(value) {
            this.props.set("tooltip", value);
        }
        get display() {
            return this.props.get("display", "icon label");
        }
        set display(value) {
            this.props.set("display", value);
        }
        get iconSet() {
            this.ensureIconSet(this.props.get("iconSetId"));
            return this.m_iconSet;
        }
        onInit() {
        }
        onStateChanged(state) {
        }
        onExecute(e) {
        }
        onExecuteSuccess() {
        }
        onExecuteError() {
        }
        onExecuteComplete() {
        }
        execute(e) {
            this.mergeCallbacks(e);
            this.onExecute(e);
        }
        bind(callback) {
            if (!_.isFunction(callback)) {
                return;
            }
            callback(this.props.toJSON());
            this.props.on("change", (e) => {
                callback(this.props.toJSON());
            });
        }
        setState(state, options = {}) {
            let src = state;
            let dst = this.state.toJSON();
            if (state == null) {
                return;
            }
            for (let key in dst) {
                if (key in src) {
                    if (_.isArray(src[key])) {
                        this.state.set(key, null);
                    }
                    this.state.set(key, src[key]);
                }
                else if (options.overwrite) {
                    this.state.set(key, null);
                }
            }
            for (let key in src) {
                if (!(key in dst) && this.state.doNotSerialize.contains(key)) {
                    dst[key] = src[key];
                }
            }
            if (Jade.Instance.isEmptyObject(state) || this.state.hasChanged() || options.force) {
                this.onStateChanged(state);
            }
        }
        getIcon(size, icon) {
            let result;
            if (this.iconSet != null) {
                result = this.iconSet.resolve(icon || this.icon, size);
            }
            else {
                result = icon || this.icon;
            }
            return result;
        }
        getDefaultValuesForProps() {
            return {};
        }
        setDefaultValuesForProps(props) {
            this.props.set(props);
            this.props.set(_.extend({
                id: null,
                enabled: false,
                icon: null,
                label: null,
                tooltip: null,
                visible: true
            }, this.getDefaultValuesForProps(), props || {}));
        }
        mergeCallbacks(args) {
            this.mergeCallback("onSuccess", args);
            this.mergeCallback("onError", args);
            this.mergeCallback("onComplete", args);
        }
        mergeCallback(callbackName, args = {}) {
            var eventHandler = this[callbackName];
            if (args != null && _.isFunction(args[callbackName])) {
                this[callbackName] = (e) => {
                    eventHandler(e);
                    args[callbackName](e);
                };
            }
        }
        ensureIconSet(iconSetId) {
            if (this.m_iconSet == null) {
                this.m_iconSet = Jade.IconSet.get(iconSetId);
            }
        }
    }
    Jade.Command = Command;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class CommandCollection {
        constructor(options = {}) {
            this.m_collection = {};
        }
        add(command) {
            if (this.commandIsValid(command)
                && !this.commandIsRegistered(command)) {
                this.m_collection[command.ID] = command;
            }
        }
        remove(commandId) {
            delete this.m_collection[commandId];
        }
        each(callback) {
            for (var key in this.m_collection) {
                if (callback != null) {
                    callback(key, this.m_collection[key]);
                }
            }
        }
        getByPath(commandPath) {
            var result = null, info = new Jade.CommandPathInfo(commandPath);
            if (info.commandId != null) {
                result = this.m_collection[info.commandId];
            }
            return result;
        }
        getById(commandId) {
            return this.m_collection[commandId];
        }
        commandIsValid(command) {
            return command.ID != null
                && command.setState != null
                && command.execute != null;
        }
        commandIsRegistered(command) {
            if (this.commandIsValid(command)) {
                return (command.ID in this.m_collection);
            }
            return false;
        }
    }
    Jade.CommandCollection = CommandCollection;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class CommandContext {
        constructor(options) {
            this.m_id = null;
            this.m_groups = new Jade.CommandGroupCollection();
            this.m_id = options.contextId;
        }
        get ID() {
            return this.m_id;
        }
        get groups() {
            return this.m_groups;
        }
        setState(state, options = {}) {
            let group = null;
            let key = null;
            let keyCount = 0;
            for (key in state) {
                group = this.groups.getById(key);
                if (group == null) {
                    group = this.ensureGroup(key);
                }
                if (group != null) {
                    group.setState(state[key], options);
                }
                keyCount += 1;
            }
            if (keyCount === 0) {
                this.groups.each((groupId) => {
                    group = this.groups.getById(groupId);
                    if (group == null) {
                        group = this.ensureGroup(groupId);
                    }
                    if (group != null) {
                        group.setState({}, options);
                    }
                });
            }
        }
        ensureGroup(groupId) {
            var result = null;
            if (!this.groups.groupIsDefined(groupId)) {
                result = Jade.CommandGroups.create(groupId);
            }
            else {
                result = this.groups.getById(groupId);
            }
            if (result != null) {
                this.groups.add(result);
            }
            return result;
        }
        resolve(commandPath) {
            let info = new Jade.CommandPathInfo(commandPath);
            let group = this.ensureGroup(info.groupId);
            let command = null;
            if (group) {
                command = group.commands.getById(info.commandId);
            }
            return {
                context: this,
                group: group,
                command: command,
                path: commandPath
            };
        }
        execute(commandPath, args) {
            args = args == null ? {} : args;
            var resolved = this.resolve(commandPath);
            if (resolved.group != null) {
                resolved.group.execute(commandPath, args);
            }
        }
        clear() {
            this.groups.clear();
        }
    }
    Jade.CommandContext = CommandContext;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class CommandExecutor {
        execute(command, args = {}) {
            command.execute(args);
            console.log(command.props.toJSON());
        }
    }
    Jade.CommandExecutor = CommandExecutor;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class CommandGroup {
        constructor(id) {
            this.m_id = null;
            this.m_label = null;
            this.m_visible = true;
            this.m_enabled = true;
            this.m_groupConditionCheck = false;
            this.m_commands = new Jade.CommandCollection();
            this.m_executor = null;
            this.m_id = id;
            this.registerCommands(new Jade.OnRegisterCommandsEventArgs({
                commands: this.commands
            }));
        }
        get ID() {
            return this.m_id;
        }
        get label() {
            return this.m_label;
        }
        get commands() {
            return this.m_commands;
        }
        get executor() {
            this.ensureCommandExecutor();
            return this.m_executor;
        }
        set executor(value) {
            this.m_executor = value;
        }
        setState(state, options = {}) {
            if (state != null) {
                this.onStateChange(state, options);
                this.commands.each((key, command) => {
                    command.setState(state, options);
                });
            }
        }
        execute(commandPath, args) {
            var command = this.commands.getByPath(commandPath);
            if (command != null) {
                this.executor.execute(command, args);
            }
        }
        onStateChange(state, options = {}) {
        }
        registerCommands(e) {
        }
        getCommandExecutor() {
            return new Jade.CommandExecutor();
        }
        ensureCommandExecutor() {
            if (this.m_executor == null) {
                this.m_executor = this.getCommandExecutor();
            }
        }
    }
    Jade.CommandGroup = CommandGroup;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class CommandGroupCollection {
        constructor() {
            this.m_collection = {};
        }
        each(callback) {
            if (!_.isFunction(callback)) {
                return;
            }
            for (var key in this.m_collection) {
                callback(key, this.m_collection[key]);
            }
        }
        add(group) {
            if (this.groupIsValid(group)
                && !this.groupIsDefined(group.ID)) {
                this.m_collection[group.ID] = group;
            }
        }
        remove(id) {
            if (this.groupIsDefined(id)) {
                delete this.m_collection[id];
            }
        }
        groupIsValid(group) {
            return group.ID != null;
        }
        groupIsDefined(id) {
            return this.m_collection[id] != null;
        }
        getByPath(commandPath) {
            let result = null;
            let info = new Jade.CommandPathInfo(commandPath);
            if (info.groupId != null) {
                result = this.m_collection[info.groupId];
            }
            return result;
        }
        getById(groupId) {
            return this.m_collection[groupId];
        }
        clear() {
            this.m_collection = {};
        }
    }
    Jade.CommandGroupCollection = CommandGroupCollection;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class CommandGroups {
        static get registrations() {
            return this.m_resgistrations;
        }
        static get instances() {
            return this.m_instances;
        }
        static add(commandGroup) {
            let instance = new commandGroup();
            if (instance != null) {
                this.registrations[instance.ID] = commandGroup;
                this.instances[instance.ID] = instance;
            }
        }
        static remove(id) {
            if (this.isGroupRegistered(id)) {
                delete this.registrations[id];
            }
        }
        static create(groupId) {
            let result = null;
            if (this.isGroupRegistered(groupId)) {
                result = new this.registrations[groupId](groupId);
            }
            return result;
        }
        static get(groupId) {
            let result = null;
            if (this.isGroupRegistered(groupId)) {
                result = new this.instances[groupId](groupId);
            }
            return result;
        }
        static isGroupRegistered(groupId) {
            return groupId != null && groupId in this.registrations;
        }
    }
    CommandGroups.m_resgistrations = {};
    CommandGroups.m_instances = {};
    Jade.CommandGroups = CommandGroups;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class ICommandInfo {
    }
    Jade.ICommandInfo = ICommandInfo;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class CommandPathInfo {
        constructor(path) {
            this.m_contextId = null;
            this.m_groupId = null;
            this.m_commandId = null;
            this.m_path = null;
            this.parse(path);
        }
        get contextId() {
            return this.m_contextId;
        }
        get groupId() {
            return this.m_groupId;
        }
        get commandId() {
            return this.m_commandId;
        }
        get path() {
            return this.m_path;
        }
        parse(path) {
            let pieces = path.toString().split(":");
            switch (pieces.length) {
                case 1:
                    this.m_commandId = pieces[0];
                    break;
                case 2:
                    this.m_groupId = pieces[0];
                    this.m_commandId = pieces[1];
                    break;
                case 3:
                    this.m_contextId = pieces[0];
                    this.m_groupId = pieces[1];
                    this.m_commandId = pieces[2];
                    break;
            }
        }
    }
    Jade.CommandPathInfo = CommandPathInfo;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class CommandSubscriber {
        constructor() {
            this.m_commandId = null;
            this.m_callback = null;
            this.m_subscription = null;
        }
        get label() {
            return this.getValue("label", "Label");
        }
        get icon() {
            return this.getValue("icon", null);
        }
        get enabled() {
            return this.getValue("enabled", true);
        }
        get tooltip() {
            return this.getValue("tooltip", "");
        }
        get visible() {
            return this.getValue("visible", true);
        }
        get display() {
            return this.command != null ? this.command.display : "label";
        }
        get command() {
            return this.info != null ? this.info.command : null;
        }
        get info() {
            this.ensureSubscription();
            return this.m_subscription;
        }
        execute(args) {
            this.command.execute(args);
        }
        subscribe(commandId, callback) {
            this.m_commandId = commandId;
            this.m_callback = callback;
            if (this.command) {
                this.command.props.on("change", () => {
                    this.m_callback();
                });
            }
        }
        ensureSubscription() {
            if (this.m_subscription == null && this.m_commandId != null) {
                this.m_subscription = Jade.Application.instance.contexts.current.commands.resolve(this.m_commandId);
            }
        }
        getValue(id, defaultValue) {
            let result = null;
            if (this.command != null) {
                result = this.command.props.get(id, defaultValue);
            }
            else {
                result = defaultValue;
            }
            return result;
        }
    }
    Jade.CommandSubscriber = CommandSubscriber;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class OnRegisterCommandsEventArgs {
        constructor(options) {
            this.m_commands = options.commands;
        }
        get commands() {
            return this.m_commands;
        }
    }
    Jade.OnRegisterCommandsEventArgs = OnRegisterCommandsEventArgs;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class Context {
        constructor(options) {
            this.m_node = options.contextNode;
            delete options.contextNode;
            this.m_options = new Jade.StateBag(_.extend({
                id: UUID.genV4(),
                name: "",
                parent: null,
                tags: []
            }, options));
            this.m_commands = new Jade.CommandContext({
                contextId: this.ID
            });
            this.m_events = new Jade.ContextEventBus();
            this.m_store = new Jade.StateBag();
            this.m_hotkeys = new window.keypress.Listener($("BODY").get(0));
            this.m_depth = this.parent == null ? 0 : this.parent.depth + 1;
            this.m_tags = [];
        }
        get ID() {
            return this.options.get("id");
        }
        get name() {
            return this.options.get("name");
        }
        get options() {
            return this.m_options;
        }
        get parent() {
            return this.options.get("parent");
        }
        get commands() {
            return this.m_commands;
        }
        get events() {
            return this.m_events;
        }
        get tags() {
            return this.m_tags;
        }
        get hotkeys() {
            return this.m_hotkeys;
        }
        get store() {
            return this.m_store;
        }
        get depth() {
            return this.m_depth;
        }
        get node() {
            return this.m_node;
        }
        get isDialogContext() {
            return this.options.get("isDialogContext", false);
        }
        onCurrentChanged(current) {
            if (current) {
                this.hotkeys.listen();
            }
            else {
                this.hotkeys.stop_listening();
            }
        }
        destroy() {
            this.hotkeys.destroy();
            this.options.clear();
            this.store.clear();
            this.events.clear();
            this.commands.clear();
        }
        findClosestContext(tags, matchAny = false) {
            var result = null, target = this;
            matchAny = matchAny == null ? false : true;
            while (target != null) {
                if (target.isTaggedWith(tags, matchAny)) {
                    result = target;
                    break;
                }
                target = target.parent;
            }
            return result;
        }
        isCurrent(value) {
            this.onCurrentChanged(value);
            this.events.publish(Context.CONTEXT_FOCUS_EVENT, { isCurrent: value });
        }
        isTaggedWith(tags, matchAny = false) {
            var result = false, unmatched = _.difference(tags, this.tags);
            result = (matchAny === false && unmatched.length === 0)
                || (matchAny === true && unmatched.length < tags.length);
            return result;
        }
    }
    Context.CONTEXT_FOCUS_EVENT = "CONTEXT_FOCUS_EVENT";
    Jade.Context = Context;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class ContextCollection {
        constructor(options) {
            this.m_collection = {};
            this.m_childContextMaps = {};
            this.m_options = new Jade.StateBag(_.extend({
                add: function () { },
                remove: function () { }
            }));
        }
        get options() {
            return this.m_options;
        }
        add(context) {
            var addFn = this.options.get("add");
            if (!this.exists(context)) {
                this.m_collection[context.ID] = context;
                this.createChildContextMap(context);
                addFn({
                    contextId: context.ID
                });
            }
        }
        remove(context, destroyChildContexts = true) {
            var targetContextId = this.getContextId(context), targetContext = this.getById(targetContextId), removeFn = this.options.get("remove");
            if (targetContext != null) {
                delete this.m_collection[targetContextId];
                if (destroyChildContexts !== false) {
                    this.destroyChildContexts(targetContext);
                }
                removeFn({
                    contextId: targetContextId
                });
            }
        }
        each(fn) {
            fn = fn || function () { };
            _.each(this.m_collection, function (value, key, list) {
                fn(key, value);
            });
        }
        exists(context) {
            var contextId = this.getContextId(context);
            return this.m_collection[contextId] != null;
        }
        getById(contextId) {
            var result = null;
            contextId = this.getContextId(contextId);
            if (this.exists(contextId)) {
                result = this.m_collection[contextId];
            }
            return result;
        }
        getContextId(context) {
            var result = null;
            if (context != null) {
                if (_.isString(context)) {
                    result = context.toLowerCase();
                }
                else {
                    result = context.ID;
                }
            }
            return result;
        }
        createChildContextMap(context) {
            var mapArray = null, focusedContext = context, focusedContextId = null;
            do {
                focusedContext = focusedContext.parent;
                if (focusedContext != null) {
                    focusedContextId = focusedContext.ID;
                    if (this.m_childContextMaps[focusedContextId] == null) {
                        this.m_childContextMaps[focusedContextId] = [];
                    }
                    mapArray = this.m_childContextMaps[focusedContextId];
                    mapArray[mapArray.length] = context.ID;
                }
            } while (focusedContext != null);
        }
        destroyChildContexts(context) {
            var focusedContext = context, focusedContextId = context.ID, mapArray = this.m_childContextMaps[focusedContextId] || [], oldArray = null, newArray = null;
            if (mapArray != null) {
                mapArray.unshift(focusedContextId);
                _.each(mapArray, (contextId) => {
                    this.remove(contextId, false);
                    delete this.m_childContextMaps[contextId];
                });
            }
            do {
                focusedContext = focusedContext.parent;
                if (focusedContext != null) {
                    oldArray = this.m_childContextMaps[focusedContext.ID];
                    this.m_childContextMaps[focusedContext.ID] = _.difference(oldArray, mapArray);
                }
            } while (focusedContext != null);
        }
    }
    Jade.ContextCollection = ContextCollection;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class EventBus {
        constructor(options) {
            this.m_events = new Jade.EventBusEvents();
            this.m_id = UUID.genV4().toString();
            this.m_label = options ? options.label : this.id;
        }
        get id() {
            return this.m_id;
        }
        get label() {
            return this.m_label;
        }
        get events() {
            return this.m_events;
        }
        ;
        subscribe(eventType, callback) {
            return this.events.subscribe(eventType, callback);
        }
        publish(eventType, data) {
            this.events.publish(eventType, data);
        }
        clear() {
            this.m_events = new Jade.EventBusEvents();
        }
    }
    Jade.EventBus = EventBus;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class ContextEventBus extends Jade.EventBus {
    }
    Jade.ContextEventBus = ContextEventBus;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class ContextManager {
        constructor() {
            this.GLOBAL_CONTEXT_ID = "GLOBAL";
            this.m_globalContext = null;
            this.m_currentContext = null;
            this.m_contexts = null;
            this.m_contexts = new Jade.ContextCollection({
                remove: function (e) {
                }
            });
            this.m_globalContext = this.createContext({
                id: this.GLOBAL_CONTEXT_ID
            });
        }
        get contexts() {
            return this.m_contexts;
        }
        get current() {
            return this.m_currentContext != null ? this.m_currentContext : this.m_globalContext;
        }
        get global() {
            return this.m_globalContext;
        }
        setCurrent(contextId) {
            var newContext = this.contexts.getById(contextId);
            var oldContext = this.current;
            var hasContextChanged = oldContext != newContext;
            if (oldContext != null) {
                this.m_currentContext = null;
                oldContext.isCurrent(false);
            }
            if (newContext != null) {
                this.m_currentContext = newContext;
                newContext.isCurrent(true);
            }
            if (hasContextChanged) {
                _.each(ContextManager.m_onContextChangeCallbacks, (callback) => {
                    callback({
                        oldContext: oldContext,
                        newContext: newContext,
                        oldContextId: oldContext != null ? oldContext.ID : null,
                        newContextId: newContext != null ? newContext.ID : null,
                    });
                });
            }
        }
        createContext(createOptions) {
            var options = _.extend({
                id: UUID.genV4(),
                name: "",
                parent: this.current,
                makeDefault: true
            }, createOptions);
            var context = new Jade.Context(options);
            this.contexts.add(context);
            if (options.makeDefault) {
                this.setCurrent(context.ID);
            }
            return context;
        }
        destroyContext(options) {
            var context = this.getContextById(options.id);
            if (options.id === this.GLOBAL_CONTEXT_ID) {
                return;
            }
            if (context != null) {
                let isDefault = this.isCurrent(context);
                this.contexts.remove(context);
                if (isDefault && context.parent != null) {
                    this.setCurrent(context.parent.ID);
                }
            }
        }
        revolveContext(args) {
            var originalContext = this.current;
            var targetedContext = args.context;
            var hasContext = targetedContext != null && targetedContext instanceof Jade.Context;
            var hasFunction = _.isFunction(args.fn);
            var hasTags = _.isArray(args.tags);
            if (!hasContext && hasTags) {
                targetedContext = this.findClosestContext(args.tags);
            }
            if (targetedContext == null) {
                return;
            }
            this.m_currentContext = targetedContext;
            if (hasFunction) {
                args.fn();
            }
            this.m_currentContext = originalContext;
        }
        getContextById(contextId) {
            return this.contexts.getById(contextId);
        }
        findClosestContext(tagsArr) {
            return this.current.findClosestContext(tagsArr);
        }
        isCurrent(context) {
            return context != null && this.current.ID === context.ID;
        }
        static onContextChange(callback) {
            ContextManager.m_onContextChangeCallbacks[ContextManager.m_onContextChangeCallbacks.length] = callback;
        }
        static setTimeout(callback, timeout) {
            let previousContext = Jade.Application.instance.contexts.current;
            setTimeout(() => {
                let currentContext = Jade.Application.instance.contexts.current;
                if (Jade.Application.instance.contexts.contexts.exists(previousContext)) {
                    Jade.Application.instance.contexts.setCurrent(previousContext.ID);
                }
                ;
                callback();
                if (Jade.Application.instance.contexts.contexts.exists(currentContext)) {
                    Jade.Application.instance.contexts.setCurrent(currentContext.ID);
                }
                ;
            }, timeout);
        }
    }
    ContextManager.m_onContextChangeCallbacks = [];
    Jade.ContextManager = ContextManager;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class EventBusCollection {
        constructor() {
            this.m_collection = {};
        }
        add(id) {
            if (!(id in this.m_collection)) {
                this.m_collection[id] = new Jade.EventBus(id);
            }
        }
        contains(id) {
            return id in this.m_collection;
        }
        each(callback) {
            if (_.isFunction(callback)) {
                callback = () => { };
            }
            _.each(this.m_collection, (item, key) => {
                callback(key, item);
            });
        }
        getById(id) {
            var result = null;
            if (id in this.m_collection) {
                result = this.m_collection[id];
            }
            return result;
        }
        remove(id) {
            if (id in this.m_collection) {
                delete this.m_collection[id];
            }
        }
    }
    Jade.EventBusCollection = EventBusCollection;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class EventBusManager {
        constructor() {
            this.m_global = null;
            this.m_locals = null;
            this.m_currentLocalId = null;
            this.m_global = new Jade.EventBus({ label: "global" });
            this.m_locals = new Jade.EventBusCollection();
        }
        get currentLocalId() {
            return this.m_currentLocalId;
        }
        local(id = null) {
            var result = null;
            if (id != null) {
                result = this.m_locals.getById(id);
            }
            else {
                result = this.m_locals.getById(this.m_currentLocalId);
            }
            return result;
        }
        get global() {
            return this.m_global;
        }
        setLocal(id) {
            this.m_currentLocalId = id;
            this.m_locals.add(id);
        }
        destroy(id) {
            this.m_locals.remove(id);
            if (this.m_currentLocalId === id) {
                this.m_currentLocalId = null;
            }
        }
    }
    Jade.EventBusManager = EventBusManager;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class EventBusEvents {
        constructor() {
            this.m_events = {};
        }
        get events() {
            return this.m_events;
        }
        publish(eventType, data) {
            let register = this.get(eventType);
            if (register != null) {
                register.publish(data);
            }
        }
        subscribe(eventType, callback) {
            let register = null;
            if (Jade.String.isNullOrWhiteSpace(eventType)) {
                return;
            }
            if (!this.exists(eventType)) {
                this.add(eventType);
            }
            register = this.get(eventType);
            return register.subscribe(callback);
        }
        exists(eventType) {
            return this.events[eventType] != undefined;
        }
        add(eventType) {
            this.events[eventType] = new Jade.EventBusSubscriptions({
                empty: () => {
                    this.remove(eventType);
                }
            });
        }
        remove(eventType) {
            delete this.events[eventType];
        }
        get(eventType) {
            return this.events[eventType];
        }
    }
    Jade.EventBusEvents = EventBusEvents;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class EventBusSubscription {
        constructor(options) {
            this.m_callback = options.callback;
            this.m_subscriptionId = options.subscriptionId;
            this.m_unsubscribeCallback = options.unsubscribe;
        }
        get subscriptionId() {
            return this.m_subscriptionId;
        }
        get callback() {
            return this.m_callback || (() => { });
        }
        get unsubscribeCallback() {
            return this.m_unsubscribeCallback || (() => { });
        }
        invoke(data) {
            this.callback(data);
        }
        unsubscribe() {
            this.unsubscribeCallback(this.subscriptionId);
        }
    }
    Jade.EventBusSubscription = EventBusSubscription;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class EventBusSubscriptions {
        constructor(options) {
            this.m_subscriptions = {};
            this.m_emptyCallback = options.empty;
        }
        get emptyCallback() {
            return this.m_emptyCallback || (() => { });
        }
        get subscriptions() {
            return this.m_subscriptions;
        }
        publish(data) {
            Object.keys(this.subscriptions).forEach((subscriptionId) => {
                this.get(subscriptionId).invoke(data);
            });
        }
        subscribe(callback) {
            let subscriptionId = UUID.genV4().toString();
            let subscription;
            this.add(subscriptionId, callback);
            subscription = this.get(subscriptionId);
            return subscription;
        }
        exists(subscriptionId) {
            return this.subscriptions[subscriptionId] != undefined;
        }
        add(subscriptionId, callback) {
            this.subscriptions[subscriptionId] = new Jade.EventBusSubscription({
                subscriptionId: subscriptionId,
                callback: callback,
                unsubscribe: (id) => {
                    this.remove(id);
                }
            });
        }
        remove(subscriptionId) {
            delete this.subscriptions[subscriptionId];
            if (Object.keys(this.subscriptions).length === 0) {
                this.emptyCallback();
            }
        }
        get(subscriptionId) {
            return this.subscriptions[subscriptionId];
        }
    }
    Jade.EventBusSubscriptions = EventBusSubscriptions;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    class Database {
        constructor(id) {
            this.m_id = id;
        }
        get id() {
            return this.m_id;
        }
        static get instance() {
            return this.m_instance;
        }
        get connection() {
            return indexedDB.open(this.id);
        }
        static create(id) {
            let dbRequest = indexedDB.open(id);
            dbRequest.onupgradeneeded = ((e) => {
                _.each(Database.m_onCreateFunctions, (callback) => {
                    callback({
                        db: e.target.result,
                        e: e
                    });
                });
            });
            this.m_instance = new Database(id);
        }
        open(callback) {
            let request = indexedDB.open(this.id);
            request.onsuccess = ((sender, e) => {
                callback(request.result);
            });
        }
        static onCreate(callback) {
            Database.m_onCreateFunctions[Database.m_onCreateFunctions.length] = callback;
        }
    }
    Database.m_onCreateFunctions = [];
    Jade.Database = Database;
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var Data;
    (function (Data) {
        class Table {
            constructor(options) {
                this.m_name = options.name;
            }
            get name() {
                return this.m_name;
            }
        }
        Data.Table = Table;
        class TableOf extends Table {
            getOf(id, success, error) {
                Jade.Database.instance.open((database) => {
                    let transaction = database.transaction(this.name);
                    let request = transaction.objectStore(this.name).get(id);
                    request.onsuccess = ((e) => {
                        if (success != null) {
                            success(e.target.result);
                        }
                    });
                    request.onerror = ((e) => {
                        if (error != null) {
                            error();
                        }
                    });
                });
            }
            setOf(id, value, success, error) {
                Jade.Database.instance.open((database) => {
                    let transaction = database.transaction(this.name, "readwrite");
                    let request = null;
                    if (id !== null) {
                        request = transaction.objectStore(this.name).put(value, id);
                    }
                    else {
                        request = transaction.objectStore(this.name).put(value);
                    }
                    request.onsuccess = ((e) => {
                        if (success != null) {
                            success();
                        }
                    });
                    request.onerror = ((e) => {
                        if (error != null) {
                            error();
                        }
                    });
                });
            }
            delete(id, success, error) {
                Jade.Database.instance.open((database) => {
                    let transaction = database.transaction(this.name, "readwrite");
                    let request = transaction.objectStore(this.name).delete(id);
                    request.onsuccess = ((e) => {
                        if (success != null) {
                            success();
                        }
                    });
                    request.onerror = ((e) => {
                        if (error != null) {
                            error();
                        }
                    });
                });
            }
        }
        Data.TableOf = TableOf;
    })(Data = Jade.Data || (Jade.Data = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        let CssClass;
        (function (CssClass) {
            CssClass["MultiMessageDialog"] = "-jadejs-multi-msg-dialog";
            CssClass["MultiMessageDialogTitle"] = "-jadejs-multi-msg-dialog-title";
            CssClass["MultiMessageDialogContent"] = "-jadejs-multi-msg-dialog-content";
            CssClass["MultiMessageDialogContentItem"] = "-jadejs-multi-msg-dialog-content-item";
        })(CssClass = UI.CssClass || (UI.CssClass = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
Jade.Application.onStart(function () {
    $(window).resize(_.debounce(() => {
        Jade.Application
            .instance
            .contexts
            .global
            .events
            .publish(Jade.Events.BrowserResizedEvent);
    }, 250));
    $(window).focus(() => {
        Jade.Application
            .instance
            .contexts
            .global
            .events
            .publish(Jade.Events.BrowserFocusedEvent);
    });
});
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class Control {
            constructor(options) {
                this.m_node = null;
                this.m_state = null;
                this.m_controls = null;
                this.m_container = null;
                this.m_tags = null;
                this.m_firedEvents = new Jade.Collection();
                this.m_controls = new UI.ControlCollection(this);
                this.m_tags = new UI.ControlTagCollection();
                this.setControlOptions(options);
                this.wrapEventMethods();
                this.setDomAttachment();
            }
            get type() {
                return this.constructor.toString();
            }
            get ID() {
                return this.state.get("id");
            }
            get controls() {
                return this.m_controls;
            }
            get state() {
                return this.m_state;
            }
            get node() {
                return this.m_node;
            }
            get insertAt() {
                return this.state.get("insertAt");
            }
            get container() {
                return this.m_container;
            }
            set container(value) {
                this.m_container = value;
            }
            get subscriptions() {
                return this.m_subscriptions;
            }
            get tags() {
                return this.m_tags;
            }
            get isDetached() {
                return this.node != null
                    && this.node.length > 0
                    && !$.contains(document.documentElement, this.node.get(0));
            }
            get isBrowserResizeAware() {
                return this.state.get("isBrowserResizeAware", false);
            }
            set isBrowserResizeAware(value) {
                this.setBrowserResizeAwareness(value);
                this.state.set("isBrowserResizeAware", value, {
                    silent: this.node == null
                });
            }
            onBrowserResize() {
            }
            onInit(e) {
            }
            onLoad(e) {
            }
            onTemplate(e) {
            }
            onTemplated(e) {
            }
            onRender(e) {
            }
            onActivate(e) {
            }
            onComplete(e) {
            }
            onDestroy(e) {
            }
            onDetach(e) {
            }
            onAttach(e) {
            }
            onStateChanged() {
            }
            template() {
                return "<div></div>";
            }
            destroy() {
                this.subscriptions.clear();
                this.onDestroy(new UI.ControlEventArgs(this));
                if (this.node != null) {
                    this.node.remove();
                }
            }
            detach() {
                this.onDetach(new UI.ControlEventArgs(this));
                this.node.detach();
            }
            attachToDOM(e) {
                if (this.container instanceof jQuery) {
                    if (this.state.get("replaceContainer") === true) {
                        this.container.replaceWith(this.node);
                    }
                    else {
                        this.container.append(this.node);
                    }
                    return;
                }
                var children = e.parent.controls, parentNode = this.insertAt != null ? e.node.find(this.insertAt) : e.insertAtNode, insertNode = $(), countOfChildren = children.count, insertAtIndex = children.indexOf(this), insertAtChild = null;
                if (insertAtIndex < countOfChildren) {
                    insertAtChild = children.item(insertAtIndex + 1);
                    if (insertAtChild != null) {
                        insertNode = parentNode.children("#" + insertAtChild.ID);
                    }
                }
                if (insertNode.length === 1) {
                    insertNode.before(this.node);
                }
                else {
                    parentNode.append(this.node);
                }
                this.onAttach(new UI.ControlEventArgs(this));
            }
            setControlOptions(options) {
                let mustCreateModel = this.m_state == null;
                let extendedOptions = null;
                if (mustCreateModel) {
                    extendedOptions = _.extend(this.getDefaultOptions(), options);
                    this.m_state = new Jade.StateBag();
                    this.m_state.set(extendedOptions);
                }
                if (!mustCreateModel) {
                    this.m_state.set(options);
                }
                if (options.id == null) {
                    this.state.set("id", UUID.genV4().toString(), { silent: true });
                }
                else {
                    this.state.set("id", options.id, { silent: true });
                }
            }
            getDefaultOptions() {
                return {};
            }
            fireEvent(eventName, args) {
                let isAttachedAndVaildEvent = !this.isDetached && !this.m_firedEvents.contains(eventName);
                let isDetachedAndVaildEvent = this.isDetached && UI.ControlEvents.detachedControlEvents.contains(eventName);
                if (isAttachedAndVaildEvent || isDetachedAndVaildEvent) {
                    this[eventName](args);
                    this.m_firedEvents.add(eventName);
                }
            }
            wrapEventMethods() {
                let encapsulatedFunctions = {};
                encapsulatedFunctions[UI.ControlEvent.onTemplate] = (e) => {
                    this.setTemplate(e);
                };
                encapsulatedFunctions[UI.ControlEvent.onRender] = (e) => {
                    this.attachToDOM(e);
                };
                encapsulatedFunctions[UI.ControlEvent.onComplete] = () => {
                    this.state.on("change", (e) => {
                        this.onStateChanged();
                    }, this);
                    this.onStateChanged();
                };
                encapsulatedFunctions[UI.ControlEvent.onDestroy] = (e) => {
                    this.controls.each((control) => {
                        control.destroy();
                    });
                };
                this.m_subscriptions = new UI.ControlEventSubscriptions();
                UI.ControlEvents.autoInvokedControlEvents.each((eventName) => {
                    this.wrapAndAssignEventMethod(eventName, encapsulatedFunctions[eventName]);
                });
                this.wrapAndAssignEventMethod(UI.ControlEvent.onDestroy, encapsulatedFunctions[UI.ControlEvent.onDestroy]);
            }
            wrapAndAssignEventMethod(eventName, encapsulatedFunction) {
                let eventFn = this[eventName];
                let eventStartFn = this[eventName + "Start"];
                let eventCompleteFn = this[eventName + "Complete"];
                let eventFunctionWrapped = null;
                eventFunctionWrapped = (e) => {
                    if (eventStartFn != null) {
                        eventStartFn.call(this, e);
                    }
                    if (_.isFunction(encapsulatedFunction)) {
                        encapsulatedFunction(e);
                    }
                    eventFn.call(this, e);
                    this.controls.controlEvents.fireEvent(eventName);
                    if (eventCompleteFn != null) {
                        eventCompleteFn.call(this, e);
                    }
                };
                this[eventName] = eventFunctionWrapped;
            }
            fireEvents() {
                var args = new UI.ControlEventArgs(this);
                UI.ControlEvents.autoInvokedControlEvents.each((eventName) => {
                    if (!this.m_firedEvents.contains(eventName)) {
                        this.fireEvent(eventName, args);
                        this.m_firedEvents.add(eventName);
                    }
                });
            }
            wrapTemplate(template) {
                return template;
            }
            setTemplate(e) {
                var template = this.parseTemplate();
                template = this.wrapTemplate(template);
                template.attr("id", this.ID);
                this.m_node = template;
            }
            parseTemplate() {
                var template = this.template();
                var result = null;
                if (template == null) {
                    throw "Call to method \"template\" returned a NULL value.";
                }
                switch (true) {
                    case template instanceof jQuery:
                        result = template;
                        break;
                    case _.isArray(template):
                        result = $(template.join(""));
                        break;
                    case _.isString(template):
                        result = $(template);
                        break;
                    default:
                        throw "The value returned by the \"template\" method is invalid.";
                }
                if (result != null) {
                    if (result.get(0) != null && result.get(0).hasAttribute("data-controls")) {
                        result.data("controls", this.ID);
                        result.attr("data-controls", this.ID);
                    }
                    else {
                        result.find("[data-controls]").data("controls", this.ID);
                        result.find("[data-controls]").attr("data-controls", this.ID);
                    }
                }
                return result;
            }
            setDomAttachment() {
                let container = this.state.get("container");
                if (_.isString(container)) {
                    container = $(container);
                }
                if (container instanceof jQuery) {
                    this.container = container;
                    this.fireEvents();
                    return;
                }
                let insertAt = this.state.get("insertAt");
                if (_.isString(insertAt)) {
                    insertAt = $(insertAt);
                }
            }
            setBrowserResizeAwareness(isAware) {
                if (isAware) {
                    this.m_onBrowserResizeSubscription =
                        this.subscriptions.add(Jade.Events.BrowserResizedEvent, () => {
                            this.onBrowserResize();
                        });
                }
                else {
                    if (this.m_onBrowserResizeSubscription != null) {
                        this.m_onBrowserResizeSubscription.unsubscribe();
                    }
                }
            }
        }
        UI.Control = Control;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ContextMenu extends UI.Control {
            constructor(options) {
                super(options);
            }
            get filter() {
                return this.state.get("filter");
            }
            get items() {
                return this.m_items;
            }
            get segments() {
                return this.m_segments;
            }
            get instance() {
                return this.m_instance;
            }
            onInit(e) {
                this.m_items = new UI.ContextMenuItemCollection();
                this.m_segments = new Jade.Collection();
            }
            onActivate(e) {
                var items = [];
                this.items.each((item) => {
                    items[items.length] = item.toJSON();
                });
                this.iterateNodes(items, function (item) {
                    delete item.imageUrl;
                    delete item.spriteCssClass;
                });
                let options = this.mergeOptions({
                    dataSource: items,
                    select: _.bind(this.onClick, this),
                    open: _.bind(this.onOpen, this),
                    filter: this.filter
                });
                this.m_instance = this.node.kendoContextMenu(options).data("kendoContextMenu");
            }
            onClick(e) {
                let item = null;
                let node = $(e.item);
                let id = node.find(".k-link:first > [data-id]").data("id");
                this.iterateItems(this.items, function (i) {
                    if (i.ID === id) {
                        item = i;
                        return false;
                    }
                });
                this.segments.each((segment) => {
                    segment.click(this, node, item);
                });
            }
            onOpen(e) {
                let node = $(e.target);
                this.segments.each((segment) => {
                    segment.open(this, node);
                });
            }
            onTemplate(e) {
                super.onTemplate(e);
                this.addSegments(e);
                this.addItems(e);
            }
            onDestroy(e) {
                if (this.instance != null) {
                    this.instance.destroy();
                }
            }
            template() {
                return "<ul class='-jadejs-context-menu'></ul>";
            }
            mergeOptions(settings) {
                let result = null;
                result = this.state.extend(settings, {
                    animation: {
                        open: {
                            effects: "fadeIn",
                            duration: 150
                        },
                        close: {
                            effects: "none"
                        }
                    },
                    target: this.state.get("target", undefined),
                    filter: this.state.get("filter", undefined),
                    showOn: this.state.get("showOn", undefined),
                    direction: this.state.get("direction", "default"),
                    alignToAnchor: this.state.get("alignToAnchor", false),
                    orientation: this.state.get("orientation", "vertical")
                });
                return result;
            }
            addSegments(e) {
                let pendingSegments = this.state.get("segments", []);
                if (!_.isArray(pendingSegments)) {
                    pendingSegments = [pendingSegments];
                }
                let resolvedSegments = this.resolveSegments(pendingSegments);
                resolvedSegments.each((segment) => {
                    if (segment.meetsLoadConditions(e)) {
                        this.segments.add(segment);
                    }
                });
            }
            resolveSegments(source) {
                let result = new Jade.Collection();
                _.each(source, (item) => {
                    let type = Jade.Type.getType(item.type);
                    let ctxt = item.context || (() => { });
                    let instance = new type(ctxt);
                    result.add(instance);
                });
                return result;
            }
            addItems(e) {
                this.segments.each((segment) => {
                    segment.onAddItems(new UI.ContextMenuOnAddItemsEventArgs({
                        menu: this,
                        items: this.items,
                        segment: segment
                    }));
                });
            }
            iterateItems(items, callback) {
                let abort = false;
                items.each((item) => {
                    var abort = false;
                    if (_.isFunction(callback)) {
                        abort = callback(item) === false;
                    }
                    return !abort;
                });
            }
            iterateNodes(items, callback) {
                let abort = false;
                _.each(items, (item) => {
                    if (_.isFunction(callback)) {
                        abort = callback(item) === false;
                    }
                    if (!abort && item.items) {
                        this.iterateNodes(item.items, callback);
                    }
                });
            }
        }
        UI.ContextMenu = ContextMenu;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ContextMenuEventArgs {
            constructor(options) {
                this.m_menu = options.menu;
                this.m_target = options.target;
                this.m_context = UI.ContextMenuUtil.transformContext(options.context);
            }
            get menu() {
                return this.m_menu;
            }
            get target() {
                return this.m_target;
            }
            get context() {
                return this.m_context;
            }
        }
        UI.ContextMenuEventArgs = ContextMenuEventArgs;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ContextMenuItemBase {
            constructor(options) {
                this.m_state = null;
                this.m_items = null;
                this.m_items = [];
                this.setOptions(options);
            }
            get items() {
                return this.m_items;
            }
            get state() {
                return this.m_state;
            }
            get ID() {
                return this.state.get("id");
            }
            onInit(e) {
                this.state.set(this.getDefaultOptions());
            }
            onLoad(e) {
            }
            onComplete(e) {
            }
            onClick(e) {
            }
            onOpen(e) {
                let openCallback = this.state.get("open", () => { });
                if (_.isFunction(openCallback)) {
                    openCallback(e);
                }
            }
            init(e = {}) {
                this.onInit(e);
            }
            load(e = {}) {
                this.onLoad(e);
            }
            complete(e = {}) {
                this.onComplete(e);
            }
            click(e = {}) {
                this.onClick(e);
            }
            open(e = {}) {
                let id = this.state.get("id");
                let selector = Jade.String.format("[data-id={0}]", this.ID);
                let node = $(e.menu.instance.element).find(selector).closest("LI");
                this.onOpen(new UI.ContextMenuItemOpenEventArgs({
                    menu: e.menu,
                    item: this,
                    node: node,
                    target: e.target,
                    context: e.context
                }));
            }
            toJSON() {
                let result = null;
                result = _.extend(this.state.toJSON(), {
                    text: this.applyTemplate(),
                    encoded: false,
                    attributes: {
                        "data-id": this.state.get("id")
                    }
                });
                return result;
            }
            getDefaultOptions() {
                return {
                    imageUrl: null,
                    id: UUID.genV4().toString(),
                    enable: true,
                    open: true,
                    overflow: "auto",
                    text: "",
                    type: "button",
                    cssClass: ""
                };
            }
            setOptions(options) {
                let mustCreateModel = this.m_state == null;
                let extendedOptions = null;
                if (mustCreateModel) {
                    extendedOptions = _.extend(this.getDefaultOptions(), options);
                    this.m_state = new Jade.StateBag(extendedOptions);
                }
                else {
                    this.m_state.set(options);
                }
            }
            applyTemplate(data) {
                let template = this.state.get("template");
                data = data || this.state.toJSON();
                if (!template) {
                    template = new UI.ContextMenuItemTemplate();
                }
                return template.apply(data);
            }
        }
        UI.ContextMenuItemBase = ContextMenuItemBase;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ContextMenuItem extends UI.ContextMenuItemBase {
            constructor(options) {
                super(options);
            }
            get command() {
                return this.m_command;
            }
            onInit(e) {
                super.onInit(e);
                this.assignCommand(this.state.toJSON());
            }
            onClick(e) {
                if (_.isFunction(this.command)) {
                    this.command(e);
                }
            }
            assignCommand(e) {
                let isFunction = _.isFunction(e);
                let isObjectWithCommand = _.isObject(e) && _.isFunction(e.command);
                let isCommandObject = _.isObject(e) && _.isFunction(e.execute);
                switch (true) {
                    case isFunction || isCommandObject:
                        this.m_command = e;
                        break;
                    case isObjectWithCommand:
                        this.m_command = e.command;
                        break;
                }
            }
        }
        UI.ContextMenuItem = ContextMenuItem;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ContextMenuItemCollection extends Jade.Collection {
            contains(item) {
                var result = false;
                result = _.find(this.innerList, (menuItem) => {
                    return item.ID === menuItem.ID;
                }) != null;
                return result;
            }
        }
        UI.ContextMenuItemCollection = ContextMenuItemCollection;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ContextMenuItemCommand extends UI.ContextMenuItemBase {
            constructor(options) {
                super(options);
                this.m_commandBag = new UI.CommandBag({
                    contextId: this.state.get("contextId"),
                    commandId: this.state.get("commandId")
                });
            }
            get commandBag() {
                return this.m_commandBag;
            }
            onClick(e) {
                if (this.commandBag.command.enabled) {
                    this.commandBag.execute(e);
                }
            }
            onOpen(e) {
                this.commandBag.bind();
                if (!this.commandBag.isCommandResolved()) {
                    return;
                }
                var bindingFn = () => {
                    _.bind(this.bind, this)(e);
                };
                this.commandBag.command.bind(bindingFn);
            }
            bind(e) {
                let template = null;
                let item = e.node.find(".-jadejs-ctx-menu-item");
                let command = this.commandBag.command;
                item.empty();
                template = this.getTemplate({
                    id: this.ID,
                    text: command.props.get("label"),
                    imageUrl: command.getIcon(Jade.IconSetSizeSpecificDirectory.x16)
                });
                if (command.props.get("visible")) {
                    e.node.removeClass("hidden");
                }
                else {
                    e.node.addClass("hidden");
                }
                if (command.props.get("enabled")) {
                    e.node.removeAttr("disabled");
                }
                else {
                    e.node.attr("disabled", "disabled");
                }
                item.html(template.html());
            }
            getTemplate(data) {
                let result = this.applyTemplate(data);
                return $(result);
            }
            setDefaultValues(e) {
            }
        }
        UI.ContextMenuItemCommand = ContextMenuItemCommand;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ContextMenuItemOpenEventArgs {
            constructor(options) {
                this.m_menu = options.menu;
                this.m_item = options.item;
                this.m_node = options.node;
                this.m_target = options.target;
                this.m_context = options.context;
            }
            get menu() {
                return this.m_menu;
            }
            get item() {
                return this.m_item;
            }
            get node() {
                return this.m_node;
            }
            get target() {
                return this.m_target;
            }
            get context() {
                return this.m_context;
            }
            enabled(value) {
                this.menu.instance.enable(this.node, value);
            }
            label(value) {
                this.node.find(".-pd-menu-text").empty();
                this.node.find(".-pd-menu-text").append(value);
            }
            icon(value) {
            }
            visible(value) {
                value === true ? this.node.show() : this.node.hide();
            }
        }
        UI.ContextMenuItemOpenEventArgs = ContextMenuItemOpenEventArgs;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ContextMenuItemTemplate {
            apply(e = {}) {
                let result = "";
                if (e.separator) {
                    result = `<div class='-jadejs-ctx-menu-sep'></div>`;
                }
                else {
                    result = [
                        "<span data-id='" + e.id + "' class='-jadejs-ctx-menu-item'>",
                        "<span class='-jadejs-ctx-menu-icon'>",
                        e.imageUrl != null ? "<img src='" + e.imageUrl + "'>" : "",
                        "</span>",
                        "<span class='-jadejs-ctx-menu-text'>",
                        e.text || e.label,
                        "</span>",
                        "</span>"
                    ].join("");
                }
                return result;
            }
        }
        UI.ContextMenuItemTemplate = ContextMenuItemTemplate;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ContextMenuOnAddItemsEventArgs {
            constructor(options) {
                this.m_items = options.items;
                this.m_menu = options.menu;
                this.m_segment = options.segment;
            }
            addItem(item) {
                this.m_items.add(item);
                this.m_segment.items.add(item);
            }
            addSeparator() {
                this.addItem(new UI.ContextMenuItem({
                    separator: true,
                    cssClass: "separator"
                }));
            }
        }
        UI.ContextMenuOnAddItemsEventArgs = ContextMenuOnAddItemsEventArgs;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ContextMenuSegment {
            constructor(context) {
                this.m_items = new UI.ContextMenuItemCollection();
                this.m_oldContext = context;
                this.m_newContext = UI.ContextMenuUtil.transformContext(context);
            }
            get oldContext() {
                return this.m_newContext;
            }
            get context() {
                return this.m_newContext;
            }
            get items() {
                return this.m_items;
            }
            onAddItems(e) {
            }
            meetsLoadConditions(e) {
                return true;
            }
            open(menu, target) {
                let args = new UI.ContextMenuEventArgs({
                    menu: menu,
                    target: target,
                    context: this.oldContext
                });
                this.onOpen(args);
                this.items.each((item) => {
                    item.open(args);
                });
                this.hidePairedSeparators(menu);
            }
            click(menu, target, item) {
                let args = new UI.ContextMenuEventArgs({
                    menu: menu,
                    target: target,
                    context: this.oldContext
                });
                this.onClick(args);
                item.click(args);
            }
            onOpen(e) {
            }
            onClick(e) {
            }
            hidePairedSeparators(menu) {
                let items = menu.instance.element.find("LI");
                items.each((index, element) => {
                    var item = $(element);
                    var isCurrSeparator = item.hasClass("separator");
                    if (isCurrSeparator) {
                        let prev = item.prev("LI").not(".hidden").first();
                        let isPrevSeparator = prev.hasClass("separator");
                        let hasNoVisibleSibling = prev.length === 0;
                        if (isPrevSeparator || hasNoVisibleSibling) {
                            item.addClass("hidden");
                        }
                        else {
                            item.removeClass("hidden");
                        }
                    }
                });
                var last = items.not(".hidden").last();
                if (last.hasClass("separator")) {
                    last.addClass("hidden");
                }
            }
        }
        UI.ContextMenuSegment = ContextMenuSegment;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ContextMenuUtil {
            static transformContext(context, target = {}) {
                let result = {};
                switch (true) {
                    case _.isFunction(context):
                        result = context(target);
                        break;
                    case _.isObject(context):
                        result = context;
                        break;
                }
                return result;
            }
        }
        UI.ContextMenuUtil = ContextMenuUtil;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class CommandBag {
            constructor(options) {
                this.m_options = new Jade.StateBag(options);
                this.bind();
            }
            get context() {
                return this.ensureContext();
            }
            get contextId() {
                return this.options.get("contextId");
            }
            get commandContext() {
                return this.context.commands;
            }
            get commandId() {
                return this.options.get("commandId");
            }
            get command() {
                return this.m_command;
            }
            get options() {
                return this.m_options;
            }
            execute(e) {
                if (this.command != null) {
                    this.commandContext.execute(this.commandId, e);
                }
            }
            bind() {
                this.ensureCommandInfo();
            }
            isCommandResolved() {
                return this.m_commandInfo != null &&
                    this.m_commandInfo.command != null;
            }
            ensureCommandInfo() {
                if (this.m_commandInfo != null || this.commandId == null) {
                    return;
                }
                this.m_commandInfo = this.commandContext.resolve(this.commandId);
                if (this.isCommandResolved()) {
                    this.m_command = this.m_commandInfo.command;
                }
            }
            ensureContext() {
                let result = Jade
                    .Application
                    .instance
                    .contexts
                    .getContextById(this.contextId);
                if (result == null) {
                    result = Jade
                        .Application
                        .instance
                        .contexts
                        .current;
                }
                return result;
            }
        }
        UI.CommandBag = CommandBag;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ControlCollection extends Jade.ObservableMappedCollection {
            constructor(parent, callbacks) {
                super({ key: "ID", data: new Array() });
                this.m_parent = null;
                this.m_controlEvents = new UI.ControlCollectionControlEvents(this);
                this.m_parent = parent;
            }
            get parent() {
                return this.m_parent;
            }
            get controlEvents() {
                return this.m_controlEvents;
            }
            add(item) {
                var result = false;
                this.executeChange("Add", item, this.count - 1, () => {
                    result = super.add(item);
                    if (result) {
                        this.controlEvents.syncControlEvents(item);
                    }
                });
                return result;
            }
            detach(item) {
                this.executeChange("Detach", item, this.indexOf(item), () => {
                    super.remove(item);
                    if (item.node != null) {
                        item.node.detach();
                    }
                });
            }
            insert(item, index) {
                var result = false;
                this.executeChange("Insert", item, index, () => {
                    result = super.insert(item, index);
                    if (result) {
                        this.controlEvents.syncControlEvents(item);
                    }
                });
                return result;
            }
            remove(item) {
                this.executeChange("Remove", item, this.indexOf(item), () => {
                    super.remove(item);
                    item.destroy();
                });
                return item;
            }
            clear() {
                let copy = this.innerList.slice(0);
                _.each(copy, (item) => {
                    this.remove(item);
                });
            }
            reverse() {
                _.reverse(this.innerList);
            }
            getById(id) {
                return this.map[id];
            }
        }
        UI.ControlCollection = ControlCollection;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ControlCollectionControlEvents {
            constructor(collection) {
                this.m_collection = null;
                this.m_firedEvents = [];
                this.m_collection = collection;
            }
            get collection() {
                return this.m_collection;
            }
            get firedEvents() {
                return this.m_firedEvents;
            }
            hasEventFired(eventName) {
                return this.firedEvents.indexOf(eventName) > -1;
            }
            fireEvent(eventName) {
                this.collection.each((control) => {
                    this.fireControlEvent(control, eventName);
                });
                this.addToFiredEvents(eventName);
            }
            syncControlEvents(item) {
                _.each(this.firedEvents, (eventName) => {
                    this.fireControlEvent(item, eventName);
                });
            }
            fireControlEvent(item, eventName) {
                item.fireEvent(eventName, new UI.ControlEventArgs(this.collection.parent));
            }
            addToFiredEvents(eventName) {
                var eventHasBeenFired = _.indexOf(this.firedEvents, eventName) > -1;
                if (!eventHasBeenFired) {
                    this.firedEvents[this.firedEvents.length] = eventName;
                }
            }
        }
        UI.ControlCollectionControlEvents = ControlCollectionControlEvents;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ControlEventArgs {
            constructor(parent) {
                this.m_parent = null;
                this.m_parent = parent;
            }
            get parent() {
                return this.m_parent;
            }
            get node() {
                return this.parent.node;
            }
            get insertAtNode() {
                let result = this.node;
                let insert = null;
                if (this.parent.node != null) {
                    insert = this.parent.node.find(`[data-controls=${this.parent.ID}]`).first();
                }
                if (insert != null && insert.length > 0) {
                    result = insert;
                }
                return result;
            }
        }
        UI.ControlEventArgs = ControlEventArgs;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ControlEventSubscriptions {
            constructor() {
                this.m_subscriptions = [];
            }
            get subscriptions() {
                return this.m_subscriptions;
            }
            get eventBus() {
                return Jade.Application.instance.contexts.current.events;
            }
            add(eventName, callback) {
                let subscription = this.eventBus.subscribe(eventName, callback);
                this.subscriptions[this.subscriptions.length] = subscription;
                return subscription;
            }
            clear() {
                this.subscriptions.forEach(subscription => {
                    subscription.unsubscribe();
                });
                this.m_subscriptions = [];
            }
        }
        UI.ControlEventSubscriptions = ControlEventSubscriptions;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        let ControlEvent;
        (function (ControlEvent) {
            ControlEvent["onInit"] = "onInit";
            ControlEvent["onLoad"] = "onLoad";
            ControlEvent["onTemplate"] = "onTemplate";
            ControlEvent["onRender"] = "onRender";
            ControlEvent["onActivate"] = "onActivate";
            ControlEvent["onComplete"] = "onComplete";
            ControlEvent["onDestroy"] = "onDestroy";
            ControlEvent["onDetach"] = "onDetach";
        })(ControlEvent = UI.ControlEvent || (UI.ControlEvent = {}));
        class ControlEvents {
            static get autoInvokedControlEvents() {
                return this.m_autoInvokedControlEvents;
            }
            static get detachedControlEvents() {
                return this.m_detachedControlEvents;
            }
        }
        ControlEvents.m_autoInvokedControlEvents = new Jade.Collection([
            ControlEvent.onInit,
            ControlEvent.onLoad,
            ControlEvent.onTemplate,
            ControlEvent.onRender,
            ControlEvent.onActivate,
            ControlEvent.onComplete
        ]);
        ControlEvents.m_detachedControlEvents = new Jade.Collection([
            ControlEvent.onRender
        ]);
        UI.ControlEvents = ControlEvents;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ControlTagCollection {
            constructor() {
                this.m_collection = {};
            }
            add(tags) {
                switch (true) {
                    case _.isArray(tags):
                        this.addTags(tags);
                        break;
                    case _.isString(tags):
                        this.addTag(tags);
                        break;
                }
            }
            remove(tags) {
                switch (true) {
                    case _.isArray(tags):
                        this.removeTags(tags);
                        break;
                    case _.isString(tags):
                        this.removeTag(tags);
                        break;
                }
            }
            match(tags, exactMatch = false) {
                let result = null;
                _.each(tags, (tag) => {
                    if (exactMatch) {
                        if (result !== false) {
                            result = tag in this.m_collection;
                        }
                    }
                    else {
                        if (result !== true) {
                            result = tag in this.m_collection;
                        }
                    }
                });
                if (result === null) {
                    result = false;
                }
                return result;
            }
            addTag(tag) {
                if (tag == null) {
                    return;
                }
                tag = tag.toLowerCase();
                if (!(tag in this.m_collection)) {
                    this.m_collection[tag] = true;
                }
            }
            addTags(tags) {
                _.each(tags, (tag) => {
                    this.addTag(tag);
                });
            }
            removeTag(tag) {
                if (tag == null) {
                    return;
                }
                tag = tag.toLowerCase();
                if (tag in this.m_collection) {
                    delete this.m_collection[tag];
                }
            }
            removeTags(tags) {
                _.each(tags, (tag) => {
                    this.addTag(tag);
                });
            }
        }
        UI.ControlTagCollection = ControlTagCollection;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class Dialog extends UI.Control {
            constructor(options = {}, windowOptions = {}) {
                super(_.extend(options, { windowOptions: windowOptions }));
            }
            get context() {
                return Jade.Application
                    .instance
                    .contexts
                    .getContextById(this.ID);
            }
            get window() {
                return this.m_window;
            }
            get title() {
                return this.state.get("title", "Message");
            }
            onRender(e) {
                this.window.setContent(this.node);
            }
            onResize(e) {
            }
            close(options = {}) {
                if (this.window != null) {
                    this.window.close(options);
                }
                this.destroy();
            }
            center() {
                this.window.center();
            }
            setTitle(title) {
                this.window.setTitle(title);
            }
            setDimensions(height, width) {
                this.window.setDimensions(height, width);
            }
            static open(options = {}, windowOptions = {}) {
                return new Dialog(options, _.extend({
                    height: "200px",
                    width: "450px"
                }, windowOptions));
            }
            getDefaultOptions() {
                return {};
            }
            setControlOptions(options) {
                super.setControlOptions(_.merge(this.getDefaultOptions(), options));
                let windowOptions = this.getWindowOptions();
                this.createWindow(options, _.extend(windowOptions, {
                    context: this.ID
                }));
                super.setControlOptions({
                    container: this.window.content
                });
            }
            getWindowOptions() {
                let result = this.state.get("windowOptions");
                result = _.extend(result, {
                    title: this.title
                });
                return result;
            }
            onCreateContext(e) {
            }
            onDestroyContext(e) {
            }
            createWindow(options, windowOptions) {
                this.m_window = new UI.Window(windowOptions, _.extend(options.callbacks, {
                    close: (e) => {
                    },
                    resize: (e) => {
                        if (this.node != null) {
                            this.onResize(e);
                        }
                    },
                    onCreateContext: (e) => {
                        this.onCreateContext(e);
                    },
                    onDestroyContext: (e) => {
                        this.onDestroyContext(e);
                    }
                }));
            }
        }
        UI.Dialog = Dialog;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class Window {
            constructor(options, callbacks = null) {
                this.m_container = null;
                this.m_content = null;
                this.m_callbacks = null;
                this.m_options = null;
                this.m_instance = null;
                this.setWindowOptions(options);
                this.setWindowCallbacks(callbacks);
                this.frame();
                this.activate();
            }
            get ID() {
                return this.options.get("id");
            }
            get contextId() {
                return this.options.get("contextId", this.ID);
            }
            get callbacks() {
                return this.m_callbacks;
            }
            get container() {
                return this.m_container;
            }
            set container(value) {
                this.m_container = value;
            }
            get content() {
                return this.m_content;
            }
            set content(value) {
                this.m_content = value;
            }
            get instance() {
                return this.m_instance;
            }
            set instance(value) {
                this.m_instance = value;
            }
            get options() {
                return this.m_options;
            }
            get kendo() {
                return this.m_instance;
            }
            onDestroy() {
                this.m_instance.destroy();
            }
            onRefresh() {
                let callback = this.callbacks.get("refresh");
                if (_.isFunction(callback)) {
                    callback();
                }
                this.instance.center();
                this.instance.trigger("resize");
                this.onResize();
            }
            onResize() {
                let callback = this.callbacks.get("resize");
                if (_.isFunction(callback)) {
                    _.bind(callback, this)();
                }
            }
            onBrowserResize() {
                if (!this.instance.options.isMaximized) {
                    this.instance.center();
                }
            }
            onCreateContext() {
            }
            onDestroyContext() {
            }
            close(options = null) {
                if (options == null) {
                    this.invokeCallback("cancel", {});
                }
                else {
                    this.invokeCallback(options.command, options.data);
                }
                this.destroyContext();
                this.instance.destroy();
                this.destroyEventSubscriptions();
            }
            setContent(content) {
                this.content.empty();
                this.content.append(content);
            }
            center() {
                this.instance.center();
            }
            setTitle(title) {
                this.setOptions({
                    title: title
                });
            }
            setDimensions(height, width) {
                this.instance.wrapper.css({
                    height: height,
                    width: width
                });
                this.center();
            }
            setOptions(options) {
                this.instance.setOptions(options);
                this.setWindowButtonIcons();
            }
            frame() {
                let markup = this.options.get("markup"), frame = [
                    "<div>",
                    markup ? markup : "<table class=\"-pd-window-loading\" style='height:100%;width:100%;'><tr><td style='text-align:center;'>Loading...</td></tr></table>",
                    "</div>"
                ];
                if ($("body > DIV[data-role=windows]").length === 0) {
                    $("body").append("<div data-role='windows'></div>");
                }
                this.content = $(frame.join("")).appendTo("body > DIV[data-role=windows]");
            }
            activate() {
                let config = _.extend(this.options.toJSON(), {
                    animation: false,
                    resize: _.bind(_.debounce(this.onResize, 200), this),
                    refresh: _.bind(this.onRefresh, this),
                    visible: false,
                    close: (e) => {
                        let callback = this.callbacks.get("close");
                        if (_.isFunction(callback)) {
                            _.bind(callback, this)();
                        }
                        else {
                            this.close();
                        }
                        this.destroyContext();
                    }
                });
                this.instance = this.content.kendoWindow(config).data("kendoWindow");
                this.container = this.content.parent();
                this.container.attr("id", this.options.get("id"));
                this.container.addClass("-jadejs-window");
                if (this.options.get("maximized", false)) {
                    this.instance.maximize();
                }
                this.instance.center();
                this.instance.open();
                this.instance.refresh({});
                this.createContext();
                this.setWindowButtonIcons();
                this.m_browserResizeSubscription =
                    Jade.Application
                        .instance
                        .contexts
                        .global
                        .events
                        .subscribe("Window:Resized", () => {
                        this.onBrowserResize();
                    });
            }
            setWindowOptions(options) {
                let mustCreateModel = this.m_options == null;
                if (mustCreateModel) {
                    this.m_options = new Jade.StateBag({
                        modal: true,
                        content: null,
                        markup: null,
                        minHeight: 50,
                        close: _.bind(this.close, this)
                    });
                    this.m_options.set("id", UUID.genV4().toString());
                    this.m_options.set(options);
                }
                if (!mustCreateModel) {
                    this.m_options.set(options);
                }
            }
            setWindowCallbacks(callbacks) {
                let mustCreateModel = this.m_callbacks == null;
                if (mustCreateModel) {
                    this.m_callbacks = new Jade.StateBag(callbacks);
                }
                if (!mustCreateModel) {
                    this.m_callbacks.set(callbacks);
                }
            }
            invokeCallback(command, args) {
                let callback = this.callbacks.get(command, () => {
                    console.log(`Could not find callback function "${command}".`);
                });
                if (_.isFunction(callback)) {
                    callback(this, args);
                }
            }
            setWindowButtonIcons() {
                let prefix = "k-window-action";
                let icon = null;
                icon = Jade.IconSet.get("jadejs").resolve("white-restore.png", Jade.IconSetSizeSpecificDirectory.misc);
                this.container.find(`.${prefix} .k-i-restore`).css({
                    backgroundImage: `url(${icon})`
                });
                icon = Jade.IconSet.get("jadejs").resolve("white-maximize.png", Jade.IconSetSizeSpecificDirectory.misc);
                this.container.find(`.${prefix} .k-i-maximize`).css({
                    backgroundImage: `url(${icon})`
                });
                icon = Jade.IconSet.get("jadejs").resolve("white-close.png", Jade.IconSetSizeSpecificDirectory.misc);
                this.container.find(`.${prefix} .k-i-close`).css({
                    backgroundImage: `url(${icon})`
                });
            }
            createContext() {
                let contextName = this.options.get("title", null);
                Jade.Application.instance.contexts.createContext({
                    id: this.contextId,
                    name: contextName,
                    isDialogContext: true,
                    contextNode: this.content
                });
                this.callbacks.get("onCreateContext", () => { })({
                    contextId: this.contextId,
                    contextName: contextName
                });
            }
            destroyContext() {
                let context = Jade.Application.instance.contexts.getContextById(this.contextId);
                if (context == null) {
                    return;
                }
                Jade.Application.instance.contexts.destroyContext({
                    id: this.contextId
                });
                this.callbacks.get("onDestroyContext", () => { })({
                    contextId: this.contextId
                });
            }
            destroyEventSubscriptions() {
                if (this.m_browserResizeSubscription != null) {
                    this.m_browserResizeSubscription.unsubscribe();
                }
            }
        }
        UI.Window = Window;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        let MessageDialogStyle;
        (function (MessageDialogStyle) {
            MessageDialogStyle[MessageDialogStyle["Success"] = 1] = "Success";
            MessageDialogStyle[MessageDialogStyle["Error"] = 2] = "Error";
            MessageDialogStyle[MessageDialogStyle["Warning"] = 3] = "Warning";
            MessageDialogStyle[MessageDialogStyle["Information"] = 4] = "Information";
        })(MessageDialogStyle = UI.MessageDialogStyle || (UI.MessageDialogStyle = {}));
        let MessageDialogButtonStyle;
        (function (MessageDialogButtonStyle) {
            MessageDialogButtonStyle[MessageDialogButtonStyle["OK"] = 1] = "OK";
            MessageDialogButtonStyle[MessageDialogButtonStyle["OKCancel"] = 2] = "OKCancel";
            MessageDialogButtonStyle[MessageDialogButtonStyle["YesNo"] = 3] = "YesNo";
            MessageDialogButtonStyle[MessageDialogButtonStyle["YesNoCancel"] = 4] = "YesNoCancel";
        })(MessageDialogButtonStyle = UI.MessageDialogButtonStyle || (UI.MessageDialogButtonStyle = {}));
        let MessageDialogButton;
        (function (MessageDialogButton) {
            MessageDialogButton[MessageDialogButton["ok"] = 1] = "ok";
            MessageDialogButton[MessageDialogButton["cancel"] = 2] = "cancel";
            MessageDialogButton[MessageDialogButton["yes"] = 3] = "yes";
            MessageDialogButton[MessageDialogButton["no"] = 4] = "no";
        })(MessageDialogButton = UI.MessageDialogButton || (UI.MessageDialogButton = {}));
        class MessageDialogBase extends UI.Dialog {
            constructor(options, windowOptions = {}) {
                super(_.extend({
                    dialogStyle: MessageDialogStyle.Warning,
                    dialogButtons: MessageDialogButtonStyle.OK
                }, MessageDialogBase.styles[options.dialogStyle] || MessageDialogStyle.Warning, options), windowOptions);
                this.buttons = {
                    ok: { label: "OK", value: MessageDialogButton.ok },
                    cancel: { label: "Cancel", value: MessageDialogButton.cancel },
                    yes: { label: "Yes", value: MessageDialogButton.yes },
                    no: { label: "No", value: MessageDialogButton.no }
                };
                this.createButtons(options);
                this.setIcon();
                this.setFocus();
                this.buttonsNode.on("click", "button", (e) => {
                    this.select($(e.target).data("value"));
                });
            }
            get buttonsNode() {
                return this.node.find(".-jadejs-msg-dialog-buttons");
            }
            get contentNode() {
                return this.node.find(".-jadejs-msg-dialog-content");
            }
            template() {
                return `<div class='-jadejs-msg-dialog'>
                        <div class='-jadejs-msg-dialog-content' data-controls></div>
                        <div class='-jadejs-msg-dialog-buttons'></div>
                    </div>`;
            }
            createButton(buttonId) {
                if (buttonId == null) {
                    buttonId = "ok";
                }
                buttonId = buttonId.toLowerCase();
                let button = "<button></button>";
                if (buttonId in this.buttons) {
                    button = `<button data-value="${this.buttons[buttonId].value}" class="-jadejs-button">${this.buttons[buttonId].label}</button>`;
                }
                this.buttonsNode.append(button);
            }
            getWindowOptions() {
                return _.extend(super.getWindowOptions(), {
                    resizable: false,
                    width: "500px"
                });
            }
            createButtons(options) {
                this.buttonsNode.empty();
                switch (options.dialogButtons) {
                    case MessageDialogButtonStyle.OK:
                        this.createButton("ok");
                        break;
                    case MessageDialogButtonStyle.OKCancel:
                        this.createButton("ok");
                        this.createButton("cancel");
                        break;
                    case MessageDialogButtonStyle.YesNo:
                        this.createButton("yes");
                        this.createButton("no");
                        break;
                    case MessageDialogButtonStyle.YesNoCancel:
                        this.createButton("yes");
                        this.createButton("no");
                        this.createButton("cancel");
                        break;
                }
            }
            getStyle() {
                let result = null;
                let style = this.state.get("dialogStyle");
                if (style != null) {
                    result = MessageDialogBase.styles[style];
                }
                if (result == null) {
                    result = MessageDialogBase.styles[4];
                }
                return result;
            }
            setIcon() {
                var icon = this.getStyle().icon, path = null;
                if (icon != null) {
                    path = Jade.IconSet.get("jadejs").resolve(icon, Jade.IconSetSizeSpecificDirectory.x32);
                    this.contentNode.addClass("w-icon");
                    this.contentNode.css({
                        backgroundImage: "url(" + path + ")"
                    });
                }
            }
            setFocus() {
                this.buttonsNode.find("button:first").focus();
            }
            select(selectionId) {
                let callback = this.state.get("select");
                if (_.isFunction(callback)) {
                    callback({
                        close: _.bind(this.close, this),
                        button: parseInt(selectionId)
                    });
                }
            }
        }
        MessageDialogBase.styles = {
            1: { icon: "ok.png", title: "Success" },
            2: { icon: "error.png", title: "Error" },
            3: { icon: "sign_warning.png", title: "Warning" },
            4: { icon: "information.png", title: "Title" }
        };
        UI.MessageDialogBase = MessageDialogBase;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ErrorDialog extends UI.MessageDialogBase {
            constructor(options, windowOptions = {}) {
                super(options, windowOptions);
            }
            get errors() {
                return this.state.get("errors");
            }
            static open(options, windowOptions = {}) {
                return new ErrorDialog(_.extend({ title: "Application Error", dialogStyle: UI.MessageDialogStyle.Error }, options), windowOptions);
                ;
            }
            onActivate(e) {
                super.onActivate(e);
                this.controls.add(new UI.ErrorDialogContent({
                    errors: this.errors
                }));
                this.center();
            }
            getWindowOptions() {
                return _.extend(super.getWindowOptions(), {
                    resizable: false,
                    width: "500px"
                });
            }
        }
        UI.ErrorDialog = ErrorDialog;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        let NodeType;
        (function (NodeType) {
            NodeType["Error"] = "error";
            NodeType["Tag"] = "tag";
        })(NodeType || (NodeType = {}));
        class ErrorDialogContent extends Jade.UI.Control {
            constructor(options) {
                super(options);
            }
            get errors() {
                return this.state.get("errors");
            }
            get treeNode() {
                return this.node.find("div[role=tree]");
            }
            template() {
                return `<div>
                        <div style="font-family:arial;font-size:12px;font-weight:bold;height:30px;line-height:30px;">The following errors were encoutered:</div>
                        <div role="errors" style="background-color:#FFFFFF;border:1px solid #CCCCCC;padding:10px;overflow:auto;height:250px;width:100%;box-sizing:border-box;overflow-y:scroll;">
                            <div role="tree"></div>
                        </div>
                    </div>`;
            }
            onActivate(e) {
                super.onActivate(e);
                this.tree_init();
            }
            tree_init() {
                this.treeNode.kendoTreeView({
                    dataSource: {
                        data: this.tree_data()
                    },
                    encoded: false,
                    select: function (e) {
                        e.preventDefault();
                    },
                    template: function (e) {
                        var item = e.item;
                        if (item.type === "tag") {
                            return `<span style='font-weight:bold;display:inline-block;font-size:11px;padding-right:10px;'>
                                    ${item.text}:
                                </span>
                                <span style='font-size:11px;'>
                                    ${item.value != null ? item.value : ""}
                                </span>`;
                        }
                        else {
                            return item.text;
                        }
                    }
                });
            }
            tree_data() {
                let result = new Array();
                _.each(this.errors, (error) => {
                    let item = {
                        text: error.message,
                        items: [],
                        expanded: true,
                        type: NodeType.Error
                    };
                    _.forOwn(error.tags, (value, key) => {
                        item.items[item.items.length] = {
                            text: key,
                            value: value,
                            expanded: true,
                            type: NodeType.Tag
                        };
                    });
                    result[result.length] = item;
                });
                return result;
            }
        }
        UI.ErrorDialogContent = ErrorDialogContent;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class MessageDialog extends UI.MessageDialogBase {
            constructor(options, windowOptions = {}) {
                super(options, windowOptions);
                this.setMessage(this.message);
            }
            get message() {
                return this.state.get("message");
            }
            get allowClose() {
                return this.state.get("allowClose", true);
            }
            setMessage(message) {
                this.contentNode.html(message);
            }
            static open(options = {}, windowOptions = {}) {
                let result = new MessageDialog(options, windowOptions);
                return result;
            }
            getWindowOptions() {
                return _.extend(super.getWindowOptions(), {
                    actions: this.allowClose ? ["Close"] : [],
                    resizable: false,
                    width: "500px",
                    title: this.title,
                });
            }
        }
        UI.MessageDialog = MessageDialog;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class MultiMessageDialog extends UI.MessageDialogBase {
            constructor(options, windowOptions = {}) {
                super(options, windowOptions);
            }
            get messages() {
                return this.state.get("messages", []);
            }
            get header() {
                return this.state.get("header");
            }
            static open(options, windowOptions = {}) {
                return new MultiMessageDialog(_.extend({
                    title: "Application Message",
                    dialogStyle: UI.MessageDialogStyle.Information
                }, options), windowOptions);
                ;
            }
            onActivate(e) {
                super.onActivate(e);
                this.controls.add(new UI.MultiMessageDialogContent({
                    header: this.header,
                    messages: this.messages
                }));
                this.center();
                this.node.addClass(UI.CssClass.MultiMessageDialog);
            }
            getWindowOptions() {
                return _.extend(super.getWindowOptions(), {
                    resizable: false,
                    width: "500px"
                });
            }
        }
        UI.MultiMessageDialog = MultiMessageDialog;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class MultiMessageDialogContent extends Jade.UI.Control {
            constructor(options) {
                super(options);
            }
            get messages() {
                return this.state.get("messages");
            }
            get header() {
                return this.state.get("header");
            }
            get messagesNode() {
                return this.node.find("div[role=messages]");
            }
            template() {
                return `<div>
                        <div role="title" class="${UI.CssClass.MultiMessageDialogTitle}">${this.header}</div>
                        <div role="messages" class="${UI.CssClass.MultiMessageDialogContent}">
                        </div>
                    </div>`;
            }
            onActivate(e) {
                super.onActivate(e);
                let bulletIcon = Jade.IconSet.get("jadejs").resolve("bullet_dot.png", Jade.IconSetSizeSpecificDirectory.misc);
                _.each(this.messages, (message) => {
                    this.messagesNode.append(`<div class="${UI.CssClass.MultiMessageDialogContentItem}" style="background-image:url(${bulletIcon});">${message}</li>`);
                });
            }
        }
        UI.MultiMessageDialogContent = MultiMessageDialogContent;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class TaskDialog extends UI.Dialog {
            constructor(options) {
                super(options);
            }
            get notificationDialog() {
                return this.m_notificationDialog;
            }
            set notificationDialog(value) {
                this.m_notificationDialog = value;
            }
            get notificationDialogTypes() {
                return this.m_notificationDialogTypes;
            }
            set notificationDialogTypes(value) {
                this.m_notificationDialogTypes = value;
            }
            get btnClose() {
                return this.node.find(".-jadejs-task-status-btn-close");
            }
            get btnCancel() {
                return this.node.find(".-jadejs-task-status-btn-cancel");
            }
            get btnDetail() {
                return this.node.find(".-jadejs-task-status-btn-detail");
            }
            get label() {
                return this.node.find(".-jadejs-task-status-label");
            }
            get progress() {
                return this.node.find(".-jadejs-task-status-progress");
            }
            get progressBar() {
                return this.node.find(".-jadejs-task-status-progress-bar");
            }
            get detail() {
                return this.node.find(".-jadejs-task-status-detail");
            }
            get btnDetailLabel() {
                return this.node.find(".-jadejs-task-status-deck > DIV > SPAN");
            }
            closeButton_onClick(e) {
                this.close(this.getTaskEventArgs());
            }
            cancelButton_onClick(e) {
                this.close(this.getTaskEventArgs());
            }
            detailButton_onClick(e) {
                let isDetailDisplayed = this.detail.css("display") !== "none";
                if (isDetailDisplayed) {
                    this.hideDetail();
                }
                else {
                    this.showDetail();
                }
                this.m_status = e;
                this.updateStatus(e);
            }
            poll_onSuccess(e) {
                this.m_status = e;
                this.updateStatus(e);
            }
            poll_onError(e) {
                let message = "";
                try {
                    message = JSON.parse(e.responseText).message;
                }
                catch (ex) {
                    message = "Fatal Error.";
                }
                this.fatalError(message);
            }
            onActivate(e) {
                this.btnClose.on("click", $.proxy(this.closeButton_onClick, this));
                this.btnCancel.on("click", $.proxy(this.cancelButton_onClick, this));
                this.btnDetail.parent().on("click", $.proxy(this.detailButton_onClick, this));
                this.enableClose(this.state.get("enableClose", false));
                this.window.setOptions({
                    actions: []
                });
            }
            onComplete(e) {
                let showDetail = this.state.get("showDetail", false);
                let allowClose = this.state.get("allowClose", false);
                this.addLabelMessage("Preparing task...");
                this.addDetailMessage(0, "Preparing task...");
                if (allowClose) {
                    this.btnClose.show();
                }
                if (showDetail) {
                    this.showDetail();
                }
                setTimeout(() => {
                    this.start();
                }, 2000);
            }
            template() {
                return [
                    "<div class='-jadejs-task-status'>",
                    "<label class='-jadejs-task-status-label'></label>",
                    "<div class='-jadejs-task-status-progress'>",
                    "<div class='-jadejs-task-status-progress-bar'>",
                    "</div>",
                    "</div>",
                    "<div class='-jadejs-task-status-detail' style='display:none;'></div>",
                    "<div class='-jadejs-task-status-deck'>",
                    "<div>",
                    "<button class='-jadejs-task-status-btn-detail' style=''>",
                    "<img src='" + Jade.Path.resolveImage("navigate_down.png", "16x16") + "'/>",
                    "</button>",
                    "<span>More Detail</span>",
                    "</div>",
                    "<button class='-jadejs-button -jadejs-task-status-btn-close' style='display:none;'>Close</button>",
                    "<button class='-jadejs-button -jadejs-task-status-btn-cancel' style='display:none;'>Cancel</button>",
                    "</div>",
                    "</div>"
                ];
            }
            close(options) {
                super.close(options);
                let callback = this.state.get("close", () => { });
                if (_.isFunction(callback)) {
                    callback(options);
                }
            }
            getWindowOptions() {
                super.getWindowOptions();
                let result = {
                    resizable: false,
                    height: 300,
                    width: 400
                };
                return result;
            }
            start() {
                let args = this.getTaskEventArgs();
                let taskCancelFn = this.state.get("taskCancel");
                let taskStartFn = this.state.get("taskStart");
                if (!_.isFunction(taskStartFn)) {
                    this.fatalError("No task start was provided.");
                    return;
                }
                if (_.isFunction(taskCancelFn)) {
                    this.btnCancel.show();
                }
                taskStartFn(args);
            }
            pollStatus(taskId) {
                let pollUrl = this.state.get("pollUrl");
                if (!pollUrl) {
                    this.fatalError("Unable to poll task.");
                    return;
                }
                pollUrl += (taskId != null ? "/" + taskId : "");
                $.ajax({
                    type: "GET",
                    url: Jade.Path.resolve(pollUrl),
                    success: (e) => {
                        if (taskId != null) {
                            e.taskId = taskId;
                        }
                        this.poll_onSuccess(e);
                    },
                    error: (e) => {
                        this.poll_onError(e);
                    }
                });
            }
            updateStatus(status) {
                this.addLabelMessage(status.lastAction);
                this.addDetailMessages(status.messages);
                this.setProgressBar(status.percentComplete);
                this.scrollDetailToBottom();
                this.handleNotification(status);
                if (status.complete) {
                    this.complete();
                }
                else {
                    setTimeout(() => {
                        this.pollStatus(status.taskId);
                    }, this.state.get("pollFrequency", 1000));
                }
            }
            alert(e) {
                let taskAlertEventArgs = this.getTaskEventArgs();
                let taskAlertFn = this.state.get("taskAlert");
                taskAlertEventArgs.timeout = function () { };
                if (_.isFunction(taskAlertFn)) {
                    taskAlertFn(taskAlertEventArgs);
                }
            }
            scrollDetailToBottom() {
                this.btnDetail[0].scrollTop = this.btnDetail[0].scrollHeight;
            }
            showDetail() {
                this.detail.show();
                this.btnDetail.find("IMG").prop("src", Jade.Path.resolveImage("navigate_up.png", "16x16"));
                this.btnDetail.css({ paddingTop: 1 });
                this.setDimensions(300, 400);
                this.btnDetailLabel.text("Less Detail");
                this.scrollDetailToBottom();
            }
            hideDetail() {
                this.detail.hide();
                this.btnDetail.find("IMG").prop("src", Jade.Path.resolveImage("navigate_down.png", "16x16"));
                this.setDimensions(110, 400);
                this.btnDetailLabel.text("More Detail");
            }
            addLabelMessage(message) {
                if (message != null) {
                    this.label.empty();
                    this.label.prop("title", message);
                    this.label.append("<span>" + message + "</span>");
                }
            }
            addDetailMessages(messages, indent = 0) {
                if (_.isArray(messages)) {
                    if (messages.length > 0) {
                        _.each(messages, (item) => {
                            this.addDetailMessage(item.level, item.message, indent);
                            if (_.isArray(item.subMessages)) {
                                this.addDetailMessages(item.subMessages, indent + 15);
                            }
                        });
                    }
                }
            }
            addDetailMessage(type, message, indent = 0) {
                var cssClass = "", marginSpacing = (indent > 0 ? 10 : 0);
                indent = indent == null ? 0 : indent;
                switch (type) {
                    case 1:
                        cssClass = "warning";
                        break;
                    case 2:
                        cssClass = "error";
                        break;
                }
                this.detail.append("<div class='" + cssClass + "' style='margin:" + marginSpacing + "px 0 " + marginSpacing + "px " + indent + "px;'>" + (message != null ? message : "") + "</div>");
            }
            complete() {
                let taskSuccessEventArgs = this.getTaskEventArgs();
                let taskSuccessFn = this.state.get("taskSuccess");
                this.label.addClass("success");
                this.setProgressBar(100, false);
                this.btnClose.focus();
                if (_.isFunction(taskSuccessFn)) {
                    _.bind(taskSuccessFn, this)(taskSuccessEventArgs);
                }
            }
            fatalError(message) {
                message = message || "Task was unexpectedly aborted.";
                this.addLabelMessage(message);
                this.addDetailMessage(2, message);
                this.addDetailMessage(0, "Task Aborted.");
                this.label.addClass("error");
            }
            setProgressBar(percentComplete, isError = false) {
                if (isError != null) {
                    if (isError) {
                        this.progressBar.addClass("error");
                    }
                    else {
                        this.progressBar.removeClass("error");
                    }
                }
                this.progressBar.css({
                    width: (percentComplete != null ? percentComplete : 0) + "%"
                });
            }
            enableClose(value) {
                this.btnClose.prop("disabled", !value);
                this.btnClose.focus();
            }
            getTaskEventArgs() {
                return {
                    startPolling: (e) => {
                        this.registerTaskNotificationDialogTypes(e.alerts);
                        this.pollStatus(e.taskId);
                    },
                    abort: (message) => {
                        this.fatalError(message);
                    },
                    complete: (message) => {
                        if (message != null) {
                            this.addDetailMessage(0, message);
                        }
                        this.complete();
                    },
                    enableClose: (value) => {
                        this.enableClose(value);
                    },
                    taskStatus: this.m_status
                };
            }
            registerTaskNotificationDialogTypes(types) {
                this.notificationDialogTypes = {};
                _.each(types, (value, key) => {
                    var type = Jade.Type.getType(value);
                    if (type != null) {
                        this.notificationDialogTypes[key] = type;
                    }
                });
            }
            showNotificationDialog(taskId, alert) {
                var notificationDialogType = this.notificationDialogTypes[alert.code];
                if (notificationDialogType != null) {
                    this.notificationDialog = new notificationDialogType({
                        alert: alert,
                        callbacks: {
                            ok: (sender, e) => {
                                this.sendNotificationResponse(taskId, e);
                                this.notificationDialog = null;
                            }
                        }
                    });
                }
            }
            sendNotificationResponse(taskId, tags) {
                let url = this.state.get("notificationResponseUrl");
                Jade.Ajax.call({
                    type: "POST",
                    data: {
                        url: Jade.Path.resolve(url),
                        reply: JSON.stringify({
                            taskId: taskId,
                            tags: tags
                        })
                    }
                });
            }
            handleNotification(status) {
                var isTaskAlerting = status.alert != null, isDialogAlerting = this.notificationDialog != null;
                if (!isTaskAlerting && isDialogAlerting) {
                    this.notificationDialog.close();
                    this.notificationDialog = null;
                }
                else if (isTaskAlerting && !isDialogAlerting) {
                    this.showNotificationDialog(status.taskId, status.alert);
                }
            }
        }
        UI.TaskDialog = TaskDialog;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ToolBar extends UI.Control {
            constructor(options) {
                super(options);
            }
            get segments() {
                return this.m_segments;
            }
            get items() {
                return this.m_items;
            }
            get instance() {
                return this.m_instance;
            }
            onInit(e) {
                this.m_items = new UI.ToolBarItemCollection();
                this.m_segments = new Jade.ObservableCollection([], {
                    onAfterAdd: (e) => {
                        this.controls.clear();
                        if (this.controls.controlEvents.hasEventFired(UI.ControlEvent.onTemplate)) {
                        }
                        this.segments.each((segment) => {
                            if (segment.meetsLoadConditions(e)) {
                            }
                        });
                    },
                    onAfterRemove: () => { }
                });
            }
            onTemplate(e) {
                super.onTemplate(e);
                this.addSegments(e);
                this.addItems(e);
            }
            onActivate(e) {
                var items = this.items.transform((item) => {
                    item.toolbar = this;
                    return item.toJSON();
                });
                this.m_instance = this.node.kendoToolBar({
                    items: items,
                    click: (e) => {
                        this.onClick(e);
                    },
                    toggle: (e) => {
                        this.onClick(e);
                    }
                }).data("kendoToolBar");
                this.items.each((item) => {
                    if (_.isFunction(item.activate)) {
                        item.activate();
                    }
                });
            }
            onToggle(e) {
                let id = $(e.target).data("id");
                this.onToggleOrClick(id);
            }
            onClick(e) {
                let id = $(e.target).data("id");
                this.onToggleOrClick(id);
            }
            onToggleOrClick(id) {
                let target = null;
                this.iterateItems(this.items, (item) => {
                    if (item.ID === id) {
                        target = item;
                        return false;
                    }
                    ;
                });
                if (target) {
                    this.segments.each((segment) => {
                        segment.click(new UI.ToolBarItemOnClickEventArgs({
                            toolBar: this,
                            item: target
                        }));
                    });
                }
            }
            template() {
                return "<div class='-jadejs-toolbar " + this.state.get("cssClass", "-jadejs-primary-toolbar") + "'></div>";
            }
            addSegments(e) {
                let pendingSegments = this.state.get("segments", []);
                if (!_.isArray(pendingSegments)) {
                    pendingSegments = [pendingSegments];
                }
                _.each(pendingSegments, (segment) => {
                    if (segment.meetsLoadConditions(e)) {
                        this.segments.add(segment);
                    }
                });
            }
            addItems(e) {
                this.segments.each((segment) => {
                    segment.onAddItems(new UI.ToolbarOnAddItemsEventArgs({
                        toolBar: this,
                        items: this.items,
                        segment: segment
                    }));
                });
            }
            iterateItems(items, callback) {
                items.each((item) => {
                    var abort = false;
                    if (_.isFunction(callback)) {
                        abort = callback(item) === false;
                    }
                    return !abort;
                });
            }
        }
        UI.ToolBar = ToolBar;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ToolBarItem {
            constructor(options = {}) {
                this.m_state = new Jade.StateBag(options);
                this.onInit();
                this.onLoad();
            }
            onInit(e = {}) {
                this.state.set({
                    id: UUID.genV4().toString()
                });
                this.state.set(this.setDefaultOptions());
            }
            onLoad(e = {}) {
            }
            onActivate(e = {}) {
            }
            onComplete(e = {}) {
            }
            onClick(e) {
            }
            get ID() {
                return this.state.get("id");
            }
            get state() {
                return this.m_state;
            }
            get toolbar() {
                return this.m_toolBar;
            }
            set toolbar(value) {
                if (this.m_toolBar == null) {
                    this.m_toolBar = value;
                }
            }
            get node() {
                return this.toolbar.instance.element.find("[data-id='" + this.ID + "']");
            }
            click(e) {
                this.onClick(e);
            }
            toJSON() {
                return this.state.toJSON();
            }
            activate(e = {}) {
                this.onActivate(e);
            }
            refresh(e) {
                let refresh = this.state.get("refresh");
                if (!_.isFunction(refresh)) {
                    return;
                }
                refresh(new UI.ToolbarOnRefreshEventArgs({
                    item: this,
                    node: this.node,
                    context: null,
                    toolbar: this.toolbar
                }));
            }
            setDefaultOptions() {
            }
        }
        UI.ToolBarItem = ToolBarItem;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ToolBarItemCollection extends Jade.Collection {
        }
        UI.ToolBarItemCollection = ToolBarItemCollection;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ToolBarItemOnClickEventArgs {
            constructor(options) {
                this.m_toolBar = options.toolBar;
                this.m_item = options.item;
            }
            get toolBar() {
                return this.m_toolBar;
            }
            get item() {
                return this.m_item;
            }
        }
        UI.ToolBarItemOnClickEventArgs = ToolBarItemOnClickEventArgs;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ToolBarItemOnCommandChangeEventArgs {
            constructor(options) {
                this.m_toolbar = options.toolbar;
                this.m_node = options.node;
                this.m_command = options.command;
                this.m_context = options.context;
            }
            get toolbar() {
                return this.m_toolbar;
            }
            get node() {
                return this.m_node;
            }
            get command() {
                return this.m_command;
            }
            get context() {
                return this.m_context;
            }
        }
        UI.ToolBarItemOnCommandChangeEventArgs = ToolBarItemOnCommandChangeEventArgs;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ToolbarOnRefreshEventArgs {
            constructor(options) {
                this.m_toolbar = options.toolbar;
                this.m_item = options.item;
                this.m_node = options.node;
                this.m_context = options.context;
            }
            get item() {
                return this.m_item;
            }
            get toolbar() {
                return this.m_toolbar;
            }
            get context() {
                return this.m_context;
            }
            get node() {
                return this.m_node;
            }
            enabled(value) {
                this.toolbar.instance.enable(this.node, value);
            }
            visible(value) {
                if (!value) {
                    this.toolbar.instance.remove(this.node);
                }
            }
        }
        UI.ToolbarOnRefreshEventArgs = ToolbarOnRefreshEventArgs;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ToolBarSegment {
            constructor(context) {
                this.m_items = new UI.ToolBarItemCollection();
                this.m_oldContext = context || {};
            }
            get oldContext() {
                return this.m_newContext;
            }
            get context() {
                return this.m_newContext;
            }
            get items() {
                return this.m_items;
            }
            onAddItems(e) {
            }
            onRefresh(e) {
            }
            onClick(e) {
            }
            meetsLoadConditions(e) {
                return true;
            }
            refresh(e) {
                this.onRefresh(e);
            }
            click(e) {
                this.onClick(e);
                e.item.click(e);
            }
        }
        UI.ToolBarSegment = ToolBarSegment;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ToolbarOnAddItemsEventArgs {
            constructor(options) {
                this.m_toolBar = options.toolBar;
                this.m_items = options.items;
                this.m_segment = options.segment;
            }
            get toolBar() {
                return this.m_toolBar;
            }
            get items() {
                return this.m_items;
            }
            get segment() {
                return this.m_segment;
            }
            registerItem(item) {
                this.segment.items.add(item);
                this.items.add(item);
            }
        }
        UI.ToolbarOnAddItemsEventArgs = ToolbarOnAddItemsEventArgs;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ToolBarItemCommand extends UI.ToolBarItem {
            constructor(options) {
                super(options);
                this.m_label = null;
                this.m_icon = null;
                this.m_tooltip = null;
                this.m_visible = null;
                this.m_enabled = null;
                this.m_value = null;
                this.m_label = options.label;
                this.m_icon = options.icon;
                this.m_tooltip = options.tooltip;
                this.m_visible = options.visible;
                this.m_enabled = options.enabled;
                this.m_value = options.value;
            }
            get commandId() {
                return this.state.get("commandId", null);
            }
            get commandSubscriber() {
                return this.state.get("$commandSubscriber", null);
            }
            set commandSubscriber(value) {
                this.state.set("$commandSubscriber", value);
            }
            get label() {
                return this.getValue("label", "Label");
            }
            get icon() {
                let result = this.getValue("icon", null);
                if (this.commandSubscriber != null) {
                    result = this.commandSubscriber.command.getIcon(Jade.IconSetSizeSpecificDirectory.x16, result);
                }
                return result;
            }
            get display() {
                return this.getValue("display", "");
            }
            get enabled() {
                return this.getValue("enabled", true);
            }
            get tooltip() {
                return this.getValue("tooltip", "");
            }
            get visible() {
                return this.getValue("visible", true);
            }
            get value() {
                return this.getValue("value", null);
            }
            onInit(e) {
                if (this.commandId != null) {
                    this.commandSubscriber = new Jade.CommandSubscriber();
                    this.commandSubscriber.subscribe(this.commandId, () => {
                        this.onPropertiesChanged();
                    });
                }
                super.onInit(e);
            }
            toJSON() {
                return this.state.toJSON();
            }
            click(e) {
                if (this.commandSubscriber != null) {
                    this.commandSubscriber.execute(this.value);
                }
            }
            refresh() {
                if (this.commandSubscriber != null) {
                    this.onPropertiesChanged();
                }
            }
            template() {
                return "";
            }
            onPropertiesChanged() {
                let toolbar = this.toolbar.node.data("kendoToolBar");
                if (toolbar != null || this.node != null) {
                    return;
                }
                toolbar.enable(this.node, this.enabled);
                if (this.visible) {
                    this.node.removeClass("k-state-hidden");
                }
                else {
                    this.node.addClass("k-state-hidden");
                }
            }
            getValue(id, defaultValue) {
                let result = null;
                if (this["m_" + id] != null) {
                    result = this["m_" + id];
                }
                else if (this.commandSubscriber != null) {
                    result = this.commandSubscriber[id];
                }
                else {
                    result = this.state.get(id);
                }
                if (result == null) {
                    result = defaultValue;
                }
                return result;
            }
        }
        UI.ToolBarItemCommand = ToolBarItemCommand;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        class ToolBarButtonCommand extends UI.ToolBarItemCommand {
            constructor(options) {
                super(options);
            }
            get command() {
                var _a;
                return (_a = this.commandSubscriber) === null || _a === void 0 ? void 0 : _a.command;
            }
            onActivate(e) {
                super.onActivate(e);
                if (this.commandId != null) {
                    this.onPropertiesChanged();
                }
            }
            onPropertiesChanged() {
                super.onPropertiesChanged();
                let content = this.template();
                this.toolbar.instance.enable(this.node, this.commandSubscriber.command.enabled);
                if (this.visible) {
                    this.node.removeClass("k-state-hidden");
                }
                else {
                    this.node.addClass("k-state-hidden");
                }
                this.node.prop("title", this.tooltip);
                this.node.empty();
                this.node.addClass("k-button-icontext");
                this.node.html(content);
            }
            toJSON() {
                let result = this.state.toJSON();
                result = {
                    type: "button",
                    id: this.ID,
                    enable: this.enabled,
                    imageUrl: this.icon,
                    overflow: "auto",
                    text: this.label,
                    display: this.display,
                    attributes: {
                        "data-id": this.ID,
                        "title": this.tooltip,
                        "class": this.getCssClass()
                    }
                };
                return result;
            }
            template(e = null) {
                let command = this.commandSubscriber.command;
                let showLabel = this.showLabel();
                let showIcon = this.showIcon();
                let result = [
                    showIcon ? "<img src='" + this.icon + "' class='k-image'/>" : "",
                    showLabel ? command.label : "&nbsp;"
                ];
                return result.join("");
            }
            showIcon() {
                let icon = this.icon;
                let display = this.display;
                return icon != null
                    && icon != ""
                    && (display == null || (display != null && display.indexOf("icon") != -1));
            }
            showLabel() {
                let label = this.label;
                let display = this.display;
                return label != null
                    && label != ""
                    && (display == null || (display != null && display.indexOf("label") != -1));
            }
            getCssClass() {
                var result = undefined;
                if (!this.showLabel()) {
                    result = "-jadejs-btn-no-text";
                }
                return result;
            }
        }
        UI.ToolBarButtonCommand = ToolBarButtonCommand;
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class ContextMenu extends UI.Control {
                constructor(options) {
                    super(options);
                    this.m_parent = null;
                    this.m_visible = false;
                    this.m_x = 0;
                    this.m_y = 0;
                    this.m_items = new Jade.MappedCollection({ key: "ID" });
                    this.m_groups = new Jade.MappedCollection({ key: "ID" });
                }
                get items() {
                    return this.m_items;
                }
                get groups() {
                    return this.m_groups;
                }
                get attachTo() {
                    return this.state.get("attachTo", $("body"));
                }
                get parent() {
                    return this.m_parent;
                }
                get x() {
                    return this.m_x;
                }
                get y() {
                    return this.m_y;
                }
                get visible() {
                    return this.m_visible;
                }
                onTemplate(e) {
                    this.node.on("click", ".-jadejs-contextmenu-item", (e) => {
                        let onClick = this.state.get("onClick");
                        let item = this.controls.getById($(e.target).attr("id"));
                        if (item != null && item.enabled) {
                            item.click(e);
                            if (item.closeOnClick) {
                                if (this.parent != null) {
                                    this.parent.hide();
                                }
                                this.hide();
                            }
                            if (_.isFunction(onClick)) {
                                onClick(item);
                            }
                        }
                    });
                    $(document).on("mousedown", "DIV:not(.-jadejs-contextmenu,.-jadejs-contextmenu-item)", (e) => {
                        if ($(e.target).closest(".-jadejs-contextmenu").length == 0) {
                            this.hide();
                        }
                    });
                    this.node.on("contextmenu", (e) => { return false; });
                }
                template() {
                    return `<div class="-jadejs-contextmenu" style="top:400px;left:400px;display:none;"></div>`;
                }
                show(e) {
                    this.m_parent = e.parent;
                    this.m_visible = true;
                    this.m_x = e.x;
                    this.m_y = e.y;
                    this.showGroups(e.groups);
                    let position = this.getPosition();
                    this.node.css({
                        top: position.y,
                        left: position.x,
                        zIndex: "100000",
                        display: "inline-block"
                    });
                    this.node.stop(true, true);
                    this.node.fadeIn(200);
                }
                hide() {
                    let onHide = this.state.get("onHide");
                    this.m_parent = null;
                    this.m_visible = false;
                    this.m_x = 0;
                    this.m_y = 0;
                    this.node.stop(true, true);
                    this.node.fadeOut(200);
                    if (_.isFunction(onHide)) {
                        onHide();
                    }
                }
                getPosition() {
                    let height = this.node.outerHeight(false);
                    let width = this.node.outerWidth(false);
                    let offsetTop = this.container.offset().top;
                    let offsetLeft = this.container.offset().left;
                    let offsetBottom = offsetTop + this.container.outerHeight(true);
                    let offsetRight = offsetLeft + this.container.outerWidth(true);
                    let top = this.y - offsetTop;
                    let left = this.x - offsetLeft;
                    if (this.y + height > offsetBottom) {
                        top = top - ((this.y - offsetBottom) + height);
                    }
                    if (this.x + width > offsetRight) {
                        left = left - ((this.x - offsetRight) + width);
                    }
                    return { x: left - 8, y: top - 8 };
                }
                showGroups(groupIds) {
                    this.groups.each((group) => {
                        group.hide(this);
                    });
                    _.each(groupIds, (groupId) => {
                        let group = null;
                        if (this.groups.get(groupId) == null) {
                            group = Controls.ContextMenuGroups.get(groupId);
                            if (group != null) {
                                this.groups.add(group);
                            }
                        }
                    });
                    this.groups.each((group) => {
                        if (_.indexOf(groupIds, group.ID) > -1) {
                            group.show(this);
                        }
                    });
                }
            }
            Controls.ContextMenu = ContextMenu;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class ContextMenuItemBase extends UI.Control {
                constructor() {
                    super(...arguments);
                    this.m_parent = null;
                }
                get parent() {
                    return this.m_parent;
                }
                set parent(value) {
                    this.m_parent = value;
                }
                template() {
                    return `<div></div>`;
                }
                click(e) {
                }
                refresh() {
                }
            }
            Controls.ContextMenuItemBase = ContextMenuItemBase;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class ContextMenuDivider extends Controls.ContextMenuItemBase {
                constructor() {
                    super({});
                }
                template() {
                    return `<div class="-jadejs-contextmenu-divider"><div></div></div>`;
                }
            }
            Controls.ContextMenuDivider = ContextMenuDivider;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class ContextMenuGroup {
                constructor(options) {
                    this.m_items = new Jade.Collection();
                    this.m_id = options.id;
                    this.onPopulate();
                }
                get ID() {
                    return this.m_id;
                }
                get items() {
                    return this.m_items;
                }
                hide(contextMenu) {
                    this.items.each((item) => {
                        contextMenu.controls.detach(item);
                        item.parent = null;
                    });
                }
                show(contextMenu) {
                    if (this.meetsLoadConditions()) {
                        this.items.each((item) => {
                            contextMenu.controls.add(item);
                            item.refresh();
                            item.parent = contextMenu;
                        });
                    }
                }
                onPopulate() {
                }
                meetsLoadConditions() {
                    return true;
                }
            }
            Controls.ContextMenuGroup = ContextMenuGroup;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class ContextMenuGroups {
                static get groups() {
                    return this.m_groups;
                }
                static add(group) {
                    this.groups.add(group);
                }
                static remove(groupId) {
                    let group = this.groups.get(groupId);
                    if (group != null) {
                        this.groups.remove(group);
                    }
                }
                static get(groupId) {
                    return this.groups.get(groupId);
                }
                static clear() {
                    this.m_groups = new Jade.MappedCollection({ key: "ID" });
                }
                static reset() {
                    let groups = new Array();
                    this.groups.each((group) => {
                        let instance = new group.constructor({
                            id: group.ID
                        });
                        groups[groups.length] = instance;
                    });
                    this.clear();
                    _.each(groups, (group) => {
                        this.add(group);
                    });
                }
            }
            ContextMenuGroups.m_groups = new Jade.MappedCollection({ key: "ID" });
            Controls.ContextMenuGroups = ContextMenuGroups;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class ContextMenuItem extends Controls.ContextMenuItemBase {
                constructor(options) {
                    super(options);
                    this.m_commandSubscriber = null;
                    this.m_label = null;
                    this.m_icon = null;
                    this.m_tooltip = null;
                    this.m_visible = null;
                    this.m_enabled = null;
                    this.m_value = null;
                    this.m_label = options.label;
                    this.m_icon = options.icon;
                    this.m_tooltip = options.tooltip;
                    this.m_visible = options.visible;
                    this.m_enabled = options.enabled;
                    this.m_value = options.value;
                }
                get label() {
                    return this.getValue("label", "Label");
                }
                get icon() {
                    let result = this.getValue("icon", null);
                    if (this.commandSubscriber != null) {
                        result = this.commandSubscriber.command.getIcon(Jade.IconSetSizeSpecificDirectory.x16, result);
                    }
                    return result;
                }
                get enabled() {
                    return this.getValue("enabled", true);
                }
                get tooltip() {
                    return this.getValue("tooltip", "");
                }
                get visible() {
                    return this.getValue("visible", true);
                }
                get value() {
                    return this.getValue("value", null);
                }
                get closeOnClick() {
                    return this.getValue("closeOnClick", true);
                }
                get commandSubscriber() {
                    return this.m_commandSubscriber;
                }
                template() {
                    return `<div class="-jadejs-contextmenu-item">${this.label}</div>`;
                }
                click(e) {
                    if (this.m_commandSubscriber != null) {
                        this.m_commandSubscriber.execute(this.value);
                    }
                }
                refresh() {
                    if (this.commandSubscriber != null) {
                        this.onPropertiesChanged();
                    }
                }
                onTemplateStart(e) {
                    if (this.state.get("commandId") != null) {
                        this.m_commandSubscriber = new Jade.CommandSubscriber();
                        this.m_commandSubscriber.subscribe(this.state.get("commandId"), () => {
                            this.onPropertiesChanged();
                        });
                    }
                }
                onTemplateComplete(e) {
                    if (this.state.get("commandId") != null) {
                        this.onPropertiesChanged();
                    }
                }
                onPropertiesChanged() {
                    if (this.enabled) {
                        this.node.removeAttr("disabled");
                    }
                    else {
                        this.node.attr("disabled", "");
                    }
                    if (this.m_commandSubscriber.display.indexOf("icon") > -1) {
                        if (this.icon != null) {
                            this.node.css({
                                backgroundImage: `url(${this.icon})`
                            });
                        }
                    }
                    this.node.text(this.label);
                }
                onStateChanged() {
                    if (this.enabled) {
                        this.node.removeAttr("disabled");
                    }
                    else {
                        this.node.attr("disabled", "");
                    }
                }
                getValue(id, defaultValue) {
                    let result = null;
                    if (this["m_" + id] != null) {
                        result = this["m_" + id];
                    }
                    else if (this.m_commandSubscriber != null) {
                        result = this.m_commandSubscriber[id];
                    }
                    else {
                        result = this.state.get(id);
                    }
                    if (result == null) {
                        result = defaultValue;
                    }
                    return result;
                }
            }
            Controls.ContextMenuItem = ContextMenuItem;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class ContextMenuItemTemplate extends Controls.ContextMenuItem {
                onPropertiesChanged() {
                    if (this.enabled) {
                        this.node.removeAttr("disabled");
                    }
                    else {
                        this.node.attr("disabled", "");
                    }
                    if (this.commandSubscriber.display.indexOf("icon") > -1) {
                        if (this.icon != null) {
                            this.node.css({
                                backgroundImage: `url(${this.icon})`
                            });
                        }
                    }
                }
            }
            Controls.ContextMenuItemTemplate = ContextMenuItemTemplate;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class ContextMenuItemColorPalette extends Controls.ContextMenuItemTemplate {
                constructor(options) {
                    super(options);
                    this.m_palette = null;
                }
                get palette() {
                    return this.m_palette;
                }
                template() {
                    return `<div class="-jadejs-contextmenu-item-color-palette-large"><div role="palette"></div></div>`;
                }
                click(e) {
                    if (this.commandSubscriber != null) {
                        this.commandSubscriber.execute({ color: this.palette.value() });
                    }
                }
                onActivate(e) {
                    this.node.find("div[role=palette]").kendoColorPalette({
                        palette: this.state.get("palette", []),
                        columns: 10,
                        change: (e) => {
                            this.onColorSelect(e.sender.value());
                            if (this.closeOnClick) {
                                this.parent.hide();
                            }
                        }
                    });
                }
                onColorSelect(color) {
                    if (this.commandSubscriber != null) {
                        this.commandSubscriber.execute(color);
                    }
                }
            }
            Controls.ContextMenuItemColorPalette = ContextMenuItemColorPalette;
            class ContextMenuItemColorPalettes {
                static get standardColors() {
                    return ["#000000", "#7f7f7f", "#880015", "#ed1c24", "#ff7f27", "#fff200", "#22b14c", "#00a2e8", "#3f48cc", "#a349a4"];
                }
                static get themeColors() {
                    return [
                        "#ffffff", "#000000", "#e7e6e6", "#44546a", "#4472c4", "#ed7d31", "#a5a5a5", "#ffc000", "#5b9bd5", "#70ad47",
                        "#f2f2f2", "#7f7f7f", "#d0cece", "#d6dce4", "#d9e2f3", "#fbe5d5", "#ededed", "#fff2cc", "#deebf6", "#e2efd9",
                        "#d8d8d8", "#595959", "#aeabab", "#adb9ca", "#b4c6e7", "#f7cbac", "#dbdbdb", "#fee599", "#bdd7ee", "#c5e0b3",
                        "#bfbfbf", "#3f3f3f", "#757070", "#8496b0", "#8eaadb", "#f4b183", "#c9c9c9", "#ffd965", "#9cc3e5", "#a8d08d",
                        "#a5a5a5", "#262626", "#3a3838", "#323f4f", "#2f5496", "#c55a11", "#7b7b7b", "#bf9000", "#2e75b5", "#538135",
                        "#7f7f7f", "#0c0c0c", "#171616", "#222a35", "#1f3864", "#833c0b", "#525252", "#7f6000", "#1e4e79", "#375623"
                    ];
                }
            }
            Controls.ContextMenuItemColorPalettes = ContextMenuItemColorPalettes;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class ContextMenuItemHeader extends Controls.ContextMenuItemBase {
                constructor(options) {
                    super(options);
                    this.m_commandSubscriber = null;
                }
                get label() {
                    return this.state.get("label", "Label");
                }
                template() {
                    return `<div class="-jadejs-contextmenu-item-header">${this.label}</div>`;
                }
            }
            Controls.ContextMenuItemHeader = ContextMenuItemHeader;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class ContextMenuItemSubMenu extends Controls.ContextMenuItem {
                constructor(options) {
                    super(options);
                    this.m_mouseIsOverContextMenu = false;
                    this.m_mouseIsOverItem = false;
                    this.m_contextMenu = null;
                    this.m_hasMouseHandlers = false;
                }
                get contextMenu() {
                    return this.m_contextMenu;
                }
                set contextMenu(value) {
                    this.m_contextMenu = value;
                }
                get menu() {
                    return this.state.get("menu", []);
                }
                get closeOnClick() {
                    return false;
                }
                template() {
                    return `<div class="-jadejs-contextmenu-item -jadejs-contextmenu-item-submenu">${this.label}</div>`;
                }
                click(e) {
                }
                onActivate(e) {
                    this.node.on("mouseenter", (e) => {
                        this.m_mouseIsOverItem = true;
                        this.createContextMenu();
                        setTimeout(() => {
                            if (this.m_mouseIsOverItem) {
                                this.onMouseEnter(e);
                            }
                        }, 250);
                    });
                    this.node.on("mouseleave", (e) => {
                        this.m_mouseIsOverItem = false;
                        setTimeout(() => {
                            if (!this.m_mouseIsOverContextMenu) {
                                this.contextMenu.hide();
                            }
                        }, 10);
                    });
                    this.node.css({
                        backgroundImage: `url(${Jade.IconSet.get("jadejs").resolve("context-menu-arrow.png", Jade.IconSetSizeSpecificDirectory.misc)}`
                    });
                }
                onMouseEnter(e) {
                    if (this.contextMenu != null) {
                        this.contextMenu.show({
                            groups: this.menu,
                            x: this.node.offset().left + this.node.outerWidth() + 4,
                            y: this.node.offset().top + 4,
                            parent: this.parent
                        });
                        if (!this.m_hasMouseHandlers) {
                            this.contextMenu.node.on("mouseenter", (e) => {
                                this.contextMenu_onMouseEnter(e);
                            });
                            this.contextMenu.node.on("mouseleave", (e) => {
                                this.contextMenu_onMouseLeave(e);
                            });
                            this.m_hasMouseHandlers = true;
                        }
                        return;
                    }
                }
                contextMenu_onMouseEnter(e) {
                    this.m_mouseIsOverContextMenu = true;
                }
                contextMenu_onMouseLeave(e) {
                    this.contextMenu.hide();
                    this.m_mouseIsOverContextMenu = false;
                }
                createContextMenu() {
                    if (this.menu.length > 0) {
                        if (this.contextMenu == null) {
                            this.contextMenu = new Controls.ContextMenu({
                                container: "BODY",
                                onClick: () => {
                                }
                            });
                        }
                    }
                }
            }
            Controls.ContextMenuItemSubMenu = ContextMenuItemSubMenu;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class RibbonBar extends UI.Control {
                constructor() {
                    super(...arguments);
                    this.m_selectedSectionId = null;
                    this.m_tabStrip = new Controls.RibbonBarTabStrip({
                        insertAt: "DIV[role=tabs]"
                    });
                    this.m_sections = null;
                }
                get tabStrip() {
                    return this.m_tabStrip;
                }
                get sections() {
                    return this.m_sections;
                }
                get selectedSectionId() {
                    return this.m_selectedSectionId;
                }
                onInit(e) {
                    this.m_sections = new Jade.MappedCollection({ key: "ID" });
                }
                onActivate(e) {
                    this.controls.add(this.tabStrip);
                    this.node.on("click", ".-jadejs-ribbonbar-tab", $.proxy(this.onTabClick, this));
                    Controls.RibbonBarSections.sections.each((section) => {
                        this.sections.add(section);
                    });
                }
                onTabClick(e) {
                    this.node.find(".-jadejs-ribbonbar-tab.selected").removeClass("selected");
                    let target = $(e.target);
                    target.addClass("selected");
                    this.m_selectedSectionId = target.data("section-id");
                    this.selectTab(this.m_selectedSectionId);
                }
                template() {
                    return `<div class="-jadejs-ribbonbar">
                        <div role="tabs"></div>
                        <div role="content" data-controls></div>
                    </div>`;
                }
                show(toolingIds) {
                    let validSections = [];
                    let invalidSections = [];
                    this.sections.each((section) => {
                        if (section.alwaysShow || _.indexOf(toolingIds, section.toolingId) > -1) {
                            validSections[validSections.length] = section.ID;
                        }
                        else {
                            invalidSections[invalidSections.length] = section.ID;
                        }
                    });
                    _.each(this.controls.toArray(), (section) => {
                        if (invalidSections.indexOf(section.ID) > -1) {
                            this.controls.detach(section);
                        }
                    });
                    this.tabStrip.controls.clear();
                    this.sections.each((section) => {
                        if (_.indexOf(validSections, section.ID) > -1) {
                            this.controls.add(section);
                            section.show(toolingIds);
                            this.tabStrip.controls.add(new Controls.RibbonBarTab({ label: section.label, sectionId: section.ID }));
                        }
                    });
                    if (_.indexOf(validSections, this.selectedSectionId) > -1) {
                        this.selectTab(this.selectedSectionId);
                    }
                    else {
                        this.m_selectedSectionId = null;
                        this.controls.each((section) => {
                            if (section instanceof Controls.RibbonBarSection) {
                                if (!section.alwaysShow) {
                                    this.m_selectedSectionId = section.ID;
                                    return false;
                                }
                            }
                        });
                        this.selectTab(this.selectedSectionId);
                    }
                }
                selectTab(sectionId) {
                    let section = null;
                    if (sectionId != null) {
                        section = this.controls.getById(sectionId);
                        if (section != null) {
                            sectionId = section.ID;
                        }
                        else {
                            sectionId = null;
                        }
                    }
                    if (sectionId == null) {
                        section = this.getFirstSection();
                        if (section != null) {
                            sectionId = section.ID;
                        }
                    }
                    if (sectionId != null) {
                        this.node.find(`.-jadejs-ribbonbar-tab[data-section-id=${sectionId}]`).addClass("selected");
                        this.node.find(`[role=content] > DIV`).hide();
                        this.node.find(`[role=content] > DIV#${sectionId}`).show();
                    }
                    this.m_selectedSectionId = sectionId;
                }
                getFirstSection() {
                    let result = null;
                    this.controls.each((control) => {
                        if (control instanceof Controls.RibbonBarSection) {
                            result = control;
                            return false;
                        }
                    });
                    return result;
                }
            }
            Controls.RibbonBar = RibbonBar;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class RibbonBarGroup extends UI.Control {
                constructor(options) {
                    super(options);
                    this.onPopulate();
                }
                get label() {
                    return this.state.get("label");
                }
                get toolingId() {
                    return this.state.get("toolingId");
                }
                get alwaysShow() {
                    return this.m_alwaysShow || false;
                }
                template() {
                    return `<div class="-jadejs-ribbonbar-group"><div role="controls" data-controls></div><div role="label">${this.label}</div></div>`;
                }
                onPopulate() {
                }
                onActivateComplete(e) {
                    this.node.on("click", ".-jadejs-ribbonbar-item", (e) => {
                        let node = $(e.currentTarget);
                        let item = this.controls.getById(node.attr("ID"));
                        if (item != null) {
                            item.click(e);
                        }
                    });
                }
                shouldAlwaysShow(value) {
                    this.m_alwaysShow = value;
                }
            }
            Controls.RibbonBarGroup = RibbonBarGroup;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class RibbonBarGroups {
                static get groups() {
                    return this.m_groups;
                }
                static add(tab) {
                    this.groups.add(tab);
                }
                static remove(groupId) {
                    let group = this.groups.get(groupId);
                    if (group != null) {
                        this.groups.remove(group);
                    }
                }
                static get(groupId) {
                    return this.groups.get(groupId);
                }
                static clear() {
                    this.m_groups = new Jade.MappedCollection({ key: "ID" });
                }
                static reset() {
                    let groups = new Array();
                    this.groups.each((group) => {
                        let instance = new group.constructor({
                            id: group.ID
                        });
                        groups[groups.length] = instance;
                    });
                    this.clear();
                    _.each(groups, (group) => {
                        this.add(group);
                    });
                }
            }
            RibbonBarGroups.m_groups = new Jade.MappedCollection({ key: "ID" });
            Controls.RibbonBarGroups = RibbonBarGroups;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class RibbonBarSection extends UI.Control {
                constructor(options) {
                    super(options);
                    this.m_groups = new Jade.MappedCollection({ key: "ID" });
                    this.onPopulate();
                }
                get groups() {
                    return this.m_groups;
                }
                get label() {
                    return this.state.get("label");
                }
                get toolingId() {
                    return this.state.get("toolingId");
                }
                get alwaysShow() {
                    return false;
                }
                template() {
                    return `<div class="-jadejs-ribbonbar-section"></div>`;
                }
                show(toolingIds) {
                    this.groups.each((group) => {
                        this.controls.detach(group);
                    });
                    _.each(toolingIds, (toolingId) => {
                        let group = null;
                        if (this.groups.get(toolingId) == null) {
                            group = Controls.RibbonBarGroups.get(toolingId);
                            if (group != null) {
                                this.groups.add(group);
                            }
                        }
                    });
                    this.groups.each((group) => {
                        if (group.alwaysShow || _.indexOf(toolingIds, group.toolingId) > -1) {
                            this.controls.add(group);
                        }
                    });
                }
                onPopulate() {
                }
            }
            Controls.RibbonBarSection = RibbonBarSection;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class RibbonBarSections {
                static get sections() {
                    return this.m_sections;
                }
                static add(section) {
                    this.sections.add(section);
                }
                static remove(sectionId) {
                    let section = this.sections.get(sectionId);
                    if (section != null) {
                        this.sections.remove(section);
                    }
                }
                static get(sectionId) {
                    return this.sections.get(sectionId);
                }
                static clear() {
                    this.m_sections = new Jade.MappedCollection({ key: "toolingId" });
                }
                static reset() {
                    let sections = new Array();
                    this.sections.each((group) => {
                        let instance = new group.constructor({
                            id: group.ID
                        });
                        sections[sections.length] = instance;
                    });
                    this.clear();
                    _.each(sections, (section) => {
                        this.add(section);
                    });
                }
            }
            RibbonBarSections.m_sections = new Jade.MappedCollection({ key: "toolingId" });
            Controls.RibbonBarSections = RibbonBarSections;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class RibbonBarSet extends UI.Control {
                constructor(options) {
                    super(options);
                    this.onPopulate();
                }
                get items() {
                    return this.state.get("items", []);
                }
                get width() {
                    return this.state.get("width", 100);
                }
                template() {
                    return `<div class="-jadejs-ribbonbar-set"></div>`;
                }
                onPopulate() {
                    _.each(this.items, (item) => {
                        this.controls.add(item);
                    });
                }
                onActivateComplete(e) {
                    this.node.on("click", ".-jadejs-ribbonbar-item", (e) => {
                        let node = $(e.currentTarget);
                        let item = this.controls.getById(node.attr("ID"));
                        if (item != null) {
                            item.click(e);
                        }
                        e.cancelBubble = true;
                        e.stopPropagation();
                    });
                    this.node.css({
                        width: `${this.width}px`
                    });
                }
            }
            Controls.RibbonBarSet = RibbonBarSet;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class RibbonBarTab extends Jade.UI.Control {
                get label() {
                    return this.state.get("label");
                }
                get sectionId() {
                    return this.state.get("sectionId");
                }
                template() {
                    return `<div class="-jadejs-ribbonbar-tab" data-section-id="${this.sectionId}">${this.label}</div>`;
                }
            }
            Controls.RibbonBarTab = RibbonBarTab;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class RibbonBarTabStrip extends Jade.UI.Control {
                get tabs() {
                    return this.controls.getByType(Controls.RibbonBarTab);
                }
                template() {
                    return `<div class="-jadejs-ribbonbar-tabstrip"></div>`;
                }
                getTabBySectionId(sectionId) {
                    let result = null;
                    this.tabs.each((control) => {
                        if (control instanceof Controls.RibbonBarTab && control.sectionId == sectionId) {
                            result = control;
                            return false;
                        }
                    });
                    return result;
                }
            }
            Controls.RibbonBarTabStrip = RibbonBarTabStrip;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class RibbionFluid {
                get contractions() {
                    return;
                }
                contract() {
                }
                expand() {
                }
                canContract() {
                    return false;
                }
                canExpand() {
                    return false;
                }
            }
            Controls.RibbionFluid = RibbionFluid;
            class RibbonFluidPriority {
                get priority1() {
                    return 0;
                }
                get priority2() {
                    return 0;
                }
                get priority3() {
                    return 0;
                }
                get priority4() {
                    return 0;
                }
                get priority5() {
                    return 0;
                }
            }
            Controls.RibbonFluidPriority = RibbonFluidPriority;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class RibbonBarItem extends Jade.UI.Control {
                constructor(options) {
                    super(options);
                    this.m_commandSubscriber = null;
                    this.m_contextMenu = null;
                    this.m_label = null;
                    this.m_icon = null;
                    this.m_tooltip = null;
                    this.m_visible = null;
                    this.m_enabled = null;
                    this.m_value = null;
                    this.m_label = options.label;
                    this.m_icon = options.icon;
                    this.m_tooltip = options.tooltip;
                    this.m_visible = options.visible;
                    this.m_enabled = options.enabled;
                    this.m_value = options.value;
                }
                get label() {
                    return this.getValue("label", "Label");
                }
                get icon() {
                    return this.getValue("icon", null);
                }
                get enabled() {
                    return this.getValue("enabled", true);
                }
                set enabled(value) {
                    this.m_enabled = value;
                    this.onPropertiesChanged();
                }
                get tooltip() {
                    return this.getValue("tooltip", "");
                }
                get visible() {
                    return this.getValue("visible", true);
                }
                get value() {
                    return this.getValue("value", null);
                }
                get contextMenu() {
                    return this.m_contextMenu;
                }
                set contextMenu(value) {
                    this.m_contextMenu = value;
                }
                get menu() {
                    return this.state.get("menu", []);
                }
                get commandSubscriber() {
                    return this.m_commandSubscriber;
                }
                click(e) {
                    this.createContextMenu();
                    if (this.contextMenu != null && this.enabled) {
                        this.contextMenu.show({
                            groups: this.menu,
                            x: this.node.offset().left + 8,
                            y: this.node.offset().top + this.node.outerHeight(true) + 8
                        });
                        return;
                    }
                    if (this.commandSubscriber != null && this.enabled) {
                        this.commandSubscriber.execute(this.value);
                    }
                }
                onActivate(e) {
                    super.onActivate(e);
                    this.onPropertiesChanged();
                }
                onTemplateStart(e) {
                    if (this.state.get("commandId") != null) {
                        this.m_commandSubscriber = new Jade.CommandSubscriber();
                        this.commandSubscriber.subscribe(this.state.get("commandId"), () => {
                            this.onPropertiesChanged();
                        });
                    }
                }
                onTemplateComplete(e) {
                    if (this.commandSubscriber != null) {
                        this.onPropertiesChanged();
                    }
                }
                onPropertiesChanged() {
                    if (this.enabled) {
                        this.node.removeAttr("disabled");
                    }
                    else {
                        this.node.attr("disabled", "");
                    }
                }
                wrapTemplate(template) {
                    return template;
                }
                createContextMenu() {
                    if (this.menu.length > 0) {
                        if (this.contextMenu == null) {
                            this.contextMenu = new Controls.ContextMenu({ container: "BODY" });
                        }
                    }
                }
                getValue(id, defaultValue) {
                    let result = null;
                    if (this["m_" + id] != null) {
                        result = this["m_" + id];
                    }
                    else if (this.m_commandSubscriber != null) {
                        result = this.m_commandSubscriber[id];
                    }
                    else {
                        result = this.state.get(id);
                    }
                    if (result == null) {
                        result = defaultValue;
                    }
                    return result;
                }
            }
            Controls.RibbonBarItem = RibbonBarItem;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class RibbonBarToggle extends Controls.RibbonBarItem {
                click(e) {
                }
            }
            Controls.RibbonBarToggle = RibbonBarToggle;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class RibbonBarButton extends Controls.RibbonBarItem {
                constructor(options) {
                    super(options);
                }
                get labelNode() {
                    return this.node.find("div[role=label]");
                }
                get imageNode() {
                    return this.node.find("img");
                }
                get icon() {
                    let result = this.getValue("icon", null);
                    if (this.commandSubscriber != null) {
                        result = this.commandSubscriber.command.getIcon(Jade.IconSetSizeSpecificDirectory.x32, result);
                    }
                    return result;
                }
                get width() {
                    return this.state.get("width", null);
                }
                onPropertiesChanged() {
                    super.onPropertiesChanged();
                    this.labelNode.html(this.getLabel());
                    this.imageNode.attr("src", this.icon);
                    this.setWidth();
                }
                onActivate(e) {
                    this.setWidth();
                }
                template() {
                    return `<div class="-jadejs-ribbonbar-item -jadejs-ribbonbar-button large" title="${this.label}">
                        <img src="${this.icon}"/><br/>
                        <div role="label">
                            ${this.getLabel()}
                        </div>
                    </div>`;
                }
                getLabel() {
                    return `${this.label} ${this.menu.length > 0 ? "<div style='font-size:8px;margin-left:3px;display:inline-block;'>▼</div>" : ""}`;
                }
                setWidth() {
                    this.node.css({
                        width: this.width == null ? "" : `${this.width}px`,
                        minWidth: this.width == null ? "" : `${this.width}px`
                    });
                }
            }
            Controls.RibbonBarButton = RibbonBarButton;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class RibbonBarButtonSmall extends Controls.RibbonBarItem {
                get icon() {
                    let result = this.getValue("icon", null);
                    if (this.commandSubscriber != null) {
                        result = this.commandSubscriber.command.getIcon(Jade.IconSetSizeSpecificDirectory.x16, result);
                    }
                    return result;
                }
                template() {
                    return `<div class="-jadejs-ribbonbar-item -jadejs-ribbonbar-button small">
                        <div role="icon">
                            <img src="${this.icon}" />
                        </div>
                        <div role="label">
                            ${this.label}${this.menu.length > 0 ? "<span style='font-size:8px;margin-left:3px;'>▼</span>" : ""}
                        </div>
                    </div>`;
                }
            }
            Controls.RibbonBarButtonSmall = RibbonBarButtonSmall;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class RibbonBarList extends Controls.RibbonBarItem {
            }
            Controls.RibbonBarList = RibbonBarList;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class RibbonBarToggleButton extends UI.Control {
            }
            Controls.RibbonBarToggleButton = RibbonBarToggleButton;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
var Jade;
(function (Jade) {
    var UI;
    (function (UI) {
        var Controls;
        (function (Controls) {
            class Tooling {
                constructor() {
                    this.m_set = {};
                }
                add(tag) {
                    this.m_set[tag] = true;
                }
                remove(tag) {
                    if (this.m_set[tag] != undefined) {
                        this.m_set[tag];
                    }
                }
                clear() {
                    this.m_set = {};
                }
                contains(tag) {
                    let result = false;
                    if (this.m_set[tag] != undefined) {
                        result = this.m_set[tag];
                    }
                    return result;
                }
                toArray() {
                    let result = new Array();
                    for (let key in this.m_set) {
                        result[result.length] = key;
                    }
                    return result;
                }
                static getCommon(toolings) {
                    let result = new Array();
                    _.each(toolings, (tooling) => {
                        result = result.concat(tooling.toArray());
                    });
                    result = _.uniq(result);
                    return result;
                }
            }
            Controls.Tooling = Tooling;
            function toolingTags(...tags) {
                return function _toolingTags(constr) {
                    return class extends constr {
                        constructor(...args) {
                            super(...args);
                            _.each(tags, (tag) => {
                                this.tooling.add(tag);
                            });
                        }
                    };
                };
            }
            Controls.toolingTags = toolingTags;
        })(Controls = UI.Controls || (UI.Controls = {}));
    })(UI = Jade.UI || (Jade.UI = {}));
})(Jade || (Jade = {}));
//# sourceMappingURL=jadejs.js.map