123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
"use strict";
modulum('UserInterfaceWidget', ['WidgetGroupBase', 'WidgetFactory'],
function(context, cls) {
cls.UserInterfaceWidget = context.oo.Class(cls.WidgetGroupBase, function($super) {
return {
__name: "UserInterfaceWidget",
$static: {
startMenuPosition: 'gStartMenuPosition'
},
_text: "",
_image: null,
_topMenuContainer: null,
_toolBarContainer: null,
_toolBarWidget: null,
_startMenuWidget: null,
_startMenuContainer: null,
_traditionalWindowContainer: null,
_vmFocusedWidget: null,
_vmPreviouslyFocusedWidget: null,
_focusedWidget: null,
_previouslyFocusedWidget: null,
_dbDate: "MDY4/",
_unBindLayoutHandler: null,
_activeWindow: null,
_errorMessageWidget: null,
_chromeBarContainer: null,
_chromeBar: null,
_isBufferingKeys: null,
_browserResizeHandler: null,
_charLengthSemantics: null,
constructor: function(opts) {
$super.constructor.call(this, opts);
this._chromeBarContainer = this._element.getElementsByClassName("gbc_chromeBarContainer")[0];
this._topMenuContainer = this._element.getElementsByClassName("gbc_topMenuContainer")[0];
this._toolBarContainer = this._element.getElementsByClassName("gbc_toolBarContainer")[0];
this._startMenuContainer = this._element.getElementsByClassName("gbc_startMenuContainer")[0];
this._errorMessageWidget = cls.WidgetFactory.createWidget("Message", this.getBuildParameters());
this._errorMessageWidget.setHidden(true);
this._chromeBar = cls.WidgetFactory.createWidget("ChromeBar", this.getBuildParameters());
var appHost = context.HostService.getApplicationHostWidget();
this._chromeBar.when(context.constants.widgetEvents.toggleClick,
() => gbc.HostLeftSidebarService.showSidebar());
this.addChromeBar();
this._browserResizeHandler = context.HostService.onScreenResize(function() {
this.getLayoutEngine().forceMeasurement();
this.getLayoutInformation().invalidateMeasure();
}.bind(this));
},
destroy: function() {
if (this._browserResizeHandler) {
this._browserResizeHandler();
this._browserResizeHandler = null;
}
this._topMenuContainer = null;
this._toolBarContainer = null;
this._startMenuContainer = null;
if (this._unBindLayoutHandler) {
this._unBindLayoutHandler();
this._unBindLayoutHandler = null;
}
this._chromeBarContainer = null;
if (this._chromeBar) {
this._chromeBar.destroy();
this._chromeBar = null;
}
this._errorMessageWidget.destroy();
this._errorMessageWidget = null;
this._vmFocusedWidget = null;
this._focusedWidget = null;
$super.destroy.call(this);
this._startMenuWidget = null;
},
_initLayout: function() {
this._layoutInformation = new cls.LayoutInformation(this);
this._layoutEngine = new cls.UserInterfaceLayoutEngine(this);
this._unBindLayoutHandler = this._layoutEngine.onLayoutApplied(this._onLayoutApplied.bind(this));
},
_onLayoutApplied: function() {
if (this.getContainerElement().children.length > 1) {
for (var i = 0; i < this.getChildren().length; i++) {
var current = this.getChildren()[i];
if (this._canBeRemoved(current)) {
current.getElement().remove();
}
}
}
if (this._unBindLayoutHandler) {
this._unBindLayoutHandler();
this._unBindLayoutHandler = null;
}
},
setCharLengthSemantics: function(charLengthSemantics) {
this._charLengthSemantics = charLengthSemantics;
},
isCharLengthSemantics: function() {
return this._charLengthSemantics;
},
_canBeRemoved: function(widget) {
const currentWindowWidget = context.HostService.getCurrentWindowWidget();
return widget instanceof cls.WindowWidget && (currentWindowWidget && widget !== currentWindowWidget) && !widget._forceVisible;
},
getMessageWidget: function() {
return this._errorMessageWidget;
},
getChromeBarWidget: function() {
return this._chromeBar;
},
addTopMenu: function(widget, order) {
widget.setOrder(order);
if (widget.getParentWidget() === null) {
this.addChildWidget(widget, {
noDOMInsert: true
});
}
widget.getElement().insertAt(order, this._topMenuContainer);
},
addChromeBar: function() {
if (this._chromeBar) {
this.addChildWidget(this._chromeBar, {
noDOMInsert: true
});
this._chromeBarContainer.appendChild(this._chromeBar.getElement());
}
},
addStartMenu: function(widget) {
this._startMenuWidget = widget;
this._startMenuContainer.appendChild(widget.getElement());
},
getStartMenuWidget: function() {
return this._startMenuWidget;
},
addToolBar: function(widget, order, widgetContainer, chromeBar) {
this._toolBarWidget = widget;
widget.setOrder(order);
if (widget.getParentWidget() === null) {
this.addChildWidget(widget, {
noDOMInsert: true
});
}
if (chromeBar) {
chromeBar.addToolBar(widget, order);
} else {
this._toolBarContainer.appendChild(widget._element);
}
},
getToolBar: function() {
return this._toolBarWidget;
},
setToolBarPosition: function(position) {
var visible = (position !== "none");
if (this.getToolBar()) {
this.getToolBar().setHidden(!visible);
}
this._toolBarContainer.toggleClass("hidden", !visible);
},
setFocus: function(fromMouse) {
$super.setFocus.call(this, fromMouse);
this.getElement().domFocus();
},
setVMFocusedWidget: function(widget) {
this._vmPreviouslyFocusedWidget = this._vmFocusedWidget;
if (this._vmFocusedWidget !== widget) {
if (this._vmFocusedWidget && !this._vmFocusedWidget.isDestroyed()) {
this._vmFocusedWidget.loseVMFocus(widget);
}
this._vmFocusedWidget = widget;
}
},
setFocusedWidget: function(widget) {
this._previouslyFocusedWidget = this._focusedWidget;
if (this._focusedWidget && this._focusedWidget._auiTag !== widget._auiTag) {
if (this._focusedWidget.getElement()) {
this._focusedWidget.getElement().removeClass("gbc_Focus");
this._focusedWidget.loseFocus();
}
}
if (!this._focusedWidget || this._focusedWidget._auiTag !== widget._auiTag) {
this._focusedWidget = widget;
if (this._focusedWidget.getElement()) {
this._focusedWidget.getElement().addClass("gbc_Focus");
}
}
},
getVMFocusedWidget: function() {
return this._vmFocusedWidget;
},
hasVMFocusedWidgetChanged: function() {
return this._vmFocusedWidget !== this._vmPreviouslyFocusedWidget;
},
hasFocusedWidgetChanged: function() {
return this._focusedWidget !== this._previouslyFocusedWidget;
},
getFocusedWidget: function() {
return this._focusedWidget;
},
setText: function(text) {
this._text = text;
},
getText: function() {
return this._text;
},
setImage: function(image) {
this._image = image;
this.emit(context.constants.widgetEvents.iconChanged, image);
},
getImage: function() {
return this._image;
},
getDbDateFormat: function() {
return this._dbDate;
},
setDbDateFormat: function(format) {
this._dbDate = format;
},
getTraditionalWindowContainer: function() {
if (!this._traditionalWindowContainer) {
this._traditionalWindowContainer = cls.WidgetFactory.createWidget("TraditionalWindowContainer", this
.getBuildParameters());
}
return this._traditionalWindowContainer;
},
removeTraditionalWindowContainer: function() {
if (this._traditionalWindowContainer) {
this.removeChildWidget(this._traditionalWindowContainer);
this._traditionalWindowContainer = null;
}
},
isLayoutTerminator: function() {
return true;
},
activate: function(win) {
this.emit(context.constants.widgetEvents.activate, win);
},
onActivate: function(hook) {
return this.when(context.constants.widgetEvents.activate, hook);
},
onDisable: function(hook) {
return this.when(context.constants.widgetEvents.disable, hook);
},
setBackgroundColor: function(color) {
$super.setBackgroundColor.call(this, color);
this.setStyle('> .gbc_barsContainer', {
"background-color": color && !this._ignoreBackgroundColor ? color : null
});
},
showChromeBarFilterMenuItem: function(visible, filterValue) {
if (this._chromeBar) {
this._chromeBar.showFilterMenuItem(visible, filterValue);
}
},
};
});
cls.WidgetFactory.registerBuilder('UserInterface', cls.UserInterfaceWidget);
});