var Semaphore = Class.create();
Object.extend(Semaphore.prototype,{
signalled: false,
timeout: null,
later: null,
initialize: function(t) {
this.timeout = t;
this.signalled = false;
},
waitForSignal: function() {
if (( this.timeout == null ) || ( this.timeout < 0 )) {
return;
}
this.later = ( new Date() ).getTime() + this.timeout * 1000;
new PeriodicalExecuter(this.poll.bind(this),0.2);
},
signal: function() {
this.signalled = true;
},
poll: function(pe) {
if (this.signalled) {
pe.stop();
}
if (( new Date() ).getTime() > this.later) {
pe.stop();
}
},
onStop: function() {
}
});
var Icons = Class.create();
Object.extend(Icons,{
DATE: "/images/ico12x12/date.gif",
INSERT: "/images/ico12x12/insert.gif",
REMOVE: "/images/ico12x12/remove.gif",
CHECK_TRUE: "/images/ico12x12/check-true.gif",
CHECK_FALSE: "/images/ico12x12/check-false.gif",
ASC: "/images/ico12x12/asc.gif",
DESC: "/images/ico12x12/desc.gif",
MAGNIFY: "/images/ico12x12/magnify.gif",
POPUP: "/images/ico12x12/popup.gif",
CLEAN: "/images/ico12x12/clean.gif"
});
var Options = Class.create();
Object.extend(Options,{
hasOption: function(options,optionName) {
return ( get(options, optionName) != null );
},
hasOptionEnabled: function(options,optionName,defaultValue) {
var optionValue = get(options, optionName);
if (optionValue != null) {
return ( optionValue == "true" );
}
return defaultValue;
},
getIntOption: function(options,optionName,defaultValue) {
var optionValue = get(options, optionName);
if (optionValue != null) {
return optionValue;
}
return defaultValue;
},
getStrOption: function(options,optionName,defaultValue) {
var optionValue = get(options, optionName);
if (optionValue != null) {
return optionValue;
}
return defaultValue;
}
});
var Style = Class.create();
Object.extend(Style,{
GRID_TABLE: "grid-table",
FORM_SECTION: "form-section",
ENTRY_TABLE: "entry-table",
LINE_FIELDS: "line-fields",
FIELD_TABLE: "field-table",
FORM_TABLE: "form-table",
TABLE_BLANK: "table-blank",
NO_DATA: "no-data",
BREAD_CRUMB: "bread-crumb",
PANEL: "panel",
TOOLBAR: "toolbar",
ENTRIES: "entries",
POINTER: "pointer",
SORTABLE: "sortable",
SORTED: "sorted",
SPACER: "spacer",
HIDDEN: "hidden",
FLOAT_LEFT: "float-left",
FLOAT_RIGHT: "float-right",
VIEW_VALUE: "view-value",
ALIGN_MIDDLE: "align-middle",
READONLY: "readonly",
EDIT_MODE: "edit-mode",
INNER_FORM: "inner-form",
BTN_70: "btn70",
BTN_120: "btn120",
ODD: "odd",
EVEN: "even",
SELECTED: "selected",
TEXT_COLUMN: "text-column",
CODE_COLUMN: "code-column",
NUMBER_COLUMN: "number-column",
DATE_COLUMN: "date-column",
HIGHLIGHT: "highlight",
ERROR: "error",
FIELDERROR: "fielderror",
WARNING: "warning",
INFO: "info",
FAKEBUTTON: "fakebutton",
FAKEFILE: "fakefile",
FILE_PROGRESS_BAR: "file-progress-bar",
FILE_PROGRESS_METER: "file-progress-meter",
FILE_PROGRESS_TEXT: "file-progress-text",
FILE_PROGRESS_BAR_BOX: "file-progress-bar-box",
FILE_PROGRESS_BAR_CONTENT: "file-progress-bar-content",
POPUP_TABLE: "popup-table",
POPUP_TABLE_SCROLL: "popup-table-scroll",
POPUP_TABLE_HEADER: "popup-table-header",
POPUP_FILTER: "popup-filter",
CLOSE_BUTTON: "close-button",
FORM_FILTER: "form-filter",
FORM_FILTER_ACTIVE: "form-filter-active",
FORM_FILTER_CANCEL: "form-filter-cancel",
ACT_T: "act-t",
ACT_C: "act-c",
TAB_CONTENT: "tab-content",
TAB_GROUP: "tab-group",
TABS: "tabs",
AUTOCOMPLETE: "autocomplete",
DRAGGABLE: "draggable",
REPORT_GROUP_LABEL: "report-group-label",
REPORT_GROUP_SUM: "report-group-sum",
REPORT_SUM: "report-sum"
});
var TabGroupElement = Class.create();
Object.extend(TabGroupElement.prototype,{
page: null,
options: null,
activeIndex: 0,
ta: null,
tl: null,
tc: null,
focusProperty: null,
init: function(opt) {
this.options = opt;
this.id = get(this.options, "id");
this.create();
},
create: function() {
this.activeIndex = 0;
var tabNav = this.down("ul");
this.ta = tabNav.getElementsByTagName("a");
this.tl = tabNav.getElementsByTagName("li");
this.tc = $TGContent(this.id).childElements();
for (var i = 0;i < this.ta.length;i ++) {
Element.extend(this.ta[i]);
Object.extend(this.ta[i], TabLinkElement.prototype);
this.ta[i].init(this, i);
}
for (var i = 0;i < this.tl.length;i ++) {
Element.extend(this.tl[i]);
Object.extend(this.tl[i], TabElement.prototype);
this.tl[i].init(this, i);
}
for (var i = 0;i < this.tl.length;i ++) {
Element.extend(this.tc[i]);
Object.extend(this.tc[i], TabContentElement.prototype);
this.tc[i].init(this, i);
}
},
activate: function(tabNo) {
if (this.activeIndex != tabNo) {
this.ta[tabNo].onClickHandler();
}
},
focusContent: function() {
if (this.tl[this.activeIndex].focusProperty != null) {
var view = $View(this.tl[this.activeIndex].focusProperty);
if (view != null) {
try {
view.focus();
}
catch (e) {
}
}
}
else {
this.focusFirstChildView(this.tc[this.activeIndex]);
}
},
focusFirstChildView: function(element) {
var childs = element.immediateDescendants();
for (var i = 0;i < childs.length;i ++) {
if (childs[i].id != null && childs[i].id.startsWith("v:")) {
try {
childs[i].focus();
}
catch (e) {
}
return true;
}
else
if (this.focusFirstChildView(childs[i])) {
return true;
}
}
return false;
},
initialize: function() {}
});
var MVCTableRowElement = Class.create();
Object.extend(MVCTableRowElement.prototype,{
rowNum: null,
toHTML: function() {
var _cells = [];
_cells[_cells.length] = "<tr class='" + this.classNames().toArray().join(" ") + "' rowNum='" + this.rowNum + "'>";
for (var i = 0;i < this.cells.length;i ++) {
_cells[_cells.length] = this.cells[i].toHTML();
}
_cells[_cells.length] = "</tr>";
return _cells.join("");
},
initialize: function() {}
});
var MVCTableCellElement = Class.create();
Object.extend(MVCTableCellElement.prototype,{
rowNum: null,
cellNum: null,
anchor: null,
toHTML: function() {
if (this.anchor != null) {
return "<td class='" + this.classNames().toArray().join(" ") + "' rowNum='" + this.rowNum + "' cellNum='" + this.cellNum + "'>" + this.anchor.toHTML() + "</td>";
}
return "<td class='" + this.classNames().toArray().join(" ") + "' rowNum='" + this.rowNum + "' cellNum='" + this.cellNum + "'>" + this.innerHTML + "</td>";
},
initialize: function() {}
});
var TabContentElement = Class.create();
Object.extend(TabContentElement.prototype,{
tg: null,
no: 0,
init: function(_tg,_no) {
this.tg = _tg;
this.no = _no;
},
initialize: function() {}
});
var PopupIFrame = Class.create();
Object.extend(PopupIFrame.prototype,{
module: null,
parent: null,
popupDiv: null,
iframe: null,
offset: 0,
width: 0,
height: 0,
initialize: function(module,parent,options) {
this.module = module;
this.parent = parent;
Object.extend(this, options);
},
show: function() {
if (this.popupDiv != null)
this.reload();
else
this.create();
Position.clone(this.parent, this.popupDiv,  {
setLeft: true,
setTop: true,
setWidth: false,
setHeight: false
});
var offsetWidth = ( this.offset != 0 ) ? ( ( this.parent.getWidth() / this.parent.getWidth() ) * this.offset ) : this.parent.getWidth();
new Effect.Parallel([new Effect.BlindDown(this.popupDiv, {
sync: true
}), new Effect.Move(this.popupDiv, {
sync: true,
x: offsetWidth + 15,
y: - 15,
mode: "relative"
})], {
duration: .4
});
PopupManager.register(this.popupDiv, false);
mvc.kph.onKey(KPH.ESC_KEYCODE, this.toggle.bind(this), false);
},
hide: function() {
PopupManager.deregister(this.popupDiv);
window.popupRef = null;
this.iframe.src = "about:blank";
},
resetReturnValue: function() {
},
toggle: function() {
if (this.popupDiv != null && this.popupDiv.visible()) {
this.hide();
}
else {
this.show();
}
},
create: function() {
this.popupDiv = elem("div");
this.popupDiv.addClassName(Style.POPUP_TABLE);
this.popupDiv.hide();
this.parent.up(0).appendChild(this.popupDiv);
var divHeader = this.createHeader();
this.popupDiv.appendChild(divHeader);
var iframeDiv = elem("div");
iframeDiv.addClassName(Style.POPUP_TABLE_SCROLL);
this.iframe = elem("iframe",  {
src: this.module + ".popupList",
name: "popup",
width: 500,
height: 600,
scrolling: true
});
iframeDiv.appendChild(this.iframe);
this.popupDiv.appendChild(iframeDiv);
window.popupRef = this;
},
createHeader: function() {
var divHeader = elem("div");
divHeader.addClassName(Style.POPUP_TABLE_HEADER);
var anchor = elem("a",  {
href: "#"
});
anchor.addClassName(Style.CLOSE_BUTTON);
Event.observe(anchor, "click", this.toggle.bind(this));
divHeader.appendChild(anchor);
var spanX = elem("span");
spanX.innerHTML = "X";
anchor.appendChild(spanX);
return divHeader;
},
reload: function() {
this.iframe.src = this.module + ".popupList";
window.popupRef = this;
},
onAction: function(event,row) {
}
});
var PopupManager = Class.create();
Object.extend(PopupManager,{
disableKPH: true,
currentPopup: null,
currentWin: null,
register: function(popupElt,disable) {
PopupManager.deregisterAll();
if (popupElt != null) {
PopupManager.disableKPH = disable;
PopupManager.currentPopup = popupElt;
if (PopupManager.disableKPH)
mvc.kph.disable();
else
mvc.kph.push();
}
},
registerWin: function(popupWin) {
PopupManager.deregisterAll();
if (popupWin != null) {
PopupManager.currentWin = popupWin;
}
},
deregister: function(popup) {
if (PopupManager.currentPopup == popup) {
PopupManager.deregisterAll();
}
},
deregisterWin: function(wnd) {
if (PopupManager.currentWin == wnd) {
PopupManager.deregisterAll();
}
else
if (wnd != null && ! wnd.closed)
wnd.close();
},
deregisterAll: function() {
if (PopupManager.currentPopup != null) {
if (PopupManager.disableKPH)
mvc.kph.enable();
else
mvc.kph.pop();
PopupManager.currentPopup.hide();
PopupManager.currentPopup = null;
}
else
if (PopupManager.currentWin != null) {
if (! PopupManager.currentWin.closed)
PopupManager.currentWin.close();
PopupManager.currentWin = null;
}
},
openWinExt: function(myUrl,winName,width,height,top,left,alignRight,el,windowFeatures) {
PopupManager.deregisterAll();
if (width == - 1)
width = 800;
if (height == - 1)
height = 600;
width = parseInt(width);
height = parseInt(height);
if (width > screen.width)
width = screen.width;
if (height > screen.height)
height = screen.height;
if (left == - 1 && top == - 1) {
if (el != null) {
var coord = getElementWindowPosition(el);
left = coord.x + 20;
top = coord.y - height / 3;
}
else {
if (alignRight) {
left = screen.width - width;
}
else {
left = ( screen.width / 2 ) - width / 2;
}
top = ( screen.height / 2 ) - height / 2;
}
}
if (( top + height ) > screen.height)
top = screen.height - height;
if (( left + width ) > screen.width)
left = screen.width - width;
if (top < 0)
top = 0;
if (left < 0)
left = 0;
var features = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + "," + windowFeatures;
var popupWin = window.open(myUrl, winName, features);
if (popupWin.opener == null)
popupWin.opener = self;
PopupManager.registerWin(popupWin);
return popupWin;
},
openWin: function(myUrl,winName,width,height,top,left,alignRight,el) {
return PopupManager.openWinExt(myUrl, winName, width, height, left, top, alignRight, el, "directories=0,location=0,menubar=0,scrollbars=1,status=0,toolbar=0,resizable=1,titlebar=0,dependent=1");
},
openModalWin: function(myUrl,winName,width,height,top,left,alignRight,el) {
PopupManager.deregisterAll();
if (width == - 1)
width = 800;
if (height == - 1)
height = 600;
width = parseInt(width);
height = parseInt(height);
if (width > screen.width)
width = screen.width;
if (height > screen.height)
height = screen.height;
if (left == - 1 && top == - 1) {
if (el != null) {
var coord = getElementWindowPosition(el);
left = coord.x + 20;
top = coord.y - height / 3;
}
else {
if (alignRight) {
left = screen.width - width;
}
else {
left = ( screen.width / 2 ) - width / 2;
}
top = ( screen.height / 2 ) - height / 2;
}
}
if (( top + height ) > screen.height)
top = screen.height - height;
if (( left + width ) > screen.width)
left = screen.width - width;
if (top < 0)
top = 0;
if (left < 0)
left = 0;
debugPrint("width=" + width + ",height=" + height + ",top=" + top + ",left=" + left);
var features = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left;
return window.openModalWindow(myUrl, winName, features);
},
openModalDialog: function(myUrl,data,width,height,top,left,alignRight,el,handler) {
PopupManager.deregisterAll();
if (width == - 1)
width = 1024;
if (height == - 1)
height = 768;
width = parseInt(width);
height = parseInt(height);
if (width > screen.width)
width = screen.width;
if (height > screen.height)
height = screen.height;
if (left == - 1 && top == - 1) {
if (el != null) {
var coord = getElementWindowPosition(el);
left = coord.x + 20;
top = coord.y - height / 3;
}
else {
if (alignRight) {
left = screen.width - width;
}
else {
left = ( screen.width / 2 ) - width / 2;
}
top = ( screen.height / 2 ) - height / 2;
}
}
if (( top + height ) > screen.height)
top = screen.height - height;
if (( left + width ) > screen.width)
left = screen.width - width;
var features = "dialogWidth:" + width + "px;dialogHeight:" + height + "px; dependent:yes; scroll:no; status:no; help:no";
if (top >= 0 || left >= 0) {
if (top < 0)
top = 0;
if (left < 0)
left = 0;
features = "dialogTop:" + top.toFixed(0) + "px;dialogLeft:" + left.toFixed(0) + "px; center:no;" + features;
}
else {
features = "center:yes;" + features;
}
debugPrint("open modal dialog with features: " + features);
return xShowModalDialog(myUrl, data, features, handler);
}
});
Object.extend(PopupManager.prototype,{
initialize: function() {
}
});
var ActionElement = Class.create();
Object.extend(ActionElement.prototype,{
gridPage: null,
formPage: null,
context: null,
options: null,
actionId: "",
init: function(opts) {
this.options = opts;
this.actionId = get(this.options, "action");
var _name = get(this.options, "name");
if (_name != null) {
this.actionName = _name;
}
if (! this.useDefaultOnclick()) {
Event.observe(this, "click", this.executeAction.bindAsEventListener(this));
}
var hotkey = get(this.options, "hotkey");
if (hotkey != null) {
var hotkeys = hotkey.split(",");
for (var i = 0;i < hotkeys.length;i ++) {
debugPrint(this.actionName + ": hotkey=" + hotkeys[i]);
this.bindHotKey(hotkeys[i], this.executeCall.bind(this));
}
}
},
useDefaultOnclick: function() {
return false;
},
bindHotKey: function(hotkey,handler) {
var flags = hotkey.split("+");
var keycode = "";
for (var i = 0;i < flags.length;i ++) {
if (i > 0)
keycode = keycode + "|";
keycode = keycode + "KPH." + flags[i];
if (flags[i] == "CTRL" || flags[i] == "ALT" || flags[i] == "SHIFT") {
keycode = keycode + "_FLAG";
}
else {
keycode = keycode + "_KEYCODE";
}
}
debugPrint(this.actionName + ": onKey(" + eval(keycode) + ") [" + keycode + "]");
mvc.kph.onKey(eval(keycode), handler, false);
},
execute: function() {
},
executeCall: function() {
this.focus();
this.execute();
},
executeAction: function() {
if (this.confirmed()) {
this.execute();
}
},
confirmed: function() {
var confirmElt = this.next(0);
if (confirmElt != null && confirmElt.nodeName == "SPAN" && confirmElt.hasClassName("confirm") && confirmElt.innerHTML != "") {
return confirm(confirmElt.innerHTML);
}
return true;
},
initialize: function() {}
});
var NextAction = Class.create();
Object.extend(NextAction.prototype, ActionElement.prototype);
Object.extend(NextAction.prototype,{
actionName: "next",
execute: function() {
this.formPage.view.loadNextBean();
},
initialize: function() {}
});
var CopyAction = Class.create();
Object.extend(CopyAction.prototype, ActionElement.prototype);
Object.extend(CopyAction.prototype,{
actionName: "copy",
execute: function() {
this.formPage.view.copyBean();
},
initialize: function() {}
});
var ViewAction = Class.create();
Object.extend(ViewAction.prototype, ActionElement.prototype);
Object.extend(ViewAction.prototype,{
actionName: "view",
execute: function() {
this.formPage.context.setRender(ViewElement.RENDER_VIEW);
this.formPage.view.viewData();
},
initialize: function() {}
});
var MVCLinkElement = Class.create();
Object.extend(MVCLinkElement.prototype,{
toHTML: function() {
return "<a href='" + this.getAttribute("href") + "'>" + this.innerHTML + "</a>";
},
initialize: function() {}
});
var Messages = Class.create();
Object.extend(Messages,{
enabled: true,
showMessages: function(msgList) {
if (! Messages.enabled)
return;
var msgDiv = Messages.getMessagesDiv();
if (msgDiv != null) {
Messages.clearMessages(msgDiv);
var tc = null;
var focusElt = null;
for (var i = 0;i < msgList.length;i ++) {
if (msgList[i] != null) {
var msgElem = Messages.createMessage(msgList[i]);
if (msgList[i].property != null) {
if (focusElt == null) {
focusElt = msgElem;
}
var ancestors = msgElem.ancestors();
for (var a = 0;a < ancestors.length;a ++) {
if (ancestors[a].id == "content")
break;
else
if (ancestors[a].hasClassName(Style.TAB_CONTENT)) {
var foundTc = ancestors[a - 1];
if (tc == null || tc.no > foundTc.no) {
tc = foundTc;
focusElt = msgElem;
}
break;
}
}
}
else {
if (focusElt == null) {
focusElt = msgElem;
}
msgDiv.appendChild(msgElem);
}
}
}
if (tc != null) {
tc.tg.activate(tc.no);
}
if (focusElt != null) {
focusElt.scrollTo();
}
}
},
showMessage: function(msg) {
var msgDiv = Messages.getMessagesDiv();
if (msgDiv != null) {
Messages.clearMessages(msgDiv);
var msgElem = Messages.createMessage(msg);
if (msgElem != null) {
msgDiv.appendChild(msgElem);
msgElem.scrollTo();
}
}
},
clearMessages: function(msgDiv) {
var msgElts = $A($("content").getElementsByClassName(Style.ERROR));
if (msgElts != null) {
msgElts.each(Messages.clearMessage);
}
msgDiv.innerHTML = "";
},
clearMessage: function(elt) {
elt.up(0).removeClassName(Style.FIELDERROR);
elt.remove();
},
getMessagesDiv: function() {
var msgDiv = $("messages");
if (msgDiv == null) {
msgDiv = elem("div",  {
id: "messages"
});
var coreDiv = $("core");
if (coreDiv != null) {
coreDiv.insertBefore(coreDiv.firstChild, msgDiv);
}
else {
document.getElementsByTagName("body")[0].appendChild(msgDiv);
}
}
return msgDiv;
},
createMessage: function(msg) {
debugPrint("message[type=" + msg.typeName + "]: " + msg.text);
if (msg.property != null) {
var span = elem("span");
span.addClassName(msg.typeName);
span.addClassName(Style.SPACER);
span.innerHTML = msg.text;
var view = $View(msg.property);
if (view != null) {
view.appendChild(span);
if (msg.typeName == "error") {
view.addClassName(Style.FIELDERROR);
}
var highlight = view;
if (view.up(0).nodeName == "TD") {
highlight = view.up(0);
}
new Effect.Highlight(highlight, {
duration: .7,
startcolor: "#ff5533",
endcolor: "#ffffff",
queue:  {
position: "end",
scope: "validation:" + msg.property
}
});
}
return span;
}
else {
var para = elem("p");
para.addClassName(msg.typeName);
para.innerHTML = msg.text;
para.hide();
new Effect.Appear(para, {
duration: 2,
queue:  {
position: "front",
scope: "messages"
}
});
if (msg.typeName == "info") {
new Effect.Pulsate(para, {
duration: 2,
from: 0.2,
pulses: 2,
queue:  {
position: "end",
scope: "messages"
},
afterFinish: function() {
new Effect.Shake(para);
}
});
}
return para;
}
},
hasErrors: function() {
var msgElts = $("content").getElementsByClassName(Style.ERROR);
return ( msgElts != null && msgElts.length != 0 );
}
});
var EditEntryAction = Class.create();
Object.extend(EditEntryAction.prototype, ActionElement.prototype);
Object.extend(EditEntryAction.prototype,{
actionName: "edit-entry",
execute: function() {
this.formPage.view.editData();
},
initialize: function() {}
});
var RemoteActionElement = Class.create();
Object.extend(RemoteActionElement.prototype, ActionElement.prototype);
Object.extend(RemoteActionElement.prototype,{
execute: function() {
this.context.invokeAction(this.actionName, this.onAction.bind(this));
},
onAction: function(success) {
if (success) {
var hideOnSuccess = get(this.options, "hideOnSuccess");
if (hideOnSuccess != null && hideOnSuccess == "true") {
this.hide();
}
}
},
initialize: function() {}
});
var FilterElement = Class.create();
Object.extend(FilterElement.prototype, ActionElement.prototype);
Object.extend(FilterElement.prototype,{
init: function(options) {
this.options = options;
this.actionId = get(this.options, "action");
this.actionName = get(options, "name");
if (this.actionId == null)
this.actionId = this.actionName;
this.onclick = this.execute.bindAsEventListener(this);
var hotkey = get(this.options, "hotkey");
if (hotkey != null) {
var hotkeys = hotkey.split(",");
for (var i = 0;i < hotkeys.length;i ++) {
this.bindHotKey(hotkeys[i], this.execute.bindAsEventListener(this));
}
}
this.onInit();
},
onInit: function() {
},
getIntOption: function(optionName,defaultValue) {
var optionValue = get(this.options, optionName);
if (optionValue != null) {
return optionValue;
}
return defaultValue;
},
initialize: function() {}
});
var NewEntryAction = Class.create();
Object.extend(NewEntryAction.prototype, ActionElement.prototype);
Object.extend(NewEntryAction.prototype,{
actionName: "new-entry",
execute: function() {
var params = Options.getStrOption(this.options, "params", "");
if (this.previous("span") != null) {
window.location = this.previous("span").innerHTML + params;
}
else {
if (this.gridPage != null) {
window.location = this.gridPage.path + "/" + this.gridPage.gridModule + ".form" + params;
}
else
if (this.formPage != null) {
window.location = this.formPage.path + "/" + this.formPage.formModule + ".form" + params;
}
}
},
initialize: function() {}
});
var FormPage = Class.create();
Object.extend(FormPage.prototype,{
context: null,
view: null,
module: null,
formModule: null,
path: null,
initContext: function(_context,_module,_path) {
this.module = _module;
this.formModule = _module;
this.path = _path;
this.context = _context;
this.context.init(this.onInit.bind(this));
},
onInit: function() {
this.view = $Form(this.module);
this.view.page = this;
this.initEvents();
this.view.loadBean(0);
},
createForm: function(options,source) {
this.view = $Form(this.module);
Object.extend(this.view, source);
this.view.initialize();
this.view.init(this, options);
},
createView: function(options,source) {
var property = get(options, "property");
var viewElt = $View(property);
if (viewElt != null) {
debugPrint("createView: property=" + property);
Object.extend(viewElt, source);
viewElt.initialize();
viewElt.init(this, options);
}
},
createAction: function(actionId,options,source) {
var action = $Action(actionId);
if (action != null) {
Object.extend(action, source);
action.initialize();
action.formPage = this;
action.context = this.context;
action.init(options);
}
},
createTabGroup: function(options,source) {
var id = get(options, "id");
var tg = $TG(id);
if (tg != null) {
Object.extend(tg, source);
tg.initialize();
tg.page = this;
tg.init(options);
if (this.view.rootTG == null) {
this.view.rootTG = tg;
}
}
},
onAfterLoad: function() {
dwr.engine.setActiveReverseAjax(true);
if ($("loading") != null)
$("loading").hide();
},
onSave: function() {
if (! Messages.hasErrors()) {
var nav = $("nav:" + this.module + ":form");
if (nav != null) {
var navLabel = get(this.view.bean, "navLabel");
if (navLabel != null) {
nav.down("span").innerHTML = navLabel;
}
}
var navMenu = $("nav:menu");
if (navMenu != null) {
var submenu = navMenu.getElementsByClassName(this.module.toLowerCase());
if (submenu != null && submenu.length != 0) {
for (var i = 0;i < submenu.length;i ++) {
submenu[i].removeClassName(Style.HIDDEN);
var link = submenu[i].down("a").getAttribute("href");
var param = this.module + "Id=" + get(this.view.bean, "id");
if (link.indexOf("?") != - 1) {
submenu[i].down("a").setAttribute("href", link + "&" + param);
}
else {
submenu[i].down("a").setAttribute("href", link + "?" + param);
}
}
}
}
}
},
onDelete: function() {
},
onCreate: function() {
Messages.enabled = true;
var nav = $("nav:" + this.module + ":form");
if (nav != null) {
nav.down("span").innerHTML = nav.down("span.hidden").innerHTML;
}
var navMenu = $("nav:menu");
if (navMenu != null) {
var submenu = navMenu.getElementsByClassName(this.module.toLowerCase());
if (submenu != null && submenu.length != 0) {
for (var i = 0;i < submenu.length;i ++) {
submenu[i].addClassName(Style.HIDDEN);
}
}
}
},
onCopy: function() {
},
onClear: function() {
},
onLoad: function() {
},
onSubmit: function() {
},
initEvents: function() {
document.delegate("entry:insert", this.onInsertEntry.bindAsEventListener(this));
document.delegate("entry:delete", this.onDeleteEntry.bindAsEventListener(this));
document.delegate("entry:clear", this.onClearEntry.bindAsEventListener(this));
document.delegate("element:change", this.onChangeElement.bindAsEventListener(this));
},
onInsertEntry: function(event) {
var element = get(event.memo, "source");
var value = get(event.memo, "value");
element.onNewRow(value);
var originalEvent = get(event.memo, "originalEvent");
if (originalEvent != null) {
originalEvent.stop();
}
event.stop();
},
onDeleteEntry: function(event) {
var element = get(event.memo, "source");
var rowNum = get(event.memo, "rowNum");
if (rowNum != null) {
element.onDeleteRow(rowNum);
}
var originalEvent = get(event.memo, "originalEvent");
if (originalEvent != null) {
originalEvent.stop();
}
event.stop();
},
onClearEntry: function(event) {
var element = get(event.memo, "source");
var value = get(event.memo, "value");
element.onClearForm(value);
var originalEvent = get(event.memo, "originalEvent");
if (originalEvent != null) {
originalEvent.stop();
}
event.stop();
},
onChangeElement: function(event) {
var element = get(event.memo, "source");
var value = get(event.memo, "value");
element.onChangeValue(value);
var originalEvent = get(event.memo, "originalEvent");
if (originalEvent != null) {
originalEvent.stop();
}
event.stop();
},
initialize: function() {}
});
var TabLinkElement = Class.create();
Object.extend(TabLinkElement.prototype,{
tg: null,
no: 0,
init: function(_tg,_no) {
this.tg = _tg;
this.no = _no;
Event.observe(this, "click", this.onClickHandler.bind(this));
},
onClickHandler: function() {
this.clearActive();
this.setActive();
},
clearActive: function() {
for (var j = 0;j < this.tg.tl.length;j ++) {
this.tg.tl[j].removeClassName(Style.ACT_T);
this.tg.tc[j].removeClassName(Style.ACT_C);
}
},
setActive: function() {
this.tg.tl[this.no].addClassName(Style.ACT_T);
this.tg.tc[this.no].addClassName(Style.ACT_C);
this.tg.activeIndex = this.no;
PopupManager.deregisterAll();
this.tg.focusContent();
},
initialize: function() {}
});
var TableColumn = Class.create();
Object.extend(TableColumn.prototype,{
gridView: null,
columnId: "",
property: "",
direction: "asc",
_selectedColumn: false,
options: null,
columnHandler: function(td,options) {
td.addClassName(Style.TEXT_COLUMN);
},
displayHandler: function(value) {
return value;
},
getMaxLength: function() {
var maxlen = get(this.options, "maxlength");
if (maxlen != null) {
return parseInt(maxlen);
}
return 0;
},
init: function(opt) {
this.options = opt;
this.property = get(this.options, "property");
this.columnId = this.property;
this._selectedColumn = Options.hasOptionEnabled(this.options, "selected", false);
this.direction = Options.getStrOption(this.options, "direction", "asc");
},
initHeader: function() {
var header = $Column(this.columnId);
if (header != null) {
header.addClassName(Style.POINTER);
header.addClassName(Style.SORTABLE);
Event.observe(header, "click", this.onColumnFilter.bind(this));
}
if (this._selectedColumn) {
this.gridView.setSelectedColumn(this);
this.highlightColumn();
}
},
onColumnFilter: function() {
if (this._selectedColumn) {
if (this.direction == "asc") {
this.direction = "desc";
}
else {
this.direction = "asc";
}
}
else {
if (this.gridView.selectedColumn != null) {
this.gridView.selectedColumn.unHighlightColumn();
}
this.gridView.setSelectedColumn(this);
var search = $Filter("search");
if (search != null) {
search.clear();
search.focus();
}
}
this.highlightColumn();
this.gridView.filterColumn(this.property, this.direction);
},
highlightColumn: function() {
var header = $Column(this.columnId);
if (header != null) {
var sortHead = header.down("span");
if (sortHead == null) {
sortHead = elem("span");
sortHead.addClassName(Style.SPACER);
sortHead.hide();
header.appendChild(sortHead);
}
sortHead.innerHTML = "";
if (this.direction == "asc") {
var ascImg = elem("img",  {
src: this.gridView.getPath() + Icons.ASC,alt: ""
});
sortHead.appendChild(ascImg);
}
else {
var descImg = elem("img",  {
src: this.gridView.getPath() + Icons.DESC,alt: ""
});
sortHead.appendChild(descImg);
}
sortHead.addClassName(Style.SORTED);
sortHead.show();
}
this._selectedColumn = true;
},
unHighlightColumn: function() {
var header = $Column(this.columnId);
if (header != null) {
var sortHead = header.down("span");
if (sortHead != null) {
sortHead.hide();
sortHead.innerHTML = "";
sortHead.removeClassName(Style.SORTED);
}
}
this._selectedColumn = false;
},
initialize: function() {}
});
var SubmitAction = Class.create();
Object.extend(SubmitAction.prototype, ActionElement.prototype);
Object.extend(SubmitAction.prototype,{
actionName: "submit",
execute: function() {
if (this.formPage.view.isReady()) {
this.formPage.onSubmit();
}
else {
debugPrint("warn: DWR request in progress!");
}
},
initialize: function() {}
});
var DateTimeColumn = Class.create();
Object.extend(DateTimeColumn.prototype, TableColumn.prototype);
Object.extend(DateTimeColumn.prototype,{
columnHandler: function(td,options) {
td.addClassName(Style.DATE_COLUMN);
},
displayHandler: function(value) {
return printDate(value, "%d.%m.%Y %H:%M");
},
initialize: function() {}
});
var ViewElement = Class.create();
Object.extend(ViewElement,{
RENDER_VIEW: 0,
RENDER_FORM: 1
});
Object.extend(ViewElement.prototype,{
page: null,
context: null,
render: - 1,
hasUI: false,
_value: null,
property: "",
emptyString: "-----",
options: null,
indexedView: null,
callbacks: null,
dependentViewOn: null,
dependentViewOff: null,
toggleOn: null,
toggleOff: null,
_enabled: true,
readonlyElement: false,
onChangeInProgress: false,
originalOnCreateEditUI: null,
clearUI: function() {
this.innerHTML = "";
},
setEmptyValue: function() {
if (this._enabled) {
this.setValueContent(this.emptyString);
}
else {
this.innerHTML = "";
}
},
setValueContent: function(val) {
this.innerHTML = "";
var span = elem("span");
span.addClassName(Style.VIEW_VALUE);
this.appendChild(span);
span.innerHTML = val;
return span;
},
formatValue: function(_value) {
return _value;
},
enableView: function(_focus) {
if (! this._enabled) {
if (this.render == ViewElement.RENDER_FORM) {
debugPrint(this.property + ": enableView [RENDER_FORM]");
if (this.hasUI) {
this.doEnableView(_focus);
}
else {
this.originalOnCreateEditUI = this.onCreateEditUI;
this.onCreateEditUI = this.enableAfterCreateEditUI.bind(this);
}
}
this._enabled = true;
}
else
if (this.render == ViewElement.RENDER_FORM) {
this.doEnableView(_focus);
}
},
disableView: function() {
if (this._enabled) {
if (this.render == ViewElement.RENDER_FORM && this.hasUI) {
this.doDisableView();
}
else {
debugPrint(this.property + ": disableView()");
if (! this.hasUI) {
debugPrint(this.property + ": !hasUI()");
this.originalOnCreateEditUI = this.onCreateEditUI;
this.onCreateEditUI = this.disableAfterCreateEditUI.bind(this);
}
this.setEmptyValue();
this.hideLabels();
}
this._enabled = false;
}
else {
if (this.render == ViewElement.RENDER_FORM) {
this.doDisableView();
}
else {
this.setEmptyValue();
this.hideLabels();
}
}
},
doEnableView: function(_focus) {
debugPrint(this.property + ": doEnableView()");
var view = $(this.property);
if (view != null) {
view.enable();
if (_focus) {
try {
view.focus();
}
catch (e) {
}
}
}
},
doDisableView: function() {
debugPrint(this.property + ": doDisableView()");
$(this.property).disable();
},
enableAfterCreateEditUI: function() {
this.doEnableView(false);
this.onCreateEditUI = this.originalOnCreateEditUI;
},
disableAfterCreateEditUI: function() {
debugPrint(this.property + ": disableAfterCreateEditUI()");
this.doDisableView();
this.onCreateEditUI = this.originalOnCreateEditUI;
},
toggleDependent: function(_focus) {
var _set_focus = _focus;
if (this.dependentViewOn != null) {
for (var i = 0;i < this.dependentViewOn.length;i ++) {
if (this.toggleOn != null) {
if (this.isSameValue(this.getSimpleValue(), this.toggleOn)) {
var elt = $View(this.dependentViewOn[i]);
if (elt != null) {
elt.enableView(_set_focus);
_set_focus = false;
}
}
else {
var elt = $View(this.dependentViewOn[i]);
if (elt != null)
elt.disableView();
}
}
}
}
if (this.dependentViewOff != null) {
for (var i = 0;i < this.dependentViewOff.length;i ++) {
if (this.toggleOff != null) {
if (this.isSameValue(this.getSimpleValue(), this.toggleOff)) {
var elt = $View(this.dependentViewOff[i]);
if (elt != null)
elt.disableView();
}
else {
var elt = $View(this.dependentViewOff[i]);
if (elt != null) {
elt.enableView(_set_focus);
_set_focus = false;
}
}
}
}
}
if (this.callbacks != null) {
for (var i = 0;i < this.callbacks.length;i ++) {
this.callbacks[i](this._value);;
}
}
},
isSameValue: function(val1,val2) {
if (( val1 == null || val1 == "" ) && ( val2 == null || val2 == "" )) {
return true;
}
return val1 == val2;
},
createEditUI: function() {
this.setFormValue();
},
createViewUI: function() {
this.setViewValue();
},
focusElement: function() {
var view = $(this.property);
if (view != null) {
try {
view.focus();
}
catch (e) {
}
}
},
onFocus: function() {
},
onCreateEditUI: function() {
},
getElementValue: function() {
var view = $(this.property);
if (view != null) {
return dwr.util.getValue(view);
}
return this._value;
},
getSimpleValue: function() {
return this._value;
},
setViewValue: function() {
this.setValueContent(this.formatValue(this._value));
},
setFormValue: function() {
dwr.util.setValue(this.property, this.formatValue(this._value));
},
clearValue: function() {
this.setValue(null);
},
bindChangeListener: function() {
this.addChangeListener(this.onValueChanged.bindAsEventListener(this));
},
bindOnFocusListener: function() {
var view = $(this.property);
if (view != null) {
view.onfocus = this.onFocus.bindAsEventListener(this);
}
},
getRealProperty: function() {
if (this.indexedView != null) {
return this.indexedView.getIndexedProperty();
}
return this.property;
},
setValueFromBean: function(data) {
this.setValue(getNestedBeanProperty(data, this.property));
},
setNestedValue: function(nestedProperty,data) {
this.setValue(getNestedBeanProperty(data, nestedProperty));
},
setValue: function(data) {
this._value = this.safeValue(data);
if (this.hasUI) {
if (this.render == ViewElement.RENDER_VIEW) {
this.setViewValue();
this.addStyles();
}
else {
this.setFormValue();
this.toggleDependent(false);
}
}
},
editValue: function() {
if (this.readonlyElement) {
if (! this.hasUI) {
this.render = ViewElement.RENDER_VIEW;
this.clearUI();
this.createViewUI();
this.addStyles();
this.hasUI = true;
}
}
else
if (this.render == ViewElement.RENDER_VIEW || ! this.hasUI) {
this.render = ViewElement.RENDER_FORM;
this.clearUI();
this.createEditUI();
this.addStyles();
this.hasUI = true;
this.bindChangeListener();
this.bindOnFocusListener();
this.onCreateEditUI();
this.showLabels();
}
},
showValue: function() {
if (this.render == ViewElement.RENDER_FORM || ! this.hasUI) {
this.render = ViewElement.RENDER_VIEW;
this.clearUI();
this.createViewUI();
this.addStyles();
this.hasUI = true;
}
},
addStyles: function() {
if (Options.hasOption(this.options, "styleClass")) {
var styles = Options.getStrOption(this.options, "styleClass", "").split(" ");
for (var i = 0;i < styles.length;i ++) {
if (this.down("span") != null) {
if (this.down("span").hasClassName(Style.VIEW_VALUE)) {
this.down("span").removeClassName(Style.VIEW_VALUE);
}
this.down("span").addClassName(styles[i]);
}
else {
this.addClassName(styles[i]);
}
}
}
},
changeValue: function(value) {
if (! this.onChangeInProgress) {
if (this.render == ViewElement.RENDER_FORM) {
if (this.doChangeValue()) {
this.page.view.numOfRequests ++;
this.onChangeInProgress = true;
debugPrint(this.property + ": " + this.getElementValue());
this.setNewValue(this.getElementValue());
this.context.setProperty(this.getRealProperty(), this.formattedValue(), this.stopOnChange.bind(this));
return true;
}
}
}
return false;
},
doChangeValue: function() {
return true;
},
stopOnChange: function() {
this.page.view.numOfRequests --;
this.onChangeInProgress = false;
},
setNewValue: function(val) {
this._value = val;
setNestedBeanProperty(this.page.view.bean, this.property, this._value);
this.toggleDependent(true);
},
safeValue: function(val) {
return val;
},
formattedValue: function() {
return this._value;
},
hasValidValue: function() {
return this._value != null && ( isBean(this._value) && ( get(this._value, "id") != 0 || get(this._value, "labelValue") != "" ) || this._value != "" );
},
init: function(pg,opt) {
this.page = pg;
this.context = pg.context;
this.options = opt;
this.property = get(this.options, "property");
var rdOnly = get(this.options, "readonly");
if (rdOnly != null) {
this.readonlyElement = ( rdOnly == "true" );
}
var depViewsOn = get(this.options, "toggleOn");
if (depViewsOn != null) {
this.dependentViewOn = depViewsOn.split(",");
this.toggleOn = get(this.options, "toggleOnValue");
}
var depViewsOff = get(this.options, "toggleOff");
if (depViewsOff != null) {
this.dependentViewOff = depViewsOff.split(",");
this.toggleOff = get(this.options, "toggleOffValue");
}
var dependsOn = get(this.options, "dependsOn");
if (dependsOn != null) {
var masterElement = $View(dependsOn);
if (masterElement != null) {
var dependsOnValue = get(this.options, "dependsOnValue");
if (dependsOnValue != null) {
masterElement.registerCallback(this.dependsOnCallback.bind(this, dependsOnValue));
}
}
}
push(this.page.view.views, this);
this.afterInit(opt);
},
dependsOnCallback: function(dependsOnValue,val) {
if (dependsOnValue.indexOf(val) != - 1) {
this.up(0).show();
}
else {
this.up(0).hide();
}
},
registerCallback: function(cb) {
if (this.callbacks == null) {
this.callbacks = [];
}
put(this.callbacks, this.callbacks.length, cb);
},
hasOption: function(optionName) {
return ( get(this.options, optionName) != null );
},
hasOptionEnabled: function(optionName,defaultValue) {
var optionValue = get(this.options, optionName);
if (optionValue != null) {
return ( optionValue == "true" );
}
return defaultValue;
},
getIntOption: function(optionName,defaultValue) {
var optionValue = get(this.options, optionName);
if (optionValue != null) {
return optionValue;
}
return defaultValue;
},
afterInit: function(opt) {
},
setAttr: function(elt,attrName,defaultValue) {
var attrValue = get(this.options, attrName);
if (attrValue == null) {
attrValue = defaultValue;
}
if (attrValue != null) {
elt.setAttribute(attrName, attrValue);
}
},
hideLabels: function() {
var prefix = this.previous("label");
if (prefix != null) {
prefix.hide();
}
var suffix = this.next("label");
if (suffix != null) {
suffix.hide();
}
},
showLabels: function() {
var prefix = this.previous("label");
if (prefix != null) {
prefix.show();
}
var suffix = this.next("label");
if (suffix != null) {
suffix.show();
}
},
onChangeValue: function(value) {
this.changeValue(value);
},
onValueChanged: function(event) {
var element = event.element();
element.fire("element:change",  {
source: this,
originalEvent: event
});
return false;
},
addChangeListener: function(f) {
var view = $(this.property);
if (view != null) {
Event.observe(view, "change", f);
Event.observe(view, "blur", f);
}
},
initialize: function() {}
});
var FormView = Class.create();
Object.extend(FormView.prototype,{
rootTG: null,
page: null,
bean: null,
options: null,
views: null,
roles: null,
formUnloadMessage: null,
beforeUnload: null,
dirty: null,
numOfRequests: null,
initialize: function() {
this.views = [];
this.roles = [];
this.dirty = false;
this.numOfRequests = 0;
},
updateDirty: function(msg) {
this.dirty = true;
this.formUnloadMessage = msg;
this.beforeUnload = window.onbeforeunload;
window.onbeforeunload = this.confirmClose.bind(this);
},
resetDirty: function() {
this.dirty = false;
window.onbeforeunload = this.beforeUnload;
},
loadBean: function(beanId) {
this.page.context.loadBean(beanId, this.onLoad.bind(this));
},
onLoad: function() {
},
loadNextBean: function() {
if (this.hasNext()) {
this.page.context.loadNextBean(this.onLoad.bind(this));
}
},
hasNext: function() {
return ( get(this.bean, "last") != null && get(this.bean, "last") != "true" && get(this.bean, "last") != true );
},
loadPrevBean: function() {
if (this.hasPrev()) {
this.page.context.loadPrevBean(this.onLoad.bind(this));
}
},
hasPrev: function() {
return ( get(this.bean, "first") != null && get(this.bean, "first") != "true" && get(this.bean, "first") != true );
},
blurView: function() {
var saveAction = $Action("save");
if (saveAction != null) {
saveAction.focus();
}
},
focusView: function() {
var focusProperty = get(this.options, "focus");
if (focusProperty != null) {
var view = $View(focusProperty);
if (view != null && view.render == ViewElement.RENDER_FORM) {
try {
view.focus();
}
catch (e) {
}
}
}
else
if (this.rootTG != null) {
this.rootTG.focusContent();
}
else {
this.focusFirstChildView(this);
}
},
focusFirstChildView: function(element) {
var childs = element.immediateDescendants();
for (var i = 0;i < childs.length;i ++) {
if (childs[i].id != null && childs[i].id.startsWith("v:")) {
try {
childs[i].focus();
}
catch (e) {
}
return true;
}
else
if (this.focusFirstChildView(childs[i])) {
return true;
}
}
return false;
},
showBean: function(_bean) {
this.bean = _bean;
this.setValues();
this.viewData();
this.resetDirty();
this.page.onLoad();
this.page.onAfterLoad();
},
editBean: function(_bean) {
this.bean = _bean;
this.setValues();
this.editData();
this.focusView();
this.page.onLoad();
this.page.onAfterLoad();
},
setValues: function() {
for (var i = 0;i < this.views.length;i ++) {
var view = this.views[i];
if (view != null) {
debugPrint("property: " + view.property);
view.setValueFromBean(this.bean);
}
}
},
initViewActions: function() {
var viewAction = $Action("view");
if (viewAction != null) {
viewAction.hide();
}
var saveAction = $Action("save");
if (saveAction != null) {
saveAction.hide();
}
var editAction = $Action("edit");
if (editAction != null) {
editAction.show();
}
},
initEditActions: function() {
var viewAction = $Action("view");
if (viewAction != null) {
viewAction.show();
}
var saveAction = $Action("save");
if (saveAction != null) {
saveAction.show();
}
var editAction = $Action("edit");
if (editAction != null) {
editAction.hide();
}
},
initMiscActions: function() {
var nextAction = $Action("next");
if (nextAction != null) {
if (this.hasNext()) {
nextAction.show();
}
else {
nextAction.hide();
}
}
var prevAction = $Action("prev");
if (prevAction != null) {
if (this.hasPrev()) {
prevAction.show();
}
else {
prevAction.hide();
}
}
},
editData: function() {
debugPrint("editData");
PopupManager.deregisterAll();
for (var i = 0;i < this.views.length;i ++) {
var view = this.views[i];
if (view != null) {
view.editValue();
}
}
this.initEditActions();
this.initMiscActions();
this.toggleDependent();
},
toggleDependent: function() {
for (var i = 0;i < this.views.length;i ++) {
var view = this.views[i];
if (view != null) {
view.toggleDependent(false);
}
}
},
viewData: function() {
debugPrint("viewData");
PopupManager.deregisterAll();
for (var i = 0;i < this.views.length;i ++) {
var view = this.views[i];
if (view != null) {
view.showValue();
}
}
this.initViewActions();
this.initMiscActions();
this.toggleDependent();
},
clear: function() {
for (var i = 0;i < this.views.length;i ++) {
var view = this.views[i];
if (view != null) {
view.clearValue();
view.removeClassName(Style.EDIT_MODE);
}
}
this.toggleDependent();
this.page.onClear();
},
setEditMode: function() {
for (var i = 0;i < this.views.length;i ++) {
var view = this.views[i];
if (view != null) {
view.addClassName(Style.EDIT_MODE);
}
}
},
disableFields: function(fields) {
for (var i = 0;i < fields.length;i ++) {
var view = $View(fields[i]);
if (view != null) {
view.disableView();
}
}
},
populate: function() {
this.page.context.populate(this.bean);
this.setEditMode();
},
saveBean: function() {
if (Messages.hasErrors()) {
var msgElts = $("content").getElementsByClassName(Style.ERROR);
if (msgElts != null) {
var tc = null;
var focusElt = null;
for (var i = 0;i < msgElts.length;i ++) {
focusElt = msgElts[i];
var ancestors = msgElts[i].ancestors();
for (var a = 0;a < ancestors.length;a ++) {
if (ancestors[a].id == "content")
break;
else
if (ancestors[a].hasClassName(Style.TAB_CONTENT)) {
var foundTc = ancestors[a - 1];
if (tc == null || tc.no > foundTc.no) {
tc = foundTc;
focusElt = msgElts[i];
}
break;
}
}
}
if (tc != null) {
tc.tg.activate(tc.no);
}
if (focusElt != null) {
focusElt.scrollTo();
}
}
}
else {
this.page.context.saveBean(this.page.onSave.bind(this.page));
}
},
deleteBean: function() {
this.page.context.deleteBean(this.page.onDelete.bind(this.page));
},
createBean: function() {
this.clear();
this.page.context.createBean(this.page.onCreate.bind(this.page));
},
copyBean: function() {
this.clear();
this.page.context.copyBean(this.page.onCopy.bind(this.page));
},
init: function(pg,opts) {
this.page = pg;
this.options = opts;
},
confirmClose: function() {
return this.formUnloadMessage;
},
isReady: function() {
return this.numOfRequests == 0;
}
});
var PopupWin = Class.create();
Object.extend(PopupWin.prototype,{
module: null,
parent: null,
popupWin: null,
top: - 1,
left: - 1,
width: - 1,
heigth: - 1,
layout: "popupList",
title: "Popup",
initialize: function(module,parent,options) {
this.module = module;
this.parent = parent;
Object.extend(this, options);
},
show: function() {
PopupManager.openModalDialog(this.module + "." + this.layout + this.params(), document, this.width, this.heigth, this.top, this.left, true, this.parent, this.modalAction.bind(this));
},
hide: function() {
},
modalAction: function(data) {
this.onAction(null, data);
},
resetReturnValue: function() {
window.returnValue = null;
},
toggle: function() {
if (this.popupWin != null) {
this.hide();
}
else {
this.show();
}
},
onAction: function(event,data) {
},
params: function() {
return "";
}
});
var BackAction = Class.create();
Object.extend(BackAction.prototype, ActionElement.prototype);
Object.extend(BackAction.prototype,{
actionName: "back",
execute: function() {
window.history.back();
},
initialize: function() {}
});
var PopupEntries = Class.create();
Object.extend(PopupEntries.prototype,{
_parent: null,
popupDiv: null,
textInput: null,
popupTableBody: null,
offset: 0,
width: 0,
height: 0,
currentRow: - 1,
cellFuncs: null,
labels: null,
source: null,
initialize: function(parent,options) {
this._parent = parent;
this.labels = [];
this.currentRow = - 1;
this.cellFuncs = [];
push(this.cellFuncs, this.getRowData.bind(this));
Object.extend(this, options);
},
show: function() {
if (this.popupDiv == null)
this.create();
this.currentRow = - 1;
this.textInput.value = "";
this.onChanged("", this.addLabels.bind(this));
try {
Position.clone(this._parent, this.popupDiv,  {
setLeft: true,
setTop: true,
setWidth: false,
setHeight: false
});
}
catch (e) {
}
var offsetWidth = ( this.offset != 0 ) ? ( ( this._parent.getWidth() / this._parent.getWidth() ) * this.offset ) : this._parent.getWidth();
var _afterFinish = this.initTextInput.bind(this);
new Effect.Parallel([new Effect.BlindDown(this.popupDiv, {
sync: true
}), new Effect.Move(this.popupDiv, {
sync: true,
x: offsetWidth + 15,
y: - 15,
mode: "relative"
})], {
duration: .4,
afterFinish: _afterFinish
});
PopupManager.register(this.popupDiv, false);
mvc.kph.onKey(KPH.UP_ARROW_KEYCODE, this.prevRow.bind(this), true);
mvc.kph.onKey(KPH.DOWN_ARROW_KEYCODE, this.nextRow.bind(this), true);
mvc.kph.onKey(KPH.ENTER_KEYCODE, this.enterRow.bind(this), true);
mvc.kph.onKey(KPH.ESC_KEYCODE, this.toggle.bind(this), false);
},
initTextInput: function() {
this.textInput.value = "== Zadáním textu začněte vyhledávat ==";
this.textInput.onfocus = this.onTextFocus.bind(this);
},
onTextFocus: function() {
this.textInput.value = "";
this.textInput.onfocus = null;
},
hide: function() {
PopupManager.deregister(this.popupDiv);
},
toggle: function() {
if (this.popupDiv != null && this.popupDiv.visible()) {
this.hide();
}
else {
this.show();
}
},
getRowData: function(l) {
return l.labelText;
},
rowCreator: function(options) {
var row = elem("tr");
row.addClassName(( ( options.rowNum % 2 ) == 0 ) ? Style.EVEN : Style.ODD);
Event.observe(row, "click", this.onAction.bindAsEventListener(this.source, this.labels[options.rowNum]));
Event.observe(row, "mouseover", this.onMouseOver.bindAsEventListener(this, options.rowNum));
return row;
},
addLabels: function(rows) {
this.currentRow = - 1;
this.labels = rows;
dwr.util.removeAllRows(this.popupTableBody);
dwr.util.addRows(this.popupTableBody, $A(rows), this.cellFuncs,  {
rowCreator: this.rowCreator.bind(this)
});
},
setLabels: function(rows) {
this.labels = rows;
},
getTypedText: function() {
return this.textInput.value;
},
nextRow: function() {
if (this.currentRow != - 1) {
if (this.currentRow < ( this.popupTableBody.rows.length - 1 )) {
this.selectRow(this.currentRow + 1);
}
}
else
if (this.labels != null && this.labels.length != 0) {
this.textInput.blur();
this.selectRow(0);
}
},
prevRow: function() {
if (this.currentRow > 0) {
this.selectRow(this.currentRow - 1);
}
},
onMouseOver: function(event,rowNum) {
this.selectRow(rowNum);
},
enterRow: function() {
if (this.currentRow != - 1) {
this.onAction(null, this.labels[this.currentRow]);
}
},
create: function() {
this.popupDiv = elem("div");
this.popupDiv.addClassName(Style.POPUP_TABLE);
this.popupDiv.hide();
this._parent.up(0).appendChild(this.popupDiv);
var divHeader = this.createHeader();
this.popupDiv.appendChild(divHeader);
var filtDiv = this.createFilter();
this.popupDiv.appendChild(filtDiv);
var tableDiv = this.createTableDiv();
this.popupDiv.appendChild(tableDiv);
},
createHeader: function() {
var divHeader = elem("div");
divHeader.addClassName(Style.POPUP_TABLE_HEADER);
var anchor = elem("a",  {
href: "#"
});
anchor.addClassName(Style.CLOSE_BUTTON);
Event.observe(anchor, "click", this.toggle.bind(this));
divHeader.appendChild(anchor);
var spanX = elem("span");
spanX.innerHTML = "X";
anchor.appendChild(spanX);
return divHeader;
},
createFilter: function() {
var filtDiv = elem("div");
filtDiv.addClassName(Style.POPUP_FILTER);
this.textInput = elem("input",  {
type: "text"
});
this.textInput.onkeyup = this.onTextTyped.bind(this);
filtDiv.appendChild(this.textInput);
return filtDiv;
},
createTableDiv: function() {
var tableDiv = elem("div");
tableDiv.addClassName(Style.POPUP_TABLE_SCROLL);
var table = elem("table");
debugPrint("create popupTableBody");
this.popupTableBody = elem("tbody");
this.popupTableBody.addClassName(Style.POINTER);
table.appendChild(this.popupTableBody);
tableDiv.appendChild(table);
return tableDiv;
},
scrollToRow: function(rowNum) {
var container = this.popupTableBody.up("div");
var element = $(this.popupTableBody.rows[rowNum]);
var tly = exists(element.y) ? element.y : element.offsetTop;
var bry = tly + element.getHeight();
var top = container.scrollTop;
var bottom = container.getHeight() + container.scrollTop;
if (bry > bottom)
container.scrollTop = top + ( bry - bottom ) + 10;
if (tly < top)
container.scrollTop = top - ( top - tly ) - 10;
},
selectRow: function(rowNum) {
if (this.currentRow >= 0 && this.currentRow < this.popupTableBody.rows.length) {
$(this.popupTableBody.rows[this.currentRow]).removeClassName(Style.SELECTED);
$(this.popupTableBody.rows[this.currentRow]).addClassName(( ( this.currentRow % 2 ) == 0 ) ? Style.EVEN : Style.ODD);
}
this.currentRow = rowNum;
$(this.popupTableBody.rows[this.currentRow]).removeClassName(( ( this.currentRow % 2 ) == 0 ) ? Style.EVEN : Style.ODD);
$(this.popupTableBody.rows[this.currentRow]).addClassName(Style.SELECTED);
this.scrollToRow(this.currentRow);
},
onChanged: function(typedText,handler) {
},
onTextTyped: function() {
debugPrint("onTextTyped: " + this.getTypedText());
this.onChanged(this.getTypedText(), this.addLabels.bind(this));
},
onAction: function(event,data) {
},
resetReturnValue: function() {
}
});
var SelectColumn = Class.create();
Object.extend(SelectColumn.prototype, TableColumn.prototype);
Object.extend(SelectColumn.prototype,{
_labels: null,
initialize: function() {
this._labels = [];
},
columnHandler: function(td,options) {
td.addClassName(Style.TEXT_COLUMN);
},
displayHandler: function(value) {
if (this._labels != null && this._labels.length != 0) {
for (var i = 0;i < this._labels.length;i ++) {
var label = this._labels[i];
if (this.hasLabelValue(value, label)) {
return label.labelText;
}
}
}
return "";
},
loadEnumLabels: function() {
this.gridView.getEnumLabels(this.property, this.setLabels.bind(this));
},
setLabels: function(lbls) {
this._labels = lbls;
},
hasLabelValue: function(value,label) {
return ( isBean(value) && get(value, "id") == label.labelValue ) || ( value == label.labelValue );
}
});
var SaveFilter = Class.create();
Object.extend(SaveFilter.prototype, FilterElement.prototype);
Object.extend(SaveFilter.prototype,{
actionName: "saveFilter",
filterName: null,
popup: null,
execute: function() {
if (this.popup == null) {
this.popup = new PopupInput(this, {
onAction: this.onSaveFilter.bind(this),
inputLabel: this.previous("span").previous("span").innerHTML,
buttonLabel: this.previous("span").innerHTML,
size: this.getIntOption("inputSize", 30)
});
}
this.popup.show();
},
activateFilter: function() {
},
onInit: function() {
this.hide();
},
onSaveFilter: function(evt,filterName) {
this.filterName = filterName;
this.gridPage.context.saveFilter(filterName, this.activateFilter.bind(this));
},
initialize: function() {}
});
var Filterbox = Class.create();
Object.extend(Filterbox.prototype, FilterElement.prototype);
Object.extend(Filterbox.prototype,{
actionName: "filterbox",
searchString: null,
searchProperties: null,
execute: function(evt) {
var query = dwr.util.getValue(this);
if (query != this.searchString) {
this.searchString = query;
this.gridPage.view.filterList(this.searchString, this.searchProperties);
}
},
init: function(options) {
var propertyAttr = get(options, "property");
if (propertyAttr != null) {
this.searchProperties = propertyAttr.split(",");
}
this.onkeyup = this.execute.bindAsEventListener(this);
this.focus();
},
initialize: function() {}
});
var GridView = Class.create();
Object.extend(GridView.prototype,{
page: null,
pageInfo: null,
selectedColumn: null,
currentRow: - 1,
nextSelectRow: - 1,
navigationOn: false,
_options: null,
columns: null,
defs: null,
data: null,
tbody: null,
initialize: function() {
this.columns = [];
this.defs = [];
this.data = [];
},
init: function(opt) {
this._options = opt;
},
showData: function(_data_) {
this.data = _data_;
this.resetPosition();
dwr.util.replaceHtmlRows(this.next("tbody"), $A(this.data), this.defs,  {
rowCreator: this.evenOddRowCreator.bind(this),
cellCreator: this.cellCreator.bind(this),
escapeHtml: false
});
this.tbody = this.next("tbody");
this.setPosition();
this.page.onAfterLoad();
},
addData: function(_data_) {
this.data = _data_;
dwr.util.addHtmlRows(this.next("tbody"), $A(this.data), this.defs,  {
rowCreator: this.evenOddRowCreator.bind(this),
cellCreator: this.cellCreator.bind(this),
escapeHtml: false
});
},
showFooter: function(_data_) {
dwr.util.replaceHtmlRows(this.next("tfoot"), $A(_data_), this.defs,  {
rowCreator: this.sumRowCreator.bind(this),
cellCreator: this.sumCellCreator.bind(this),
escapeHtml: false
});
},
addColumn: function(property) {
var column = $Column(property);
if (column != null) {
push(this.columns, column);
push(this.defs, this.getData.bind(this, column));
}
},
loadList: function() {
if (Options.hasOptionEnabled(this._options, "navigation", true)) {
mvc.kph.onKey(KPH.UP_ARROW_KEYCODE, this.prevRow.bind(this), true);
mvc.kph.onKey(KPH.DOWN_ARROW_KEYCODE, this.nextRow.bind(this), true);
mvc.kph.onKey(KPH.PAGE_UP_KEYCODE, this.prevPage.bind(this), false);
mvc.kph.onKey(KPH.PAGE_DOWN_KEYCODE, this.nextPage.bind(this), false);
}
dwr.engine.beginBatch();
this.page.context.loadList(this.showData.bind(this));
this.page.context.loadPageInfo(this.onLoad.bind(this));
dwr.engine.endBatch();
},
submitFilter: function(bean) {
dwr.engine.beginBatch();
this.page.context.submitFilter(bean, this.showData.bind(this));
this.page.context.loadPageInfo(this.onLoadFilter.bind(this));
dwr.engine.endBatch();
},
cancelFilters: function() {
dwr.engine.beginBatch();
this.page.context.submitFilter(null, this.showData.bind(this));
this.page.context.loadPageInfo(this.onCancelFilters.bind(this));
dwr.engine.endBatch();
},
filterList: function(query,properties) {
debugPrint("query[" + properties + "]: " + query);
dwr.engine.beginBatch();
this.page.context.filterList(query, properties, this.showData.bind(this));
this.page.context.loadPageInfo(this.onLoad.bind(this));
dwr.engine.endBatch();
},
invokeFilter: function(name,params) {
dwr.engine.beginBatch();
this.page.context.invokeFilter(name, params, this.showData.bind(this));
this.page.context.loadPageInfo(this.onLoad.bind(this));
dwr.engine.endBatch();
},
filterPage: function(page) {
this.navigationOn = false;
this.pageInfo.page = this.pageInfo.cacheOffset + page;
dwr.engine.beginBatch();
this.page.context.filterPage(this.pageInfo.page, this.showData.bind(this));
this.page.context.loadPageInfo(this.onLoad.bind(this));
dwr.engine.endBatch();
},
filterColumn: function(column,direction) {
dwr.engine.beginBatch();
this.page.context.filterColumn(column, direction, this.showData.bind(this));
this.page.context.loadPageInfo(this.onLoad.bind(this));
dwr.engine.endBatch();
},
evenOddRowCreator: function(options) {
var row = htmlTableRow();
row.rowNum = options.rowNum;
var counter = options.rowNum;
if (Options.hasOptionEnabled(this._options, "group", false)) {
if (options.counter == null)
options.counter = 0;
if (get(options.rowData, "label") == true) {
row.addClassName(Style.REPORT_GROUP_LABEL);
options.counter = 0;
return row;
}
else
if (get(options.rowData, "sum") == true) {
row.addClassName(Style.REPORT_GROUP_SUM);
return row;
}
counter = options.counter;
options.counter = options.counter + 1;
}
row.addClassName(( ( counter % 2 ) == 0 ) ? Style.EVEN : Style.ODD);
if (Options.hasOptionEnabled(this._options, "navigation", true)) {
row.addClassName("grid-table-row");
row.addClassName(Style.POINTER);
}
return row;
},
cellCreator: function(options) {
var td = htmlTableCell();
td.rowNum = options.rowNum;
td.cellNum = options.cellNum;
if (Options.hasOptionEnabled(this._options, "group", false)) {
var groupPos = get(options.rowData, "groupPos");
var groupCount = get(options.rowData, "groupCount");
if (get(options.rowData, "label") == true) {
if (groupPos != null && ( options.cellNum + 1 ) < groupPos) {
td.innerHTML = "&nbsp;";
return td;
}
else
if (( options.cellNum + 1 ) == groupPos) {
this.setColSpan(options, td);
}
else {
return null;
}
}
else
if (get(options.rowData, "sum") == true) {
if (groupPos != null && ( options.cellNum + 1 ) < groupPos) {
td.innerHTML = "&nbsp;";
return td;
}
else
if (( options.cellNum + 1 ) == groupPos) {
this.setColSpan(options, td);
}
else
if (options.cellNum < groupCount) {
return null;
}
}
else
if (options.cellNum == 0) {
this.setColSpan(options, td);
td.innerHTML = "&nbsp;";
return td;
}
else
if (options.data == null || options.data == "") {
return null;
}
}
else
if (Options.hasOptionEnabled(this._options, "navigation", true)) {
td.addClassName("grid-table-row");
if (this.columns[options.cellNum].property != null) {
td.addClassName("grid-table-cell");
}
}
this.columns[options.cellNum].columnHandler(td, options);
return td;
},
sumRowCreator: function(options) {
var row = htmlTableRow();
row.rowNum = options.rowNum;
row.addClassName(Style.REPORT_SUM);
return row;
},
sumCellCreator: function(options) {
var td = htmlTableCell();
td.rowNum = options.rowNum;
td.cellNum = options.cellNum;
var groupCount = get(options.rowData, "groupCount");
if (options.cellNum == 0) {
this.setColSpan(options, td);
}
else
if (options.cellNum < groupCount) {
return null;
}
this.columns[options.cellNum].columnHandler(td, options);
return td;
},
setRowSpan: function(options,td) {
var rowspan = get(options.rowData, "rowSpan");
if (rowspan != null && rowspan != 0) {
td.rowSpan = rowspan;
}
},
setColSpan: function(options,td) {
var colspan = get(options.rowData, "colSpan");
if (colspan != null && colspan != 0) {
td.colSpan = colspan;
}
},
disableLinks: function() {
put(this._options, "useLinks", "false");
},
getData: function(column,row) {
if (column.property != null) {
var propertyValue = getNestedBeanProperty(row, column.property);
if (propertyValue != null) {
var data = column.displayHandler(propertyValue);
if (Options.hasOptionEnabled(this._options, "useLinks", false)) {
var url = this.page.createRowLink(this.page.gridModule, row, "id");
var anchor = elem("a",  {
href: url
});
anchor.innerHTML = data;
return anchor;
}
else
if (Options.hasOptionEnabled(column.options, "useLink", false) || Options.hasOption(column.options, "linkModule")) {
var url = this.page.createRowLink(Options.getStrOption(column.options, "linkModule", this.page.gridModule), row, Options.getStrOption(column.options, "linkProperty", "id"));
var anchor = elem("a",  {
href: url
});
anchor.innerHTML = data;
return anchor;
}
return data;
}
return "";
}
return null;
},
onLoadFilter: function(pgInfo) {
var formFilter = $Filter("formFilter");
if (formFilter != null) {
formFilter.activateFilter();
}
this.onLoad(pgInfo);
},
onCancelFilters: function(pgInfo) {
var cancelFilters = $Filter("cancelFilters");
if (cancelFilters != null) {
cancelFilters.activateFilter();
}
this.onLoad(pgInfo);
},
onLoad: function(pgInfo) {
debugPrint("resetPaging: page=" + pgInfo.page + " pageCount=" + pgInfo.pageCount);
this.pageInfo = pgInfo;
this.resetPaging();
this.loadNextPage();
},
loadNextPage: function() {
if (this.pageInfo.multiOn) {
if (( this.pageInfo.page + 1 ) < this.pageInfo.pageCount) {
var lastPage = ( this.pageInfo.page + 2 ) == this.pageInfo.pageCount;
dwr.engine.beginBatch();
this.page.context.loadNextPage(this.addData.bind(this));
this.page.context.loadPageInfo(this.onLoad.bind(this));
if (lastPage) {
this.page.context.loadPageSummary(this.showFooter.bind(this));
}
dwr.engine.endBatch();
}
}
},
resetPaging: function() {
},
onClickRow: function(event) {
var cell = event.element();
this.page.onEnterRow(this.data[cell.rowNum]);
},
onDeleteRow: function(rowNum) {
if (this.deleteConfirmed()) {
put(this.data[rowNum], "id", 0);
dwr.engine.beginBatch();
this.page.context.deleteRow(rowNum, this.showData.bind(this));
this.page.context.loadPageInfo(this.onLoad.bind(this));
dwr.engine.endBatch();
}
return false;
},
deleteConfirmed: function() {
var confirmSpan = $("confirmDelete:" + this.page.module);
if (confirmSpan != null && confirmSpan.innerHTML != "") {
return confirm(confirmSpan.innerHTML);
}
return true;
},
nextRow: function() {
if (this.navigationOn) {
this.page.onNavigationStart();
if (this.currentRow != - 1) {
if (this.currentRow < ( this.tbody.rows.length - 1 )) {
this.selectRow(this.currentRow + 1, true);
}
else {
this.nextPage();
}
}
else
if (this.data != null && this.data.length != 0) {
this.selectRow(0, true);
}
}
return false;
},
prevRow: function() {
if (this.navigationOn) {
if (this.currentRow > 0) {
this.selectRow(this.currentRow - 1, true);
}
else {
this.prevPage();
}
}
return false;
},
nextPage: function() {
if (this.navigationOn && this.pageInfo != null && this.pageInfo.pagingOn) {
var pgFilter = $Filter("paging");
if (pgFilter != null) {
pgFilter.next();
}
}
return false;
},
prevPage: function() {
if (this.navigationOn && this.pageInfo != null && this.pageInfo.pagingOn) {
var pgFilter = $Filter("paging");
if (pgFilter != null) {
pgFilter.prev();
}
}
return false;
},
onMouseOver: function(event) {
var cell = event.element();
if (this.currentRow != cell.rowNum) {
this.selectRow(cell.rowNum, false);
}
return false;
},
enterRow: function() {
if (this.currentRow != - 1) {
this.page.onEnterRow(this.data[this.currentRow]);
}
return false;
},
resetPosition: function() {
this.currentRow = - 1;
},
setPosition: function() {
this.navigationOn = true;
if (this.nextSelectRow != - 1) {
this.selectRow(this.nextSelectRow, true);
this.nextSelectRow = - 1;
}
},
selectRow: function(rowNum,navigate) {
if (this.currentRow >= 0 && this.currentRow < this.tbody.rows.length) {
$(this.tbody.rows[this.currentRow]).removeClassName(Style.SELECTED);
$(this.tbody.rows[this.currentRow]).addClassName(( ( this.currentRow % 2 ) == 0 ) ? Style.EVEN : Style.ODD);
}
this.currentRow = rowNum;
if (this.currentRow >= 0 && this.currentRow < this.tbody.rows.length) {
$(this.tbody.rows[this.currentRow]).removeClassName(( ( this.currentRow % 2 ) == 0 ) ? Style.EVEN : Style.ODD);
$(this.tbody.rows[this.currentRow]).addClassName(Style.SELECTED);
if (navigate) {
this.page.onNavigateRow(this.data[rowNum]);
}
else {
this.page.onSelectRow(this.data[rowNum]);
}
}
},
getPath: function() {
return this.page.path;
},
setSelectedColumn: function(column) {
this.selectedColumn = column;
},
getEnumLabels: function(property,handler) {
this.page.context.getEnumLabels(property, handler);
}
});
var PopupColumn = Class.create();
Object.extend(PopupColumn.prototype, TableColumn.prototype);
Object.extend(PopupColumn.prototype,{
initialize: function() {
},
columnHandler: function(td,options) {
td.addClassName(Style.TEXT_COLUMN);
},
displayHandler: function(value) {
if (value != null) {
var label = value;
return label.labelText;
}
return "";
}
});
var EnumTableElement = Class.create();
Object.extend(EnumTableElement.prototype, ViewElement.prototype);
Object.extend(EnumTableElement.prototype,{
_labels: null,
editUI: null,
emptyMsg: null,
cellFuncs: null,
popup: null,
tableWidth: 0,
initialize: function() {
this._labels = [];
this.cellFuncs = [];
},
setViewValue: function() {
this.showRows();
},
setFormValue: function() {
this.setViewValue();
},
clearUI: function() {
this.cellFuncs = [];
if (this.editUI == null) {
this.emptyMsg = this.up("table").next("p");
if (this.tableWidth != 0) {
this.up("table").setAttribute("width", this.tableWidth);
}
this.editUI = this.up("table").previous("p").down(0);
this.popup = new PopupUI(this.editUI, {
source: this,
onAction: this.onNewEntryClicked,
onChanged: this.loadEnumLabels.bind(this),
offset: this.tableWidth
});
Event.observe(this.editUI, "click", this.popup.toggle.bind(this.popup));
}
this.editUI.hide();
this.emptyMsg.hide();
this.up("table").hide();
},
createEditUI: function() {
push(this.cellFuncs, this.getData.bind(this));
push(this.cellFuncs, this.getDelete.bind(this));
this.editUI.show();
this.setFormValue();
},
createViewUI: function() {
push(this.cellFuncs, this.getData.bind(this));
this.setViewValue();
},
bindChangeListener: function() {
},
onNewRow: function(value) {
var row = value;
if (! this.containsEnum(row)) {
push(this._value, row.labelValue);
this.context.addEnumEntryRow(this.property, row.labelValue);
this.showRows();
}
},
onDeleteRow: function(rowNum) {
this.context.deleteEntryRow(this.property, rowNum);
splice(this._value, rowNum);
this.showRows();
},
onClearForm: function(value) {
},
evenOddRowCreator: function(options) {
var row = elem("tr");
row.addClassName(( ( options.rowNum % 2 ) == 0 ) ? Style.EVEN : Style.ODD);
return row;
},
cellCreatorCallback: function(options) {
var td = elem("td");
if (options.cellNum == 1) {
var nav = elem("img",  {
src: this.page.path + Icons.REMOVE
});
nav.addClassName(Style.POINTER);
Event.observe(nav, "click", this.onDeleteRow.bind(this, options.rowNum));
Object.extend(td.style,  {
width: "1%"
});
td.appendChild(nav);
}
return td;
},
getData: function(row) {
var l = this.getEnumLabel(row);
if (l != null) {
return l.labelText;
}
return "";
},
getDelete: function(row) {
return null;
},
afterInit: function(opt) {
var width = get(opt, "width");
if (width != null) {
this.tableWidth = width;
}
},
showRows: function() {
dwr.util.removeAllRows(this);
if (length(this._value) > 0) {
this.emptyMsg.hide();
this.up(0).removeClassName(Style.HIDDEN);
this.up(0).show();
dwr.util.addRows(this, $A(this._value), this.cellFuncs,  {
rowCreator: this.evenOddRowCreator.bind(this),
cellCreator: this.cellCreatorCallback.bind(this)
});
}
else {
this.up(0).hide();
this.emptyMsg.show();
}
},
loadEnumLabels: function(typedText,handler) {
this.context.getFilteredEnumLabels(this.property, typedText, handler);
},
hasLabelValue: function(val,label) {
return ( isBean(val) && get(val, "id") == label.labelValue ) || ( val == label.labelValue );
},
getEnumLabel: function(val) {
for (var j = 0;j < this._labels.length;j ++) {
if (this.hasLabelValue(val, this._labels[j])) {
return this._labels[j];
}
}
return null;
},
containsEnum: function(row) {
var values = this._value;
for (var i = 0;i < values.length;i ++) {
if (this.hasLabelValue(values[i], row)) {
return true;
}
}
return false;
},
onNewEntryClicked: function(event,label) {
var element = event.element();
element.fire("entry:insert",  {
source: this,
value: label,
originalEvent: event
});
},
onDeleteEntryClicked: function(event,rowIndex) {
var element = event.element();
element.fire("entry:delete",  {
source: this,
rowNum: rowIndex,
originalEvent: event
});
}
});
var SelectElement = Class.create();
Object.extend(SelectElement.prototype, ViewElement.prototype);
Object.extend(SelectElement.prototype,{
_labels: null,
getSimpleValue: function() {
if (this._labels != null && this._labels.length != 0) {
for (var i = 0;i < this._labels.length;i ++) {
var label = this._labels[i];
if (this.hasLabelValue(label)) {
return label.labelValue;
}
}
}
return "";
},
setViewValue: function(val) {
if (this._labels != null && this._labels.length != 0) {
for (var i = 0;i < this._labels.length;i ++) {
var label = this._labels[i];
if (this.hasLabelValue(label)) {
this.setValueContent(label.labelText);
return;
}
}
}
this.setEmptyValue();
},
hasLabelValue: function(label) {
if (label == null) {
return ( this._value == null || this._value == "" );
}
if (isBean(this._value)) {
return ( get(this._value, "id") == label.labelValue || get(this._value, "poradi") == label.labelValue || get(this._value, "labelValue") == label.labelValue );
}
return ( this._value == label.labelValue );
},
setFormValue: function() {
if (isBean(this._value)) {
if (get(this._value, "id") != null) {
dwr.util.setValue(this.property, get(this._value, "id"));
}
else
if (get(this._value, "poradi") != null) {
dwr.util.setValue(this.property, get(this._value, "poradi"));
}
else
if (get(this._value, "labelValue") != null) {
dwr.util.setValue(this.property, get(this._value, "labelValue"));
}
}
else {
dwr.util.setValue(this.property, this._value);
}
},
setLabels: function(_labels) {
this._labels = _labels;
this.setEnumLabels();
},
safeValue: function(val) {
if (val == null && ! this.hasOptionEnabled("allowNull", false)) {
if (this._labels != null && this._labels.length != 0) {
return this._labels[0];
}
}
return val;
},
bindChangeListener: function() {
var view = $(this.property);
if (view != null) {
view.onchange = this.changeValue.bindAsEventListener(this);
}
},
createEditUI: function() {
var sel = elem("select",  {
id: this.property
});
this.setAttr(sel, "size", null);
this.setAttr(sel, "multiple", null);
this.setAttr(sel, "title", null);
this.appendChild(sel);
if (this._labels == null) {
this.context.getEnumLabels(this.getRealProperty(), this.setLabels.bind(this));
}
else {
this.setEnumLabels();
}
},
setEnumLabels: function() {
if (this.hasOptionEnabled("allowNull", false)) {
var optionElt = elem("option",  {
id: this.property + ".null",
value: null
});
if (this.hasLabelValue(null)) {
optionElt.selected = true;
}
this.down("select").appendChild(optionElt);
}
if (this._labels != null && this._labels.length != 0) {
for (var i = 0;i < this._labels.length;i ++) {
var label = this._labels[i];
var optionElt = elem("option",  {
id: this.property + "." + label.labelValue,
value: label.labelValue
});
optionElt.innerHTML = label.labelText;
if (this.hasLabelValue(label)) {
optionElt.selected = true;
}
this.down("select").appendChild(optionElt);
}
}
},
initialize: function() {}
});
var PrevAction = Class.create();
Object.extend(PrevAction.prototype, ActionElement.prototype);
Object.extend(PrevAction.prototype,{
actionName: "prev",
execute: function() {
this.formPage.view.loadPrevBean();
},
initialize: function() {}
});
var NestedViewElement = Class.create();
Object.extend(NestedViewElement.prototype, ViewElement.prototype);
var TabElement = Class.create();
Object.extend(TabElement.prototype,{
tg: null,
no: 0,
focusProperty: null,
enabled: true,
init: function(_tg,_no) {
this.tg = _tg;
this.no = _no;
this.enabled = true;
},
enableView: function() {
if (! this.enabled) {
this.tg.tc[this.no].show();
this.tg.ta[this.no].show();
this.enabled = true;
}
},
disableView: function() {
if (this.enabled) {
this.tg.ta[this.no].hide();
this.tg.tc[this.no].hide();
this.enabled = false;
}
},
activate: function() {
this.tg.activate(this.no);
},
initialize: function() {}
});
var DeleteAction = Class.create();
Object.extend(DeleteAction.prototype, ActionElement.prototype);
Object.extend(DeleteAction.prototype,{
actionName: "delete",
execute: function() {
this.formPage.view.deleteBean();
},
initialize: function() {}
});
var SaveAction = Class.create();
Object.extend(SaveAction.prototype, ActionElement.prototype);
Object.extend(SaveAction.prototype,{
actionName: "save",
execute: function() {
this.formPage.view.saveBean();
},
initialize: function() {}
});
var EntriesRowElement = Class.create();
Object.extend(EntriesRowElement.prototype, ViewElement.prototype);
Object.extend(EntriesRowElement.prototype,{
row: null,
parent: null,
nodes: null,
initialize: function() {
this.nodes = [];
},
decRowNumber: function() {
this.row = this.row - 1;
for (var i = 0;i < this.nodes.length;i ++) {
this.nodes[i].decRowNumber();
}
},
createEditUI: function() {
for (var i = 0;i < this.nodes.length;i ++) {
this.nodes[i].createEditUI();
this.nodes[i].hasUI = true;
}
this.hasUI = true;
}
});
var FormPageWithGrid = Class.create();
Object.extend(FormPageWithGrid.prototype, FormPage.prototype);
Object.extend(FormPageWithGrid.prototype,{
grid: null,
onSave: function() {
this.grid.view.loadList();
Messages.enabled = false;
this.view.createBean();
this.view.focusView();
},
onDelete: function() {
this.grid.view.loadList();
},
onClear: function() {
this.grid.view.selectRow(- 1, false);
},
initialize: function() {}
});
var AlphabetFilter = Class.create();
Object.extend(AlphabetFilter.prototype, FilterElement.prototype);
Object.extend(AlphabetFilter.prototype,{
actionName: "alphabet",
searchProperties: null,
execute: function(letter) {
var anchors = this.getElementsByTagName("a");
for (var i = 0;i < anchors.length;i ++) {
if (anchors[i].innerHTML == letter) {
$(anchors[i]).addClassName(Style.HIGHLIGHT);
}
else {
$(anchors[i]).removeClassName(Style.HIGHLIGHT);
}
}
var filter = letter;
if (filter == "#") {
filter = "0|1|2|3|4|5|6|7|8|9";
}
else
if (filter == $("alphabet:all").innerHTML) {
filter = "";
}
var search = $Filter("search");
if (search != null) {
search.clear();
}
this.gridPage.view.filterList(filter, this.searchProperties);
},
clear: function() {
var anchors = this.getElementsByTagName("a");
for (var i = 0;i < anchors.length;i ++) {
$(anchors[i]).removeClassName(Style.HIGHLIGHT);
}
},
init: function(options) {
var propertyAttr = get(options, "property");
if (propertyAttr != null) {
this.searchProperties = propertyAttr.split(",");
}
var anchors = this.getElementsByTagName("a");
for (var i = 0;i < anchors.length;i ++) {
anchors[i].onclick = this.execute.bind(this, anchors[i].innerHTML);
}
},
initialize: function() {}
});
var GoUpAction = Class.create();
Object.extend(GoUpAction.prototype, ActionElement.prototype);
Object.extend(GoUpAction.prototype,{
actionName: "up",
execute: function() {
this.onclick();
},
useDefaultOnclick: function() {
return true;
},
initialize: function() {}
});
var PopupElement = Class.create();
Object.extend(PopupElement.prototype, SelectElement.prototype);
Object.extend(PopupElement.prototype,{
popup: null,
_labelMap: null,
initialize: function() {
this.popup = null;
this._labelMap = [];
},
doEnableView: function(setFocus) {
$(this.property).enable();
$(this.property).next(0).show();
$(this.property).next(1).show();
},
doDisableView: function() {
$(this.property).disable();
$(this.property).next(0).hide();
$(this.property).next(1).hide();
},
createEditUI: function() {
if (this.popup == null) {
this.popup = new PopupUI(this, {
source: this,
onAction: this.onSelect,
onChanged: this.loadEnumLabels.bind(this)
});
}
var inputElt = elem("input",  {
type: "text",
id: this.property
});
inputElt.readOnly = true;
inputElt.addClassName(Style.READONLY);
this.setAttr(inputElt, "size", null);
this.setAttr(inputElt, "title", null);
this.appendChild(inputElt);
var popupElt = elem("img",  {
src: this.page.path + Icons.POPUP,alt: ""
});
popupElt.addClassName(Style.POINTER);
Event.observe(popupElt, "click", this.popup.toggle.bind(this.popup));
this.appendChild(popupElt);
var cleanElt = elem("img",  {
src: this.page.path + Icons.CLEAN,alt: ""
});
Event.observe(cleanElt, "click", this.onClearValue.bind(this));
cleanElt.addClassName(Style.POINTER);
this.appendChild(cleanElt);
this.setFormValue();
},
safeValue: function(val) {
return val;
},
setViewValue: function() {
if (this._value != null) {
var labelText = ( this._value ).labelText;
if (labelText == "") {
var label = get(this._labelMap, ( this._value ).labelValue);
if (label != null) {
labelText = label.labelText;
}
}
this.setValueContent(labelText);
}
else {
this.setEmptyValue();
}
},
setFormValue: function() {
if (this._value != null) {
var labelText = ( this._value ).labelText;
if (labelText == "") {
var label = get(this._labelMap, ( this._value ).labelValue);
if (label != null) {
labelText = label.labelText;
}
}
dwr.util.setValue(this.property, labelText);
}
else {
dwr.util.setValue(this.property, "");
}
},
onSelect: function(event,row) {
debugPrint("popup.onSelect: clicked");
if (row != null) {
debugPrint("row: " + Object.toJSON(row));
dwr.util.setValue(this.property, row.labelText);
put(this._labelMap, row.labelValue, row);
this.setNewValue(row);
this.context.setProperty(this.property, row.labelValue);
}
this.popup.hide();
},
bindChangeListener: function() {
},
onClearValue: function() {
this.clearValue();
this.context.setProperty(this.property, null);
},
loadEnumLabels: function(typedText,handler) {
this.context.getFilteredEnumLabels(this.property, typedText, handler);
},
getSimpleValue: function() {
if (this._value != null) {
return ( this._value ).labelValue;
}
return "";
}
});
var TimeColumn = Class.create();
Object.extend(TimeColumn.prototype, TableColumn.prototype);
Object.extend(TimeColumn.prototype,{
columnHandler: function(td,options) {
td.addClassName(Style.DATE_COLUMN);
},
displayHandler: function(value) {
return printDate(value, "%H:%M");
},
initialize: function() {}
});
var NewAction = Class.create();
Object.extend(NewAction.prototype, ActionElement.prototype);
Object.extend(NewAction.prototype,{
actionName: "new",
execute: function() {
if (! this.formPage.view.dirty || confirm(this.formPage.view.confirmClose())) {
this.formPage.view.createBean();
}
},
initialize: function() {}
});
var CancelFilters = Class.create();
Object.extend(CancelFilters.prototype, FilterElement.prototype);
Object.extend(CancelFilters.prototype,{
actionName: "cancelFilters",
execute: function() {
this.gridPage.view.cancelFilters();
},
activateFilter: function() {
this.hide();
var filterName = get(this.options, "filters");
if (filterName == null) {
filterName = "formFilter";
}
var formFilter = $Filter(filterName);
if (formFilter != null) {
formFilter.removeClassName(Style.FORM_FILTER_ACTIVE);
formFilter.addClassName(Style.FORM_FILTER);
}
var saveFilter = $Filter("saveFilter");
if (saveFilter != null) {
saveFilter.hide();
}
},
onInit: function() {
this.addClassName(Style.FORM_FILTER_CANCEL);
this.hide();
},
initialize: function() {}
});
var GridPage = Class.create();
Object.extend(GridPage.prototype,{
context: null,
view: null,
module: null,
gridModule: null,
path: null,
initContext: function(_context,_module,_path) {
this.module = _module;
this.gridModule = _module;
this.path = _path;
this.context = _context;
this.context.init(this.onInit.bind(this));
},
onInit: function() {
this.view.loadList();
},
onAfterLoad: function() {
document.delegate("grid:search", this.onSearchTyping.bindAsEventListener(this));
if (Options.hasOptionEnabled(this.view._options, "navigation", true)) {
document.delegate("mouseover",  {
selector: ".grid-table-row",
handler: this.view.onMouseOver.bindAsEventListener(this.view)
});
document.delegate("click",  {
selector: ".grid-table-cell",
handler: this.view.onClickRow.bindAsEventListener(this.view)
});
}
dwr.engine.setActiveReverseAjax(true);
if ($("loading") != null)
$("loading").hide();
},
createGrid: function(opts,source) {
debugPrint("createGrid: module=" + this.module);
this.view = $Grid(this.module);
Object.extend(this.view, source);
this.view.initialize();
this.view.init(opts);
this.view.page = this;
},
createTable: function() {
debugPrint("createTable: module=" + this.module);
},
createAction: function(actionId,opts,source) {
var action = $Action(actionId);
if (action != null) {
debugPrint("createAction: id=" + actionId);
Object.extend(action, source);
action.initialize();
action.gridPage = this;
action.context = this.context;
action.init(opts);
}
},
createFilter: function(filterId,options,source) {
var filterName = get(options, "name");
if (filterName == null) {
filterName = filterId;
}
debugPrint("createFilter: id=" + filterId + ", name=" + filterName);
var filter = $Filter(filterId);
if (filter != null) {
Object.extend(filter, source);
filter.initialize();
filter.gridPage = this;
filter.context = this.context;
filter.init(options);
}
},
createColumn: function(options,source) {
var column;
var property = get(options, "property");
if (property != null) {
debugPrint("createColumn: property=" + property);
column = $Column(property);
}
else {
var id = get(options, "id");
debugPrint("createAction: id=" + id);
column = $Column(id);
}
if (column != null) {
Object.extend(column, source);
column.initialize();
column.gridView = this.view;
column.init(options);
var sortable = get(options, "sortable");
if (sortable == "on" || sortable == "true") {
column.initHeader();
}
}
},
onNavigationStart: function() {
var search = $Filter("search");
if (search != null) {
search.blur();
search.suspend();
}
mvc.kph.onKey(KPH.ENTER_KEYCODE, this.view.enterRow.bind(this.view), true);
},
onSelectRow: function(row) {
},
onNavigateRow: function(row) {
},
onEnterRow: function(row) {
window.location = this.createRowLink(this.gridModule, row, "id");
},
createRowLink: function(_module,_row,property) {
var params = "";
if ($Table(this.module).previous("span") != null) {
params = $Table(this.module).previous("span").innerHTML;
if (params != null && params != "") {
params = "&" + params;
}
}
return this.path + "/" + _module + ".form?" + _module + "Id=" + get(_row, property) + params;
},
onSearchTyping: function(event) {
var element = get(event.memo, "source");
element.execute();
var originalEvent = get(event.memo, "originalEvent");
if (originalEvent != null) {
originalEvent.stop();
}
event.stop();
},
initialize: function() {}
});
var PagingFilter = Class.create();
Object.extend(PagingFilter.prototype, FilterElement.prototype);
Object.extend(PagingFilter.prototype,{
actionName: "paging",
currentPage: 0,
execute: function(page,reload) {
$("page:" + ( this.currentPage + 1 )).removeClassName(Style.HIGHLIGHT);
this.currentPage = page;
if (! reload) {
$("page:" + ( this.currentPage + 1 )).addClassName(Style.HIGHLIGHT);
}
this.gridPage.view.filterPage(page);
},
init: function(options) {
this.gridPage.view.resetPaging = this.onLoad.bind(this);
},
onLoad: function() {
var content = this.down("a").next("span");
$("page:prev").hide();
content.innerHTML = "";
$("page:next").hide();
this.currentPage = this.gridPage.view.pageInfo.page - this.gridPage.view.pageInfo.cacheOffset;
if (this.gridPage.view.pageInfo.pageCount > 1 || this.gridPage.view.pageInfo.cacheOffset > 0) {
if (this.gridPage.view.pageInfo.cacheOffset > 0 || this.currentPage > 0) {
$("page:prev").onclick = this.prev.bind(this);
$("page:prev").show();
}
content.appendChild(document.createTextNode("\u00a0\u00a0"));
for (var i = 0;i < this.gridPage.view.pageInfo.pageCount;i ++) {
var anchorId = "page:" + ( i + 1 );
var anchor = elem("a",  {
href: "#",
id: anchorId
});
anchor.innerHTML = "" + ( i + this.gridPage.view.pageInfo.cacheOffset + 1 );
anchor.onclick = this.execute.bind(this, i, false);
content.appendChild(anchor);
content.appendChild(document.createTextNode("\u00a0"));
}
content.appendChild(document.createTextNode("\u00a0"));
$("page:" + ( this.currentPage + 1 )).addClassName(Style.HIGHLIGHT);
if (this.gridPage.view.pageInfo.hasMore || this.currentPage < ( this.gridPage.view.pageInfo.pageCount - 1 )) {
$("page:next").onclick = this.next.bind(this);
$("page:next").show();
}
}
},
next: function() {
if (this.currentPage < ( this.gridPage.view.pageInfo.pageCount - 1 )) {
this.gridPage.view.nextSelectRow = 0;
this.execute(this.currentPage + 1, false);
return true;
}
else
if (this.gridPage.view.pageInfo.hasMore) {
this.gridPage.view.nextSelectRow = 0;
this.execute(this.currentPage + 1, true);
return true;
}
return false;
},
prev: function() {
if (this.currentPage > 0) {
this.gridPage.view.nextSelectRow = this.gridPage.view.pageInfo.pageSize - 1;
this.execute(this.currentPage - 1, false);
return true;
}
else
if (this.gridPage.view.pageInfo.cacheOffset > 0) {
this.gridPage.view.nextSelectRow = this.gridPage.view.pageInfo.pageSize - 1;
this.execute(this.currentPage - 1, true);
return true;
}
return false;
},
initialize: function() {}
});
var SearchFilter = Class.create();
Object.extend(SearchFilter.prototype, FilterElement.prototype);
Object.extend(SearchFilter.prototype,{
actionName: "search",
filterInput: null,
searchString: null,
searchProperties: null,
lastTypedText: "",
pollInterval: 0.3,
pe: null,
auto: null,
execute: function() {
var query = dwr.util.getValue(this.filterInput).replace('*', '%');
if (query != this.searchString) {
this.searchString = query;
this.gridPage.view.filterList(this.searchString, this.searchProperties);
}
var alphabet = $Filter("alphabet");
if (alphabet != null) {
alphabet.clear();
}
},
init: function(opt) {
this.options = opt;
var propertyAttr = get(this.options, "property");
if (propertyAttr != null) {
this.searchProperties = propertyAttr.split(",");
}
this.createFilterInput(this.options);
},
createFilterInput: function(options) {
this.filterInput = elem("input",  {
type: "text",
size: this.getIntOption("size", 20)
});
this.filterInput.observe("keyup", this.onTyping.bindAsEventListener(this));
this.appendChild(this.filterInput);
this.filterInput.focus();
if (Options.hasOptionEnabled(this.options, "autocomplete", false)) {
var autompleteDiv = elem("div");
autompleteDiv.addClassName(Style.AUTOCOMPLETE);
this.appendChild(autompleteDiv);
var array = [];
this.auto = new Autocompleter.Local(this.filterInput,autompleteDiv,array, {
frequency: 0.3,
autoSelect: true
});
this.auto.getUpdatedChoices = this.updateChoices.bind(this);
}
},
updateChoices: function() {
var query = dwr.util.getValue(this.filterInput);
this.gridPage.context.autocomplete(query, this.onAutocomplete.bind(this));
},
onAutocomplete: function(result) {
var query = dwr.util.getValue(this.filterInput);
if (( result.length != 1 ) || ( result[0] != query )) {
this.auto.updateChoices(this.decorateChoices(result));
}
},
decorateChoices: function(array) {
var ret = [];
var entry = this.auto.getToken();
for (var i = 0;i < array.length && ret.length < this.auto.options.choices;i ++) {
var elem = array[i];
push(ret, "<li><strong>" + elem.substr(0, entry.length) + "</strong>" + elem.substr(entry.length) + "</li>");
}
return "<ul>" + ret.join('') + "</ul>";
},
onTyping: function(event) {
if (this.pe == null) {
this.pe = new PeriodicalExecuter(this.poll.bind(this),this.pollInterval);
}
},
poll: function(executer) {
var typedText = dwr.util.getValue(this.filterInput);
if (this.lastTypedText != typedText) {
this.lastTypedText = typedText;
this.fire("grid:search",  {
source: this
});
this.pe.stop();
this.pe = null;
}
},
suspend: function() {
if (this.auto != null) {
this.auto.hide();
}
},
clear: function() {
if (this.filterInput != null) {
dwr.util.setValue(this.filterInput, "");
}
},
initialize: function() {}
});
var PopupFormPage = Class.create();
Object.extend(PopupFormPage.prototype, FormPage.prototype);
Object.extend(PopupFormPage.prototype,{
onInit: function() {
this.view = $Form(this.module);
this.view.page = this;
this.initEvents();
mvc.kph.onKey(KPH.ESC_KEYCODE, this.closeWindow.bind(this), false);
if (! hasModalWindow()) {
window.onunload = this.setReturnValue.bind(this);
}
this.view.loadBean(0);
},
onSubmit: function() {
if (hasModalWindow()) {
window.returnValue = this.view.bean;
}
else {
self.opener.returnValue = this.view.bean;
}
this.view.resetDirty();
window.close();
},
setReturnValue: function() {
self.opener.delayedWindowFocus(150);
},
closeWindow: function() {
window.close();
},
initialize: function() {}
});
var PopupFormFilter = Class.create();
Object.extend(PopupFormFilter.prototype, FilterElement.prototype);
Object.extend(PopupFormFilter.prototype,{
actionName: "formFilter",
popup: null,
execute: function() {
if (this.popup == null) {
var popupModule = Options.getStrOption(this.options, "popupModule", this.gridPage.gridModule + "Filter");
this.popup = new PopupWin(popupModule,this, {
onAction: this.onSubmit.bind(this),
layout: "popupForm",
title: "Filter",
width: this.getIntOption("popupWidth", 700),
heigth: this.getIntOption("popupHeigth", 700)
});
}
this.popup.show();
},
activateFilter: function() {
var cancelFilters = $Filter("cancelFilters");
if (cancelFilters != null) {
cancelFilters.show();
}
var saveFilter = $Filter("saveFilter");
if (saveFilter != null) {
saveFilter.show();
}
this.removeClassName(Style.FORM_FILTER);
this.addClassName(Style.FORM_FILTER_ACTIVE);
},
onInit: function() {
this.addClassName(Style.FORM_FILTER);
},
onSubmit: function(event,bean) {
if (bean != null) {
this.gridPage.view.submitFilter(bean);
}
},
initialize: function() {}
});
var TimeElement = Class.create();
Object.extend(TimeElement,{
pattern: "%H:%M"
});
Object.extend(TimeElement.prototype, ViewElement.prototype);
Object.extend(TimeElement.prototype,{
getElementValue: function() {
var timeStr = dwr.util.getValue(this.property);
if (timeStr != null && timeStr != "" && length(timeStr) <= 2 && timeStr.indexOf(":") == - 1) {
timeStr = timeStr + ":";
dwr.util.setValue(this.property + ":time", timeStr);
}
if (timeStr.endsWith(":")) {
timeStr = timeStr + "00";
dwr.util.setValue(this.property + ":time", timeStr);
}
if (timeStr != null && timeStr != "") {
return timeStr;
}
return null;
},
setNewValue: function(val) {
this._value = this._value = parseDate(val, TimeElement.pattern);
setNestedBeanProperty(this.page.view.bean, this.property, this._value);
this.toggleDependent(true);
},
formattedValue: function() {
return printDate(this._value, TimeElement.pattern);
},
assistTime: function() {
var timeStr = dwr.util.getValue(this.property + ":time");
var newTimeStr = timeStr;
if (length(timeStr) == 2 && timeStr.indexOf(":") == - 1) {
newTimeStr = newTimeStr + ":";
}
if (newTimeStr.indexOf(".") != - 1) {
newTimeStr = newTimeStr.replace(".", ":");
}
if (newTimeStr.endsWith("::")) {
newTimeStr = newTimeStr.substring(0, length(newTimeStr) - 1);
}
if (newTimeStr != timeStr) {
dwr.util.setValue(this.property + ":time", newTimeStr);
}
},
setViewValue: function() {
if (this._value != null) {
var dateStr = printDate(this._value, TimeElement.pattern);
this.setValueContent(dateStr);
}
else {
this.setEmptyValue();
}
},
setFormValue: function() {
if (this._value != null) {
var dateStr = printDate(this._value, TimeElement.pattern);
dwr.util.setValue(this.property, dateStr);
}
else {
dwr.util.setValue(this.property, "");
}
},
createEditUI: function() {
var dateStr = printDate(this._value, TimeElement.pattern);
var elt = elem("input",  {
type: "text",id: this.property,value: dateStr
});
this.setAttr(elt, "size", 3);
this.setAttr(elt, "title", null);
this.appendChild(elt);
Event.observe(elt, "keyup", this.assistTime.bind(this));
},
initialize: function() {}
});
var PopupGridPage = Class.create();
Object.extend(PopupGridPage.prototype, GridPage.prototype);
Object.extend(PopupGridPage.prototype,{
onInit: function() {
mvc.kph.onKey(KPH.ESC_KEYCODE, this.closeWindow.bind(this), false);
if (! hasModalWindow()) {
window.onunload = this.setReturnValue.bind(this);
}
this.view.disableLinks();
this.view.loadList();
},
onEnterRow: function(row) {
if (hasModalWindow()) {
window.returnValue = row;
}
else {
self.opener.returnValue = row;
}
window.close();
},
setReturnValue: function() {
self.opener.delayedWindowFocus(150);
},
closeWindow: function() {
window.close();
},
initialize: function() {}
});
var ClearAction = Class.create();
Object.extend(ClearAction.prototype, ActionElement.prototype);
Object.extend(ClearAction.prototype,{
actionName: "clear",
execute: function() {
this.formPage.view.createBean();
},
initialize: function() {}
});
var PopupFilter = Class.create();
Object.extend(PopupFilter.prototype, FilterElement.prototype);
Object.extend(PopupFilter.prototype,{
params: null,
initialize: function() {
this.params = [];
},
execute: function(evt) {
this.params[0] = this.actionName;
this.params[1] = ( this.checked ) ? ( "true" ) : ( "false" );
this.gridPage.view.invokeFilter(this.actionName, this.params);
},
init: function(opts) {
this.options = opts;
this.actionName = get(this.options, "name");
this.params = [];
this.onclick = this.execute.bindAsEventListener(this);
}
});
var DateTimeElement = Class.create();
Object.extend(DateTimeElement.prototype, ViewElement.prototype);
Object.extend(DateTimeElement.prototype,{
getElementValue: function() {
var dateStr = dwr.util.getValue(this.property);
var timeStr = dwr.util.getValue(this.property + ":time");
if (( dateStr == null || dateStr == "" ) && timeStr != null && timeStr != "") {
dateStr = printDate(new Date(), DateElement.pattern);
}
else
if (( timeStr == null || timeStr == "" ) && dateStr != null && dateStr != "") {
timeStr = printDate(new Date(), TimeElement.pattern);
}
if (timeStr != null && timeStr != "" && length(timeStr) <= 2 && timeStr.indexOf(":") == - 1) {
timeStr = timeStr + ":";
dwr.util.setValue(this.property + ":time", timeStr);
}
if (timeStr.endsWith(":")) {
timeStr = timeStr + "00";
dwr.util.setValue(this.property + ":time", timeStr);
}
if (dateStr != null && dateStr != "" && length(dateStr) == 8 && dateStr.indexOf(".") == - 1) {
dateStr = dateStr.substring(0, 2) + "." + dateStr.substring(2, 4) + "." + dateStr.substring(4);
dwr.util.setValue(this.property, dateStr);
}
else
if (dateStr != null && dateStr != "" && length(dateStr) == 6 && dateStr.indexOf(".") == - 1) {
var year = dateStr.substring(4);
if (parseInt(year) < 70) {
year = "20" + year;
}
else {
year = "19" + year;
}
dateStr = dateStr.substring(0, 2) + "." + dateStr.substring(2, 4) + "." + year;
dwr.util.setValue(this.property, dateStr);
}
if (dateStr != null && dateStr != "" && length(dateStr) <= 5 && ! dateStr.endsWith(".")) {
dateStr = dateStr + ".";
}
if (dateStr != null && dateStr != "" && length(dateStr) <= 6 && dateStr.endsWith(".")) {
dateStr = dateStr + "" + new Date().getFullYear();
dwr.util.setValue(this.property, dateStr);
}
if (dateStr != null && dateStr != "" && timeStr != null && timeStr != "") {
return dateStr + " " + timeStr;
}
return null;
},
setNewValue: function(val) {
this._value = parseDate(val, DateElement.pattern + " " + TimeElement.pattern);
setNestedBeanProperty(this.page.view.bean, this.property, this._value);
this.toggleDependent(true);
},
formattedValue: function() {
return printDate(this._value, DateElement.pattern + " " + TimeElement.pattern);
},
assistDate: function() {
var dateStr = dwr.util.getValue(this.property);
var newDateStr = dateStr;
if (length(dateStr) == 2 && dateStr.indexOf(".") == - 1) {
newDateStr = newDateStr + ".";
}
else
if (length(dateStr) == 5 && dateStr.substring(dateStr.indexOf(".") + 1).indexOf(".") == - 1) {
newDateStr = newDateStr + ".";
}
if (newDateStr.endsWith("..")) {
newDateStr = newDateStr.substring(0, length(newDateStr) - 1);
}
if (newDateStr != dateStr) {
dwr.util.setValue(this.property, newDateStr);
}
},
assistTime: function() {
var timeStr = dwr.util.getValue(this.property + ":time");
var newTimeStr = timeStr;
if (length(timeStr) == 2 && timeStr.indexOf(":") == - 1) {
newTimeStr = newTimeStr + ":";
}
if (newTimeStr.indexOf(".") != - 1) {
newTimeStr = newTimeStr.replace(".", ":");
}
if (newTimeStr.endsWith("::")) {
newTimeStr = newTimeStr.substring(0, length(newTimeStr) - 1);
}
if (newTimeStr != timeStr) {
dwr.util.setValue(this.property + ":time", newTimeStr);
}
},
setViewValue: function() {
if (this._value != null) {
var datetimeStr = printDate(this._value, DateElement.pattern + " " + TimeElement.pattern);
this.setValueContent(datetimeStr);
}
else {
this.setEmptyValue();
}
},
setFormValue: function() {
if (this._value != null) {
var dateStr = printDate(this._value, DateElement.pattern);
var timeStr = printDate(this._value, TimeElement.pattern);
dwr.util.setValue(this.property, dateStr);
dwr.util.setValue(this.property + ":time", timeStr);
}
else {
dwr.util.setValue(this.property, "");
dwr.util.setValue(this.property + ":time", "");
}
},
createEditUI: function() {
var dateStr = printDate(this._value, DateElement.pattern);
var dateElt = elem("input",  {
type: "text",id: this.property,value: dateStr
});
this.setAttr(dateElt, "size", 8);
this.setAttr(dateElt, "title", null);
this.appendChild(dateElt);
Event.observe(dateElt, "keyup", this.assistDate.bind(this));
var imgElt = elem("img",  {
src: this.page.path + Icons.DATE,
alt: "Výběr datumu",
onclick: function(evt) {
showCalendar(this, DateElement.pattern, "24");
return false;
}
});
this.appendChild(imgElt);
this.appendChild(document.createTextNode("\u00a0"));
var timeStr = printDate(this._value, TimeElement.pattern);
var timeElt = elem("input",  {
type: "text",id: this.property + ":time",value: timeStr
});
this.setAttr(timeElt, "size", 3);
this.setAttr(timeElt, "title", null);
this.appendChild(timeElt);
Event.observe(timeElt, "keyup", this.assistTime.bind(this));
},
addChangeListener: function(f) {
var view = $(this.property);
if (view != null) {
Event.observe(view, "change", f);
Event.observe(view, "blur", f);
}
var timeView = $(this.property + ":time");
if (timeView != null) {
Event.observe(timeView, "change", f);
Event.observe(timeView, "blur", f);
}
},
initialize: function() {}
});
var PopupUI = Class.create();
Object.extend(PopupUI.prototype,{
_parent: null,
popupDiv: null,
textInput: null,
popupTableBody: null,
offset: 0,
width: 0,
height: 0,
defaultText: "== Zadáním textu začněte vyhledávat ==",
currentRow: - 1,
cellFuncs: null,
labels: null,
source: null,
initialize: function(parent,options) {
this._parent = parent;
this.labels = [];
this.currentRow = - 1;
this.cellFuncs = [];
push(this.cellFuncs, this.getRowData.bind(this));
Object.extend(this, options);
},
show: function() {
if (this.popupDiv == null)
this.create();
this.currentRow = - 1;
this.textInput.value = "";
this.onChanged("", this.addLabels.bind(this));
try {
Position.clone(this._parent, this.popupDiv,  {
setLeft: true,
setTop: true,
setWidth: false,
setHeight: false
});
}
catch (e) {
}
var offsetWidth = ( this.offset != 0 ) ? ( ( this._parent.getWidth() / this._parent.getWidth() ) * this.offset ) : this._parent.getWidth();
var _afterFinish = this.initTextInput.bind(this);
new Effect.Parallel([new Effect.BlindDown(this.popupDiv, {
sync: true
}), new Effect.Move(this.popupDiv, {
sync: true,
x: offsetWidth + 15,
y: - 15,
mode: "relative"
})], {
duration: .4,
afterFinish: _afterFinish
});
PopupManager.register(this.popupDiv, false);
mvc.kph.onKey(KPH.UP_ARROW_KEYCODE, this.prevRow.bind(this), true);
mvc.kph.onKey(KPH.DOWN_ARROW_KEYCODE, this.nextRow.bind(this), true);
mvc.kph.onKey(KPH.ENTER_KEYCODE, this.enterRow.bind(this), true);
mvc.kph.onKey(KPH.ESC_KEYCODE, this.toggle.bind(this), false);
},
initTextInput: function() {
this.textInput.value = this.defaultText;
this.textInput.onfocus = this.onTextFocus.bind(this);
},
onTextFocus: function() {
this.textInput.value = "";
this.textInput.onfocus = null;
},
hide: function() {
PopupManager.deregister(this.popupDiv);
},
toggle: function() {
if (this.popupDiv != null && this.popupDiv.visible()) {
this.hide();
}
else {
this.show();
}
},
getRowData: function(l) {
return l.labelText;
},
rowCreator: function(options) {
var row = elem("tr");
row.addClassName(( ( options.rowNum % 2 ) == 0 ) ? Style.EVEN : Style.ODD);
Event.observe(row, "click", this.onAction.bindAsEventListener(this.source, this.labels[options.rowNum]));
Event.observe(row, "mouseover", this.onMouseOver.bindAsEventListener(this, options.rowNum));
return row;
},
addLabels: function(rows) {
this.currentRow = - 1;
this.labels = rows;
dwr.util.removeAllRows(this.popupTableBody);
dwr.util.addRows(this.popupTableBody, $A(rows), this.cellFuncs,  {
rowCreator: this.rowCreator.bind(this)
});
},
setLabels: function(rows) {
this.labels = rows;
},
getTypedText: function() {
return this.textInput.value;
},
nextRow: function() {
if (this.currentRow != - 1) {
if (this.currentRow < ( this.popupTableBody.rows.length - 1 )) {
this.selectRow(this.currentRow + 1);
}
}
else
if (this.labels != null && this.labels.length != 0) {
this.textInput.blur();
this.selectRow(0);
}
},
prevRow: function() {
if (this.currentRow > 0) {
this.selectRow(this.currentRow - 1);
}
},
onMouseOver: function(event,rowNum) {
this.selectRow(rowNum);
},
enterRow: function() {
if (this.currentRow != - 1) {
this.onAction(null, this.labels[this.currentRow]);
}
},
create: function() {
this.popupDiv = elem("div");
this.popupDiv.addClassName(Style.POPUP_TABLE);
this.popupDiv.hide();
this._parent.up(0).appendChild(this.popupDiv);
var divHeader = this.createHeader();
this.popupDiv.appendChild(divHeader);
var filtDiv = this.createFilter();
this.popupDiv.appendChild(filtDiv);
var tableDiv = this.createTableDiv();
this.popupDiv.appendChild(tableDiv);
},
createHeader: function() {
var divHeader = elem("div");
divHeader.addClassName(Style.POPUP_TABLE_HEADER);
var anchor = elem("a",  {
href: "#"
});
anchor.addClassName(Style.CLOSE_BUTTON);
Event.observe(anchor, "click", this.toggle.bind(this));
divHeader.appendChild(anchor);
var spanX = elem("span");
spanX.innerHTML = "X";
anchor.appendChild(spanX);
return divHeader;
},
createFilter: function() {
var filtDiv = elem("div");
filtDiv.addClassName(Style.POPUP_FILTER);
this.textInput = elem("input",  {
type: "text"
});
this.textInput.onkeyup = this.onTextTyped.bind(this);
filtDiv.appendChild(this.textInput);
return filtDiv;
},
createTableDiv: function() {
var tableDiv = elem("div");
tableDiv.addClassName(Style.POPUP_TABLE_SCROLL);
var table = elem("table");
debugPrint("create popupTableBody");
this.popupTableBody = elem("tbody");
this.popupTableBody.addClassName(Style.POINTER);
table.appendChild(this.popupTableBody);
tableDiv.appendChild(table);
return tableDiv;
},
scrollToRow: function(rowNum) {
var container = this.popupTableBody.up("div");
var element = $(this.popupTableBody.rows[rowNum]);
var tly = exists(element.y) ? element.y : element.offsetTop;
var bry = tly + element.getHeight();
var top = container.scrollTop;
var bottom = container.getHeight() + container.scrollTop;
if (bry > bottom)
container.scrollTop = top + ( bry - bottom ) + 10;
if (tly < top)
container.scrollTop = top - ( top - tly ) - 10;
},
selectRow: function(rowNum) {
if (this.currentRow >= 0 && this.currentRow < this.popupTableBody.rows.length) {
$(this.popupTableBody.rows[this.currentRow]).removeClassName(Style.SELECTED);
$(this.popupTableBody.rows[this.currentRow]).addClassName(( ( this.currentRow % 2 ) == 0 ) ? Style.EVEN : Style.ODD);
}
this.currentRow = rowNum;
$(this.popupTableBody.rows[this.currentRow]).removeClassName(( ( this.currentRow % 2 ) == 0 ) ? Style.EVEN : Style.ODD);
$(this.popupTableBody.rows[this.currentRow]).addClassName(Style.SELECTED);
this.scrollToRow(this.currentRow);
},
onChanged: function(typedText,handler) {
},
onTextTyped: function() {
debugPrint("onTextTyped: " + this.getTypedText());
this.onChanged(this.getTypedText(), this.addLabels.bind(this));
},
onAction: function(event,data) {
},
resetReturnValue: function() {
}
});
var EntryTableGridElement = Class.create();
Object.extend(EntryTableGridElement.prototype, ViewElement.prototype);
Object.extend(EntryTableGridElement.prototype,{
columns: null,
defs: null,
grid: null,
form: null,
currentRow: 0,
showForm: false,
initialize: function() {
this.columns = [];
this.defs = [];
this._value = [];
},
addColumn: function(opts,source) {
var column;
var columnProperty = get(opts, "property");
if (columnProperty != null) {
column = $Column(this.property + "[]." + columnProperty);
}
else {
var columnId = get(opts, "id");
column = $Column(this.property + "[]." + columnId);
put(opts, "nestedProperty", this.property);
put(opts, "path", this.page.path);
}
if (column != null) {
Object.extend(column, source);
column.initialize();
column.init(opts);
push(this.columns, column);
push(this.defs, this.getData.bind(this, column));
}
},
evenOddRowCreator: function(options) {
var row = elem("tr");
row.addClassName(( ( options.rowNum % 2 ) == 0 ) ? Style.EVEN : Style.ODD);
if (this.render == ViewElement.RENDER_FORM || this.showForm) {
Event.observe(row, "click", this.onClickRow.bind(this, options.rowNum));
}
return row;
},
cellCreatorCallback: function(options) {
var td = elem("td");
if (this.columns[options.cellNum].property != null || this.render == ViewElement.RENDER_FORM) {
this.columns[options.cellNum].columnHandler(td, options);
}
return td;
},
getData: function(column,row) {
if (column.property != null) {
var propertyValue = getNestedBeanProperty(row, column.property);
if (propertyValue != null) {
return column.displayHandler(propertyValue);
}
return "";
}
return column.displayHandler(null);
},
onClickRow: function(rowNum) {
debugPrint(this.property + ".onClickRow: " + rowNum);
this.context.populateEntryTableRow(this.property, rowNum);
var row = get(this._value, rowNum);
debugPrint(this.property + ".populate: " + Object.toJSON(row));
this.clearFormValues(row);
debugPrint(this.property + ".onClickRow: set values");
for (var i = iterator(row);i.hasNext();) {
var nestedProperty = i.next();
var view = $View(this.property + "Template." + nestedProperty);
if (view != null) {
view.setNestedValue(nestedProperty, row);
view.addClassName(Style.EDIT_MODE);
}
}
debugPrint(this.property + ".onClickRow: select row");
this.selectRow(rowNum);
},
safeValue: function(val) {
if (val == null) {
var array = [];
return array;
}
return val;
},
setViewValue: function() {
this.setRows();
this.onClearForm(getNestedBeanProperty(this.page.view.bean, this.property + "Template"));
},
setFormValue: function() {
this.setViewValue();
},
clearUI: function() {
this.form.hide();
this.grid.up(0).hide();
this.grid.up(0).next("p").hide();
this.selectRow(length(this._value));
debugPrint(this.property + ".clearUI: currentRow=" + this.currentRow);
},
createEditUI: function() {
debugPrint(this.property + ": createEditUI");
var insertAction = $("i:" + this.property + "Template");
if (insertAction != null) {
insertAction.show();
Event.observe(insertAction, "click", this.onNewEntryClicked.bindAsEventListener(this));
}
var clearAction = $("c:" + this.property + "Template");
if (clearAction != null) {
clearAction.show();
Event.observe(clearAction, "click", this.onClearEntryClicked.bindAsEventListener(this, getNestedBeanProperty(this.page.view.bean, this.property + "Template")));
}
this.form.show();
var formTable = this.form.down("table");
if (formTable != null) {
formTable.addClassName(Style.INNER_FORM);
}
this.grid.addClassName(Style.POINTER);
this.setFormValue();
debugPrint(this.property + ": createEditUI finished");
},
createViewUI: function() {
var insertAction = $("i:" + this.property + "Template");
if (insertAction != null) {
insertAction.hide();
}
var clearAction = $("c:" + this.property + "Template");
if (clearAction != null) {
clearAction.hide();
}
if (this.showForm && this._enabled) {
var formTable = this.form.down("table");
if (formTable != null) {
formTable.addClassName(Style.INNER_FORM);
}
this.form.show();
this.grid.addClassName(Style.POINTER);
}
this.setViewValue();
},
bindChangeListener: function() {
},
doDisableView: function() {
debugPrint(this.property + ": doDisableView()");
this.form.hide();
},
doEnableView: function(_focus) {
debugPrint(this.property + ": doEnableView()");
this.form.show();
},
onNewRow: function(value) {
if (! this.hasErrors()) {
debugPrint(this.property + ".onNewRow: currentRow=" + this.currentRow);
this.context.addEntryTableRow(this.property, this.currentRow, this.addRow.bind(this));
}
},
onDeleteRow: function(rowNum) {
debugPrint(this.property + ".onDeleteRow: currentRow=" + this.currentRow);
this.context.deleteEntryRow(this.property, rowNum);
splice(this._value, rowNum);
this.setRows();
this.selectRow(length(this._value));
debugPrint(this.property + ".onDeleteRow(finished): currentRow=" + this.currentRow);
},
addRow: function(row) {
if (! this.hasErrors()) {
debugPrint(this.property + ".addRow: " + Object.toJSON(row));
if (get(row, "poradi") != null) {
this.currentRow = get(row, "poradi") - 1;
debugPrint(this.property + ".addRow: poradi=" + this.currentRow);
}
else {
this.currentRow = length(this._value);
debugPrint(this.property + ".addRow: currentRow=" + this.currentRow);
}
if (length(this._value) == 0) {
this._value = [];
}
if (this.currentRow >= length(this._value)) {
push(this._value, row);
}
else {
put(this._value, this.currentRow, row);
}
this.setRows();
this.onClearForm(row);
debugPrint(this.property + ".addRow(finished): currentRow=" + this.currentRow);
}
},
clearValue: function() {
this.setValue(null);
},
onClearForm: function(row) {
this.clearFormValues(row);
this.context.clearEntryTableForm(this.property, this.populateForm.bind(this));
},
clearFormValues: function(row) {
for (var i = iterator(row);i.hasNext();) {
var nestedProperty = i.next();
var view = $View(this.property + "Template." + nestedProperty);
if (view != null) {
debugPrint("clear: " + this.property + "Template." + nestedProperty);
view.clearValue();
view.removeClassName(Style.EDIT_MODE);
}
}
this.selectRow(length(this._value));
debugPrint(this.property + ".clearForm(finished): currentRow=" + this.currentRow);
},
populateForm: function(row) {
for (var i = iterator(row);i.hasNext();) {
var nestedProperty = i.next();
var view = $View(this.property + "Template." + nestedProperty);
if (view != null) {
debugPrint(this.property + "Template." + nestedProperty + "=" + Object.toJSON(get(row, nestedProperty)));
view.setValue(get(row, nestedProperty));
view.removeClassName(Style.EDIT_MODE);
}
}
setNestedBeanProperty(this.page.view.bean, this.property + "Template", row);
},
onNewEntryClicked: function(event) {
var element = event.element();
element.fire("entry:insert",  {
source: this,
originalEvent: event
});
},
onDeleteEntryClicked: function(event,rowIndex) {
var element = event.element();
element.fire("entry:delete",  {
source: this,
rowNum: rowIndex,
originalEvent: event
});
},
onClearEntryClicked: function(event,rowValue) {
var element = event.element();
element.fire("entry:clear",  {
source: this,
value: rowValue,
originalEvent: event
});
},
setRows: function() {
dwr.util.removeAllRows(this.grid);
debugPrint(this.property + ": setRows()");
if (length(this._value) > 0) {
this.grid.up(0).next("p").hide();
this.grid.up(0).removeClassName(Style.HIDDEN);
this.grid.up(0).show();
dwr.util.addRows(this.grid, $A(this._value), this.defs,  {
rowCreator: this.evenOddRowCreator.bind(this),
cellCreator: this.cellCreatorCallback.bind(this)
});
}
else {
this.grid.up(0).hide();
this.grid.up(0).next("p").show();
}
debugPrint(this.property + ": setRows() finished");
},
selectRow: function(rowNum) {
debugPrint(this.property + ": currentRow=" + this.currentRow);
debugPrint(this.property + ": selectRow(" + rowNum + ")");
if (this.grid != null) {
debugPrint(this.property + ": rows " + this.grid.rows.length);
}
if (this.currentRow >= 0 && this.currentRow < this.grid.rows.length) {
$(this.grid.rows[this.currentRow]).removeClassName(Style.SELECTED);
$(this.grid.rows[this.currentRow]).addClassName(( ( this.currentRow % 2 ) == 0 ) ? Style.EVEN : Style.ODD);
}
this.currentRow = rowNum;
if (this.currentRow >= 0 && this.currentRow < this.grid.rows.length) {
$(this.grid.rows[this.currentRow]).removeClassName(( ( this.currentRow % 2 ) == 0 ) ? Style.EVEN : Style.ODD);
$(this.grid.rows[this.currentRow]).addClassName(Style.SELECTED);
}
},
afterInit: function(opt) {
this.grid = $Grid(this.property);
this.form = $Form(this.property);
this.showForm = ( get(opt, "showForm") == "allways" );
},
hasErrors: function() {
var msgElts = this.form.getElementsByClassName(Style.ERROR);
return ( msgElts != null && msgElts.length != 0 );
},
mouseDown: function() {
debugPrint("mouse down");
},
mouseUp: function() {
debugPrint("mouse up");
},
mouseClick: function() {
debugPrint("mouse click");
}
});
var FilterFormPage = Class.create();
Object.extend(FilterFormPage.prototype, FormPage.prototype);
Object.extend(FilterFormPage.prototype,{
grid: null,
onInit: function() {
this.view = $Form(this.module);
this.view.page = this;
this.view.loadBean(0);
for (var i = 0;i < this.view.views.length;i ++) {
if (! this.view.views[i].readonlyElement) {
this.view.views[i].addChangeListener(this.newOnChangeFunction.bind(this));
}
}
},
newOnChangeFunction: function() {
this.grid.view.submitFilter(this.view.bean);
},
onSave: function() {
debugPrint("bean: " + Object.toJSON(this.view.bean));
this.grid.view.submitFilter(this.view.bean);
this.view.focusView();
},
onClear: function() {
this.grid.view.selectRow(- 1, false);
},
initialize: function() {}
});
var EditAction = Class.create();
Object.extend(EditAction.prototype, ActionElement.prototype);
Object.extend(EditAction.prototype,{
actionName: "edit",
execute: function() {
this.formPage.context.setRender(ViewElement.RENDER_FORM);
this.formPage.view.editData();
},
initialize: function() {}
});
var RadioElement = Class.create();
Object.extend(RadioElement.prototype, SelectElement.prototype);
Object.extend(RadioElement.prototype,{
setViewValue: function() {
this.innerHTML = "";
if (this._labels != null && this._labels.length != 0) {
for (var i = 0;i < this._labels.length;i ++) {
var label = this._labels[i];
var labelElt = elem("label");
var img;
if (this.hasLabelValue(label)) {
img = elem("img",  {
src: this.page.path + Icons.CHECK_TRUE
});
}
else {
img = elem("img",  {
src: this.page.path + Icons.CHECK_FALSE
});
}
img.addClassName(Style.ALIGN_MIDDLE);
labelElt.appendChild(img);
labelElt.appendChild(document.createTextNode(label.labelText));
this.appendChild(labelElt);
}
}
},
setFormValue: function() {
if (this._labels != null && this._labels.length != 0) {
for (var i = 0;i < this._labels.length;i ++) {
var label = this._labels[i];
var inputElt = $(this.property + "." + label.labelValue);
if (this.hasLabelValue(label)) {
debugPrint("setting " + label.labelValue);
inputElt.checked = true;
}
else {
inputElt.checked = false;
}
}
}
},
createEditUI: function() {
if (this._labels != null && this._labels.length != 0) {
for (var i = 0;i < this._labels.length;i ++) {
var label = this._labels[i];
var labelElt = elem("label");
var inputElt = elem("input",  {
id: this.property + "." + label.labelValue,
name: this.property,
type: "radio",
value: label.labelValue
});
inputElt.addClassName(Style.ALIGN_MIDDLE);
Event.observe(inputElt, "click", this.onValueChanged.bindAsEventListener(this, label));
labelElt.appendChild(inputElt);
labelElt.appendChild(document.createTextNode(label.labelText));
this.appendChild(labelElt);
if (this.hasLabelValue(label)) {
inputElt.checked = true;
}
}
}
},
bindChangeListener: function() {
},
changeValue: function(label) {
if (this.render == ViewElement.RENDER_FORM) {
debugPrint("change value to " + label.labelValue);
this.setNewValue(label);
this.setFormValue();
this.context.setProperty(this.getRealProperty(), label.labelValue);
}
return true;
},
onValueChanged: function(event,label) {
var element = event.element();
element.fire("element:change",  {
source: this,
value: label
});
return true;
},
addChangeListener: function(f) {
if (this._labels != null && this._labels.length != 0) {
for (var i = 0;i < this._labels.length;i ++) {
var label = this._labels[i];
var inputElt = $(this.property + "." + label.labelValue);
Event.observe(inputElt, "click", f);
}
}
},
initialize: function() {}
});
var CheckboxElement = Class.create();
Object.extend(CheckboxElement.prototype, ViewElement.prototype);
Object.extend(CheckboxElement.prototype,{
toggleOn: true,
chbox: null,
createEditUI: function() {
this.chbox = elem("input",  {
type: "checkbox",id: this.property,value: "true"
});
this.chbox.addClassName(Style.ALIGN_MIDDLE);
this.appendChild(this.chbox);
this.setFormValue();
},
getElementValue: function() {
if (this.chbox != null) {
return "" + this.chbox.checked;
}
return "false";
},
getSimpleValue: function() {
return "" + this._value;
},
setFormValue: function() {
this.chbox.checked = ( ( "" + this._value ) == "true" );
},
setViewValue: function() {
this.innerHTML = "";
if (( "" + this._value ) == "true") {
this.appendChild(elem("img",  {
src: this.page.path + Icons.CHECK_TRUE
}));
}
else {
this.appendChild(elem("img",  {
src: this.page.path + Icons.CHECK_FALSE
}));
}
this.down("img").addClassName(Style.ALIGN_MIDDLE);
},
onValueChanged: function(event) {
var element = event.element();
element.fire("element:change",  {
source: this
});
return true;
},
bindChangeListener: function() {
if (this.chbox != null) {
Event.observe(this.chbox, "click", this.onValueChanged.bindAsEventListener(this));
}
},
addChangeListener: function(f) {
Event.observe(this.chbox, "click", f);
},
initialize: function() {}
});
var BeanTableElement = Class.create();
Object.extend(BeanTableElement.prototype, ViewElement.prototype);
Object.extend(BeanTableElement.prototype,{
columns: null,
selectedColumn: null,
defs: null,
chooseBtn: null,
insertBtn: null,
popup: null,
tableWidth: 0,
sortedRows: null,
initialize: function() {
this.columns = [];
this.defs = [];
this._value = [];
},
addColumn: function(opts,source) {
var column;
var columnProperty = get(opts, "property");
var columnId = columnProperty;
if (columnProperty != null) {
columnId = this.property + "[]." + columnProperty;
debugPrint("addColumn: " + columnId);
column = $Column(this.property + "[]." + columnProperty);
}
else {
columnId = this.property + "[]." + get(opts, "id");
debugPrint("addAction: " + columnId);
column = $Column(columnId);
put(opts, "nestedProperty", this.property);
put(opts, "path", this.page.path);
}
if (column != null) {
Object.extend(column, source);
column.initialize();
column.init(opts);
if (Options.hasOptionEnabled(opts, "sortable", false)) {
column.gridView = this;
column.columnId = columnId;
column.initHeader();
}
push(this.columns, column);
push(this.defs, this.getData.bind(this, column));
}
},
evenOddRowCreator: function(options) {
var row = elem("tr");
row.addClassName(( ( options.rowNum % 2 ) == 0 ) ? Style.EVEN : Style.ODD);
Event.observe(row, "click", this.onClickRow.bind(this, options.rowNum));
return row;
},
cellCreatorCallback: function(options) {
var td = elem("td");
if (this.columns[options.cellNum].property != null || this.render == ViewElement.RENDER_FORM) {
this.columns[options.cellNum].columnHandler(td, options);
}
return td;
},
getData: function(column,row) {
if (column.property != null) {
var propertyValue = getNestedBeanProperty(row, column.property);
if (propertyValue != null) {
return column.displayHandler(propertyValue);
}
return "";
}
return column.displayHandler(null);
},
onClickRow: function(rowNum) {
if (this.sortedRows != null) {
rowNum = parseInt(get(get(this.sortedRows, rowNum), "poradi")) - 1;
}
var module = get(this.options, "module");
var row = get(this._value, rowNum);
var param = module + "Id=" + get(row, "id");
var link = this.up("div").previous("span");
if (link != null) {
var url = link.innerHTML;
if (url.indexOf("?") != - 1) {
var paramIndex = url.indexOf(module + "Id=");
if (paramIndex != - 1) {
var suffix = url.substring(paramIndex + length(module + "Id="));
if (suffix.indexOf("&") != - 1) {
suffix = suffix.substring(suffix.indexOf("&"));
}
else {
suffix = "";
}
url = url.substring(0, paramIndex);
url = url + param + suffix;
}
else {
url = url + "&" + param;
}
}
else {
url = url + "?" + param;
}
window.location = url;
}
else {
window.location = this.page.path + "/" + module + ".form?" + param;
}
},
safeValue: function(val) {
if (val == null) {
var array = [];
return array;
}
return val;
},
setViewValue: function() {
this.setRows();
},
setFormValue: function() {
this.setViewValue();
},
clearUI: function() {
if (this.chooseBtn == null) {
this.chooseBtn = this.up("div").previous("p").down(".chooseAction");
}
if (this.insertBtn == null) {
this.insertBtn = this.up("div").previous("p").down(".newAction");
}
this.chooseBtn.hide();
this.chooseBtn.stopObserving("click");
this.insertBtn.hide();
this.insertBtn.stopObserving("click");
this.up("div").hide();
this.up("div").next("p").hide();
},
createEditUI: function() {
if (this.popup == null) {
this.popup = new PopupUI(this.chooseBtn, {
source: this,
onAction: this.onNewEntryClicked,
onChanged: this.loadBeanLabels.bind(this),
offset: this.tableWidth
});
}
if (this.tableWidth != 0) {
this.up("table").setAttribute("width", this.tableWidth);
}
if (this.hasOptionEnabled("chooseEnabled", true)) {
this.chooseBtn.show();
Event.observe(this.chooseBtn, "click", this.popup.toggle.bind(this.popup));
}
if (this.hasOptionEnabled("insertEnabled", false)) {
this.insertBtn.show();
Event.observe(this.insertBtn, "click", this.onInsertBtnClicked.bind(this));
}
this.addClassName(Style.POINTER);
this.setFormValue();
},
createViewUI: function() {
if (this.tableWidth != 0) {
this.up("table").setAttribute("width", this.tableWidth);
}
this.addClassName(Style.POINTER);
this.setViewValue();
},
bindChangeListener: function() {
},
setRows: function() {
dwr.util.removeAllRows(this);
if (length(this._value) > 0) {
this.up("div").next("p").hide();
this.up("div").removeClassName(Style.HIDDEN);
this.up("div").show();
var rows = $A(this._value);
if (this.selectedColumn != null) {
for (var i = 0;i < length(this._value);i ++) {
put(get(this._value, i), "poradi", i + 1);
}
rows = rows.sortBy(this.getData.bind(this, this.selectedColumn));
if (this.selectedColumn.direction == "desc") {
rows = rows.reverse();
}
this.sortedRows = rows;
}
dwr.util.addRows(this, rows, this.defs,  {
rowCreator: this.evenOddRowCreator.bind(this),
cellCreator: this.cellCreatorCallback.bind(this)
});
}
else {
this.up("div").hide();
this.up("div").next("p").show();
}
},
onNewRow: function(row) {
if (! this.containsRow(row)) {
push(this._value, row);
this.context.addEnumEntryRow(this.property, get(row, "id"));
this.setRows();
}
},
containsRow: function(row) {
var values = this._value;
for (var i = 0;i < values.length;i ++) {
if (get(values[i], "id") == get(row, "id")) {
return true;
}
}
return false;
},
onDeleteRow: function(rowNum) {
if (this.sortedRows != null) {
rowNum = parseInt(get(get(this.sortedRows, rowNum), "poradi")) - 1;
}
this.context.deleteEntryRow(this.property, rowNum);
splice(this._value, rowNum);
this.setRows();
},
onClearForm: function(row) {
},
onNewEntryClicked: function(event,label) {
var element = event.element();
element.fire("entry:insert",  {
source: this,
value: label,
originalEvent: event
});
},
onDeleteEntryClicked: function(event,rowIndex) {
var element = event.element();
element.fire("entry:delete",  {
source: this,
rowNum: rowIndex,
originalEvent: event
});
},
onInsertBtnClicked: function(event) {
var link = this.up("div").previous("span");
if (link != null) {
window.location = link.innerHTML;
}
else {
var module = get(this.options, "module");
window.location = this.page.path + "/" + module + ".form";
}
},
loadBeanLabels: function(typedText,handler) {
this.context.getFilteredEnumLabels(this.property, typedText, handler);
},
setSelectedColumn: function(column) {
this.selectedColumn = column;
},
getPath: function() {
return this.page.path;
},
getEnumLabels: function(property,handler) {
this.page.context.getEnumLabels(property, handler);
},
filterColumn: function(column,direction) {
this.setRows();
}
});
var EntryTableElement = Class.create();
Object.extend(EntryTableElement.prototype, NestedViewElement.prototype);
var DelegatingViewElement = Class.create();
Object.extend(DelegatingViewElement.prototype, ViewElement.prototype);
Object.extend(DelegatingViewElement.prototype,{
delegated: null,
initialize: function(d) {
this.delegated = d;
},
clearUI: function() {
this.delegated.clearUI();
},
createEditUI: function() {
this.delegated.createEditUI();
this.delegated.hasUI = true;
},
createViewUI: function() {
this.delegated.createViewUI();
},
bindChangeListener: function() {
this.delegated.bindChangeListener();
},
bindOnFocusListener: function() {
this.delegated.bindOnFocusListener();
},
getElementValue: function() {
return this.delegated.getElementValue();
},
setViewValue: function() {
this.delegated.setViewValue();
},
setFormValue: function() {
this.delegated.setFormValue();
},
clearValue: function() {
this.delegated.clearValue();
},
setValue: function(val) {
this.delegated.setValue(val);
},
editValue: function() {
this.delegated.editValue();
},
showValue: function() {
this.delegated.showValue();
},
changeValue: function(val) {
return this.delegated.changeValue(val);
},
safeValue: function(val) {
return this.delegated.safeValue(val);
}
});
var TextColumn = Class.create();
Object.extend(TextColumn.prototype, TableColumn.prototype);
Object.extend(TextColumn.prototype,{
columnHandler: function(td,options) {
td.addClassName(Style.TEXT_COLUMN);
},
displayHandler: function(value) {
var data = value;
var len = data.length;
if (this.getMaxLength() != 0 && len >= this.getMaxLength()) {
data = data.substring(0, this.getMaxLength());
}
return data;
},
initialize: function() {}
});
var DeleteRowColumn = Class.create();
Object.extend(DeleteRowColumn.prototype, TableColumn.prototype);
Object.extend(DeleteRowColumn.prototype,{
columnHandler: function(td,options) {
var nestedProperty = get(this.options, "nestedProperty");
var path = get(this.options, "path");
var view = $View(nestedProperty);
if (view != null && view.render == ViewElement.RENDER_FORM && ! view.readonlyElement) {
var nav = elem("img",  {
src: path + Icons.REMOVE
});
nav.addClassName(Style.POINTER);
Event.observe(nav, "click", view.onDeleteEntryClicked.bindAsEventListener(view, options.rowNum));
td.appendChild(nav);
}
else {
this.hide();
td.hide();
}
},
displayHandler: function(value) {
return null;
},
initialize: function() {}
});
var CheckboxColumn = Class.create();
Object.extend(CheckboxColumn.prototype, TableColumn.prototype);
Object.extend(CheckboxColumn.prototype,{
columnHandler: function(td,options) {
td.addClassName(Style.CODE_COLUMN);
},
displayHandler: function(value) {
return ( ( "" + value ) == "true" ) ? "ANO" : "NE";
},
initialize: function() {}
});
var DeleteColumn = Class.create();
Object.extend(DeleteColumn.prototype, TableColumn.prototype);
Object.extend(DeleteColumn.prototype,{
columnHandler: function(td,options) {
debugPrint("DeleteColumn.handler");
if (get(this.options, "readonly") == null) {
debugPrint("options.readonly == null");
var nav = elem("img",  {
src: this.gridView.getPath() + Icons.REMOVE
});
nav.addClassName(Style.POINTER);
nav.onclick = this.gridView.onDeleteRow.bind(this.gridView, options.rowNum);
td.appendChild(nav);
}
else {
debugPrint("options.readonly == " + get(this.options, "readonly"));
}
},
displayHandler: function(value) {
return null;
},
initialize: function() {}
});
var CheckboxFilter = Class.create();
Object.extend(CheckboxFilter.prototype, FilterElement.prototype);
Object.extend(CheckboxFilter.prototype,{
actionName: "checkboxFilter",
params: null,
initialize: function() {
this.params = [];
},
execute: function(evt) {
this.params[0] = this.actionName;
this.params[1] = ( this.checked ) ? ( "true" ) : ( "false" );
this.gridPage.view.invokeFilter(this.actionId, this.params);
},
onInit: function() {
this.params = [];
this.observe("click", this.execute.bindAsEventListener(this));
}
});
var FilteredGridPage = Class.create();
Object.extend(FilteredGridPage.prototype, GridPage.prototype);
Object.extend(FilteredGridPage.prototype,{
form: null,
onNavigationStart: function() {
this.form.view.blurView();
},
onNavigateRow: function(row) {
},
onEnterRow: function(row) {
this.form.view.editBean(row);
this.form.view.focusView();
this.form.view.populate();
},
initialize: function() {}
});
var PopupInput = Class.create();
Object.extend(PopupInput.prototype,{
_parent: null,
popupDiv: null,
textInput: null,
offset: 0,
size: 30,
inputLabel: null,
buttonLabel: "OK",
initialize: function(parent,options) {
this._parent = parent;
Object.extend(this, options);
},
show: function() {
if (this.popupDiv == null)
this.create();
this.textInput.value = "";
try {
Position.clone(this._parent, this.popupDiv,  {
setLeft: true,
setTop: true,
setWidth: false,
setHeight: false
});
}
catch (e) {
}
var offsetWidth = ( this.offset != 0 ) ? ( ( this._parent.getWidth() / this._parent.getWidth() ) * this.offset ) : this._parent.getWidth();
var _afterFinish = this.initTextInput.bind(this);
new Effect.Parallel([new Effect.BlindDown(this.popupDiv, {
sync: true
}), new Effect.Move(this.popupDiv, {
sync: true,
x: offsetWidth + 15,
y: - 15,
mode: "relative"
})], {
duration: .4,
afterFinish: _afterFinish
});
PopupManager.register(this.popupDiv, false);
mvc.kph.onKey(KPH.ESC_KEYCODE, this.toggle.bind(this), false);
mvc.kph.onKey(KPH.ENTER_KEYCODE, this.submitClicked.bind(this), false);
},
initTextInput: function() {
this.textInput.value = "";
this.textInput.focus();
},
hide: function() {
PopupManager.deregister(this.popupDiv);
},
toggle: function() {
if (this.popupDiv != null && this.popupDiv.visible()) {
this.hide();
}
else {
this.show();
}
},
getTypedText: function() {
return this.textInput.value;
},
submitClicked: function() {
this.onAction(null, this.getTypedText());
},
create: function() {
this.popupDiv = elem("div");
this.popupDiv.hide();
this._parent.up(0).appendChild(this.popupDiv);
var divHeader = this.createHeader();
this.popupDiv.appendChild(divHeader);
var inputDiv = this.createInput();
this.popupDiv.appendChild(inputDiv);
},
createHeader: function() {
var divHeader = elem("div");
divHeader.addClassName(Style.POPUP_TABLE_HEADER);
var anchor = elem("a",  {
href: "#"
});
anchor.addClassName(Style.CLOSE_BUTTON);
Event.observe(anchor, "click", this.toggle.bind(this));
divHeader.appendChild(anchor);
var spanX = elem("span");
spanX.innerHTML = "X";
anchor.appendChild(spanX);
return divHeader;
},
createInput: function() {
var inputDiv = elem("div");
inputDiv.addClassName(Style.LINE_FIELDS);
if (this.inputLabel != null) {
var inputLabelElt = elem("label");
inputLabelElt.innerHTML = this.inputLabel;
inputDiv.appendChild(inputLabelElt);
}
this.textInput = elem("input",  {
type: "text",
size: this.size
});
inputDiv.appendChild(this.textInput);
var submitButton = elem("input",  {
type: "button",
value: this.buttonLabel
});
submitButton.addClassName(Style.BTN_70);
submitButton.observe("click", this.submitClicked.bind(this));
inputDiv.appendChild(submitButton);
return inputDiv;
},
onAction: function(event,data) {
},
resetReturnValue: function() {
}
});
var NumberColumn = Class.create();
Object.extend(NumberColumn.prototype, TableColumn.prototype);
Object.extend(NumberColumn.prototype,{
displayHandler: function(value) {
var val = value;
if (val != null) {
var fixedSizeParameter = get(this.options, "fixedSize");
if (fixedSizeParameter != null) {
var fixedSize = parseInt(fixedSizeParameter);
return parseFloat(val).toFixed(fixedSize);
}
}
return value;
},
columnHandler: function(td,options) {
td.addClassName(Style.NUMBER_COLUMN);
},
initialize: function() {}
});
var GridPageWithForm = Class.create();
Object.extend(GridPageWithForm.prototype, GridPage.prototype);
Object.extend(GridPageWithForm.prototype,{
form: null,
onNavigationStart: function() {
this.form.view.blurView();
},
onNavigateRow: function(row) {
this.onEnterRow(row);
},
onEnterRow: function(row) {
this.form.view.editBean(row);
this.form.view.focusView();
this.form.view.populate();
},
initialize: function() {}
});
var FileUploadElement = Class.create();
Object.extend(FileUploadElement.prototype, ViewElement.prototype);
Object.extend(FileUploadElement.prototype,{
upload: null,
input: null,
form: null,
resetButton: null,
submitButton: null,
progressSpan: null,
progressBar: null,
progressBarText: null,
progressBarBoxContent: null,
hiddenId: null,
hiddenDwr: null,
fakeInput: null,
button: null,
viewAction: null,
viewSpan: null,
createViewUI: function() {
this.viewSpan = elem("span");
this.viewSpan.addClassName("view-value");
this.appendChild(this.viewSpan);
this.progressSpan = null;
this.setViewValue();
},
setViewValue: function() {
var file = this._value;
if (file == null || file.originalFilename == null) {
this.setEmptyValue();
}
else {
this.viewSpan.innerHTML = file.originalFilename;
}
},
createEditUI: function() {
this.viewAction = $Action("view");
var text = get(this.options, "uploadtext");
this.button = elem("input",  {
type: "button",value: text
});
this.button.addClassName(Style.BTN_70);
this.button.addClassName(Style.FAKEBUTTON);
this.createUploadElement();
this.setFormValue();
this.appendChild(this.button);
},
setFormValue: function() {
var file = this._value;
if (! ( file == null || file.originalFilename == null )) {
this.input.value = file.originalFilename;
}
},
createUploadElement: function() {
this.createForm();
this.createButtons();
var iframe = elem("iframe",  {
name: "upload"
});
iframe.hide();
this.appendChild(iframe);
},
createButtons: function() {
this.resetButton = elem("input",  {
type: "button",value: "reset"
});
this.resetButton.addClassName(Style.BTN_70);
Event.observe(this.resetButton, "click", this.reset.bind(this));
this.submitButton = elem("input",  {
type: "button",value: "submit"
});
this.submitButton.addClassName(Style.BTN_70);
Event.observe(this.submitButton, "click", this.startProgress.bind(this));
this.resetButton.hide();
this.submitButton.hide();
this.fakeInput = elem("span");
this.fakeInput.addClassName(Style.VIEW_VALUE);
this.fakeInput.hide();
this.appendChild(this.fakeInput);
this.appendChild(this.submitButton);
this.appendChild(this.resetButton);
},
createForm: function() {
this.form = elem("form",  {
method: "post",action: this.page.path + "/" + this.page.module + ".upload",target: "upload",name: this.property,enctype: "multipart/form-data"
});
this.form.addClassName("upload-form");
this.upload = elem("input",  {
type: "file",
name: this.property
});
this.upload.addClassName("file-hidden");
this.upload.onchange = this.uploadChange.bind(this);
this.hiddenId = elem("input",  {
type: "hidden",
name: "id"
});
this.hiddenDwr = elem("input",  {
type: "hidden",
name: "scriptSessionId"
});
this.context.getProperty("id", this.setId.bind(this));
this.hiddenDwr.value = dwr.engine._getScriptSessionId();
this.form.appendChild(this.upload);
this.form.appendChild(this.hiddenId);
this.form.appendChild(this.hiddenDwr);
this.appendChild(this.form);
this.input = elem("input",  {
readOnly: "readOnly",type: "text"
});
this.input.addClassName(Style.FAKEFILE);
this.appendChild(this.input);
},
createProgress: function() {
this.fakeInput.hide();
this.submitButton.hide();
this.resetButton.hide();
if (this.progressSpan == null) {
this.progressSpan = elem("span");
this.progressSpan.addClassName(Style.FILE_PROGRESS_BAR);
}
else {
this.progressSpan.innerHTML = "";
}
this.progressBar = elem("div");
var theMeter = elem("div");
theMeter.addClassName(Style.FILE_PROGRESS_METER);
this.progressBarText = elem("div");
this.progressBarText.addClassName(Style.FILE_PROGRESS_TEXT);
var progressBarBox = elem("div");
progressBarBox.addClassName(Style.FILE_PROGRESS_BAR_BOX);
this.progressBarBoxContent = elem("div");
this.progressBarBoxContent.addClassName(Style.FILE_PROGRESS_BAR_CONTENT);
this.progressBar.appendChild(theMeter);
theMeter.appendChild(progressBarBox);
progressBarBox.appendChild(this.progressBarBoxContent);
progressBarBox.appendChild(this.progressBarText);
var abortButton = elem("input",  {
type: "button",value: "abort"
});
Event.observe(abortButton, "click", this.createEditUI.bind(this));
abortButton.addClassName(Style.BTN_70);
this.progressBar.appendChild(abortButton);
this.progressSpan.appendChild(this.progressBar);
this.appendChild(this.progressSpan);
},
setId: function(id) {
this.hiddenId.value = id;
},
uploadChange: function() {
var value = this.upload.value;
var index = - 1;
index = value.lastIndexOf("/");
if (index == - 1) {
index = value.lastIndexOf("\\");
}
value = value.substring(index + 1, value.lastIndexOf(""));
this.fakeInput.innerHTML = value;
this.button.hide();
this.input.hide();
this.upload.hide();
this.fakeInput.show();
this.submitButton.show();
this.resetButton.show();
},
reset: function() {
this.form.reset();
this.fakeInput.hide();
this.submitButton.hide();
this.resetButton.hide();
this.input.show();
this.upload.show();
this.button.show();
if (this.progressSpan != null) {
if (this.progressSpan.parentNode != null) {
this.progressSpan.parentNode.removeChild(this.progressSpan);
}
this.progressSpan = null;
}
if (this.viewAction != null) {
this.viewAction.enable();
}
this.setFormValue();
},
updateProgress: function(uploadInfo) {
if (uploadInfo.inProgress) {
var fileIndex = uploadInfo.fileIndex;
var progressPercent = Math.ceil(( uploadInfo.bytesRead / uploadInfo.totalSize ) * 100);
this.progressBarText.innerHTML = this.fakeInput.innerHTML + "&nbsp;" + progressPercent + "%";
Object.extend(this.progressBarBoxContent.style,  {
width: "" + parseInt(progressPercent * 3.5) + "px"
});
window.setTimeout(this.refreshProgress.bind(this), 400);
}
else
if (uploadInfo.done) {
this.onUploadDone();
}
return true;
},
onUploadDone: function() {
this.context.getProperty(this.property, this.setVal.bind(this));
},
refreshProgress: function() {
this.context.getUploadInfo(this.updateProgress.bind(this));
},
startProgress: function() {
this.createProgress();
Object.extend(this.progressBar.style,  {
display: "block"
});
this.progressBarText.innerHTML = this.fakeInput.innerHTML + "&nbsp;" + "0%";
window.setTimeout(this.refreshProgress.bind(this), 1000);
if (this.viewAction != null) {
this.viewAction.disable();
}
this.form.submit();
},
setVal: function(data) {
this._value = data;
this.reset();
},
initialize: function() {}
});
var LoadFilter = Class.create();
Object.extend(LoadFilter.prototype, FilterElement.prototype);
Object.extend(LoadFilter.prototype,{
actionName: "loadFilter",
popup: null,
execute: function() {
if (this.popup == null) {
this.popup = new PopupEntries(this, {
onAction: this.onLoadFilter.bind(this),
onDelete: this.onDeleteFilter.bind(this)
});
}
this.popup.show();
},
activateFilter: function() {
var filterName = get(this.options, "filterName");
if (filterName == null) {
filterName = "formFilter";
}
var formFilter = $Filter(filterName);
if (formFilter != null) {
formFilter.removeClassName(Style.FORM_FILTER_ACTIVE);
formFilter.addClassName(Style.FORM_FILTER);
}
var cancelFilters = $Filter("cancelFilters");
if (cancelFilters != null) {
cancelFilters.show();
}
var saveFilter = $Filter("saveFilter");
if (saveFilter != null) {
saveFilter.show();
}
},
onLoadFilter: function(evt,filterId) {
this.gridPage.context.loadFilter(filterId, this.activateFilter.bind(this));
},
onDeleteFilter: function(evt,filterId) {
this.gridPage.context.deleteFilter(filterId);
},
onInit: function() {
},
initialize: function() {}
});
var TextElement = Class.create();
Object.extend(TextElement.prototype, ViewElement.prototype);
Object.extend(TextElement.prototype,{
safeValue: function(val) {
if (val != null) {
return val;
}
return "";
},
createEditUI: function() {
var elt = elem("input",  {
type: "text",id: this.property
});
this.setHtmlOptions(elt);
this.appendChild(elt);
var units = get(this.options, "units");
if (units != null) {
this.appendChild(document.createTextNode("\u00a0[" + units + "]"));
}
this.setFormValue();
},
setViewValue: function() {
var content = this.setValueContent(this.formatValue(this._value));
if (content.innerHTML != null && content.innerHTML != "") {
var units = get(this.options, "units");
if (units != null) {
this.appendChild(document.createTextNode(units));
}
}
else {
this.setEmptyValue();
}
},
setHtmlOptions: function(elt) {
this.setAttr(elt, "size", 20);
this.setAttr(elt, "maxlength", null);
this.setAttr(elt, "accesskey", null);
this.setAttr(elt, "title", null);
},
initialize: function() {}
});
var DateColumn = Class.create();
Object.extend(DateColumn.prototype, TableColumn.prototype);
Object.extend(DateColumn.prototype,{
columnHandler: function(td,options) {
td.addClassName(Style.DATE_COLUMN);
},
displayHandler: function(value) {
return printDate(value, "%d.%m.%Y");
},
initialize: function() {}
});
var DateElement = Class.create();
Object.extend(DateElement,{
pattern: "%d.%m.%Y"
});
Object.extend(DateElement.prototype, ViewElement.prototype);
Object.extend(DateElement.prototype,{
getElementValue: function() {
var dateStr = dwr.util.getValue(this.property);
if (dateStr != null && dateStr != "" && length(dateStr) == 8 && dateStr.indexOf(".") == - 1) {
dateStr = dateStr.substring(0, 2) + "." + dateStr.substring(2, 4) + "." + dateStr.substring(4);
dwr.util.setValue(this.property, dateStr);
}
else
if (dateStr != null && dateStr != "" && length(dateStr) == 6 && dateStr.indexOf(".") == - 1) {
var year = dateStr.substring(4);
if (parseInt(year) < 70) {
year = "20" + year;
}
else {
year = "19" + year;
}
dateStr = dateStr.substring(0, 2) + "." + dateStr.substring(2, 4) + "." + year;
dwr.util.setValue(this.property, dateStr);
}
if (dateStr != null && dateStr != "" && length(dateStr) <= 5 && ! dateStr.endsWith(".")) {
dateStr = dateStr + ".";
}
if (dateStr != null && dateStr != "" && length(dateStr) <= 6 && dateStr.endsWith(".")) {
dateStr = dateStr + "" + new Date().getFullYear();
dwr.util.setValue(this.property, dateStr);
}
if (dateStr != null && dateStr != "") {
return dateStr;
}
return null;
},
setNewValue: function(val) {
this._value = parseDate(val, DateElement.pattern);
setNestedBeanProperty(this.page.view.bean, this.property, this._value);
this.toggleDependent(true);
},
formattedValue: function() {
return printDate(this._value, DateElement.pattern);
},
assistDate: function() {
var dateStr = dwr.util.getValue(this.property);
var newDateStr = dateStr;
if (length(dateStr) == 2 && dateStr.indexOf(".") == - 1) {
newDateStr = newDateStr + ".";
}
else
if (length(dateStr) == 5 && dateStr.substring(dateStr.indexOf(".") + 1).indexOf(".") == - 1) {
newDateStr = newDateStr + ".";
}
if (newDateStr.endsWith("..")) {
newDateStr = newDateStr.substring(0, length(newDateStr) - 1);
}
if (newDateStr != dateStr) {
dwr.util.setValue(this.property, newDateStr);
}
},
setViewValue: function() {
if (this._value != null) {
var dateStr = printDate(this._value, DateElement.pattern);
this.setValueContent(dateStr);
}
else {
this.setEmptyValue();
}
},
setFormValue: function() {
if (this._value != null) {
var dateStr = printDate(this._value, DateElement.pattern);
dwr.util.setValue(this.property, dateStr);
}
else {
dwr.util.setValue(this.property, "");
}
},
createEditUI: function() {
var dateStr = printDate(this._value, DateElement.pattern);
var elt = elem("input",  {
type: "text",id: this.property,value: dateStr
});
this.setAttr(elt, "size", 8);
this.setAttr(elt, "title", null);
this.appendChild(elt);
Event.observe(elt, "keyup", this.assistDate.bind(this));
elt = elem("img",  {
src: this.page.path + Icons.DATE,
alt: "Výběr datumu",
onclick: function(evt) {
showCalendar(this, DateElement.pattern);
return false;
}
});
this.appendChild(elt);
},
initialize: function() {}
});
var RadioGroupElement = Class.create();
Object.extend(RadioGroupElement.prototype, RadioElement.prototype);
Object.extend(RadioGroupElement.prototype,{
setViewValue: function() {
if (this._labels != null && this._labels.length != 0) {
for (var i = 0;i < this._labels.length;i ++) {
var label = this._labels[i];
if (this.render == ViewElement.RENDER_VIEW) {
var radioView = $(this.property + "." + label.labelValue);
radioView.innerHTML = "";
var img;
if (this.hasLabelValue(label)) {
img = elem("img",  {
src: this.page.path + Icons.CHECK_TRUE
});
}
else {
img = elem("img",  {
src: this.page.path + Icons.CHECK_FALSE
});
}
img.addClassName(Style.ALIGN_MIDDLE);
radioView.appendChild(img);
}
}
}
},
clearUI: function() {
if (this.down("TR") != null) {
var header = this.down("TR").down("TH");
var firstLabel;
if (header != null) {
firstLabel = header.next("TD");
}
else {
firstLabel = this.down("TR").down("TD");
}
if (firstLabel != null) {
firstLabel.remove();
}
var rows = this.down("TR").nextSiblings();
for (var i = 0;i < rows.length;i ++) {
rows[i].remove();
}
}
},
createEditUI: function() {
if (this._labels != null && this._labels.length != 0 && this.down("TR") != null) {
var firstRowElt = this.down("TR");
if (firstRowElt.down("TH") != null) {
firstRowElt.down("TH").setAttribute("rowSpan", this._labels.length);
}
for (var i = 0;i < this._labels.length;i ++) {
var rowElt;
if (i == 0) {
rowElt = firstRowElt;
}
else {
rowElt = elem("tr");
}
var colElt = elem("td");
rowElt.appendChild(colElt);
var label = this._labels[i];
var labelElt = elem("label");
colElt.appendChild(labelElt);
var inputElt = elem("input",  {
id: this.property + "." + label.labelValue,
name: this.property,
type: "radio",
value: label.labelValue
});
inputElt.addClassName(Style.ALIGN_MIDDLE);
Event.observe(inputElt, "click", this.onValueChanged.bindAsEventListener(this, label));
labelElt.appendChild(inputElt);
labelElt.appendChild(document.createTextNode(label.labelText));
if (i > 0)
this.appendChild(rowElt);
if (this.hasLabelValue(label)) {
inputElt.checked = true;
}
}
}
},
createViewUI: function() {
if (this._labels != null && this._labels.length != 0 && this.down("TR") != null) {
var firstRowElt = this.down("TR");
if (firstRowElt != null && firstRowElt.down("TH") != null) {
firstRowElt.down("TH").setAttribute("rowSpan", this._labels.length);
}
for (var i = 0;i < this._labels.length;i ++) {
var rowElt;
if (i == 0) {
rowElt = firstRowElt;
}
else {
rowElt = elem("tr");
}
var colElt = elem("td");
rowElt.appendChild(colElt);
var label = this._labels[i];
var labelElt = elem("label");
colElt.appendChild(labelElt);
var spanElt = elem("span",  {
id: this.property + "." + label.labelValue
});
var img;
if (this.hasLabelValue(label)) {
img = elem("img",  {
src: this.page.path + Icons.CHECK_TRUE
});
}
else {
img = elem("img",  {
src: this.page.path + Icons.CHECK_FALSE
});
}
img.addClassName(Style.ALIGN_MIDDLE);
spanElt.appendChild(img);
labelElt.appendChild(spanElt);
labelElt.appendChild(document.createTextNode(label.labelText));
if (i > 0)
this.appendChild(rowElt);
}
}
},
initialize: function() {}
});
var EnumerationElement = Class.create();
Object.extend(EnumerationElement.prototype, NestedViewElement.prototype);
var EntriesElement = Class.create();
Object.extend(EntriesElement.prototype, ViewElement.prototype);
Object.extend(EntriesElement.prototype,{
rows: null,
nodes: null,
nodeOptions: null,
counter: null,
initialize: function() {
this.rows = [];
this.nodes = [];
this.nodeOptions = [];
this._value = [];
this.counter = 0;
},
setViewValue: function() {
this.rows = [];
this.counter = 0;
this.innerHTML = "";
for (var i = 0;i < length(this._value);i ++) {
this.addRow(get(this._value, i));
}
},
setFormValue: function() {
this.setViewValue();
},
clearUI: function() {
this.rows = [];
this.counter = 0;
this.innerHTML = "";
if (this.previous("*|ui") != null) {
this.previous("*|ui").hide();
}
},
createEditUI: function() {
if (this.previous("*|ui") != null) {
if (this.previous("*|ui").empty()) {
var nav = elem("img",  {
src: this.page.path + Icons.INSERT
});
nav.addClassName(Style.POINTER);
nav.addClassName(Style.SPACER);
Event.observe(nav, "click", this.onNewRow.bind(this));
this.previous("*|ui").appendChild(nav);
}
this.previous("*|ui").show();
}
this.setFormValue();
},
bindChangeListener: function() {
},
onNewRow: function() {
this.context.addEntryRow(this.property, this.addRow.bind(this));
},
onDeleteRow: function(row) {
this.context.deleteEntryRow(this.property, row.row);
row.remove();
splice(this.rows, row.row);
for (var i = row.row;i < this.rows.length;i ++) {
this.rows[i].decRowNumber();
}
},
addRow: function(row) {
var li = elem("li");
this.appendChild(li);
this.createRowElement(li, this.rows.length, row);
push(this.rows, li);
},
createRowElement: function(li,rowNum,rowValue) {
Object.extend(li, EntriesRowElement.prototype);
li.initialize();
li.parent = this;
li._value = rowValue;
li.row = rowNum;
debugPrint("new li: rowNum=" + rowNum + ", value=" + Object.toJSON(rowValue));
for (var i = 0;i < this.nodes.length;i ++) {
var entry = this.createEntry(rowNum, i, rowValue);
push(li.nodes, entry);
li.appendChild(entry.delegated);
if (this.render == ViewElement.RENDER_FORM) {
entry.render = ViewElement.RENDER_FORM;
entry.delegated.render = ViewElement.RENDER_FORM;
entry.createEditUI();
entry.bindChangeListener();
entry.bindOnFocusListener();
}
}
if (this.render == ViewElement.RENDER_FORM) {
var nav = elem("img",  {
src: this.page.path + Icons.REMOVE
});
nav.addClassName(Style.POINTER);
nav.addClassName(Style.SPACER);
Event.observe(nav, "click", this.onDeleteRow.bind(this, li));
li.appendChild(nav);
}
},
addNode: function(opts,source) {
debugPrint("entries: property=" + this.property + ", node=" + get(opts, "property"));
push(this.nodes, source);
push(this.nodeOptions, opts);
},
createEntry: function(rowNum,colNum,rowValue) {
var view = elem("mvc:view");
var options = this.nodeOptions[colNum];
var nodeProperty = get(options, "property");
this.initView(view, options, this.nodes[colNum]);
var entry = new IndexedViewElement(view);
this.initEntry(entry, rowNum, rowValue, nodeProperty);
return entry;
},
initView: function(view,options,source) {
Object.extend(view, source);
view.initialize();
view.init(this.page, options);
},
initEntry: function(entry,rowNum,rowValue,nodeProperty) {
this.counter = this.counter + 1;
entry.initEntry(this.property, this.counter, nodeProperty, rowNum, rowValue);
}
});
var IdColumn = Class.create();
Object.extend(IdColumn.prototype, NumberColumn.prototype);
Object.extend(IdColumn.prototype,{
columnHandler: function(td,options) {
td.hide();
},
displayHandler: function(value) {
return "";
},
init: function(opt) {
this.options = opt;
this.property = get(this.options, "property");
this.hide();
},
initialize: function() {}
});
var PopupWinElement = Class.create();
Object.extend(PopupWinElement.prototype, SelectElement.prototype);
Object.extend(PopupWinElement.prototype,{
popup: null,
doEnableView: function(setFocus) {
$(this.property).enable();
$(this.property).next(0).show();
$(this.property).next(1).show();
},
doDisableView: function() {
$(this.property).disable();
$(this.property).next(0).hide();
$(this.property).next(1).hide();
},
createEditUI: function() {
if (this.popup == null) {
this.popup = new PopupWin(get(this.options, "popupModule"),this, {
onAction: this.onSelect.bind(this),
width: this.getIntOption("popupWidth", 900),
heigth: this.getIntOption("popupHeigth", 730),
params: this.getPopupParams.bind(this)
});
}
var inputElt = elem("input",  {
type: "text",
id: this.property
});
inputElt.readOnly = true;
inputElt.addClassName(Style.READONLY);
this.setAttr(inputElt, "size", null);
this.setAttr(inputElt, "title", null);
this.appendChild(inputElt);
var popupElt = elem("img",  {
src: this.page.path + Icons.POPUP,alt: ""
});
popupElt.addClassName(Style.POINTER);
Event.observe(popupElt, "click", this.popup.toggle.bind(this.popup));
this.appendChild(popupElt);
var cleanElt = elem("img",  {
src: this.page.path + Icons.CLEAN,alt: ""
});
Event.observe(cleanElt, "click", this.onClearValue.bind(this));
cleanElt.addClassName(Style.POINTER);
this.appendChild(cleanElt);
this.setFormValue();
},
getPopupParams: function() {
var paramNames = Options.getStrOption(this.options, "paramNames", "").split(",");
var paramValues = Options.getStrOption(this.options, "paramValues", "").split(",");
var params = "";
if (paramNames.length > 0) {
for (var i = 0;i < paramNames.length;i ++) {
if (length(paramNames[i]) > 0) {
if (params == "")
params = "?";
else
params = params + "&";
params = params + paramNames[i] + "=" + getNestedBeanProperty(this.page.view.bean, paramValues[i]);
}
}
}
return params;
},
setViewValue: function() {
if (this._value != null) {
this.setValueContent(( this._value ).labelText);
}
else {
this.setEmptyValue();
}
},
setValueContent: function(val) {
this.innerHTML = "";
var span = elem("span");
span.addClassName(Style.VIEW_VALUE);
span.innerHTML = val;
if (this._value != null) {
var popupModule = Options.getStrOption(this.options, "popupModule", "");
var link = elem("a",  {
href: this.page.path + "/" + popupModule + ".form?" + popupModule + "Id=" + ( this._value ).labelValue
});
link.appendChild(span);
this.appendChild(link);
return link;
}
else {
this.appendChild(span);
return span;
}
},
setFormValue: function() {
if (this._value != null) {
dwr.util.setValue(this.property, ( this._value ).labelText);
}
else {
dwr.util.setValue(this.property, "");
}
},
onSelect: function(event,row) {
if (row != null) {
dwr.util.setValue(this.property, row.labelText);
this.setNewValue(row);
this.context.setProperty(this.property, row.labelValue);
}
this.popup.resetReturnValue();
},
hidePopup: function() {
this.popup.hide();
},
bindChangeListener: function() {
},
onClearValue: function() {
this.clearValue();
this.context.setProperty(this.property, null);
},
getSimpleValue: function() {
if (this._value != null) {
return ( this._value ).labelValue;
}
return "";
},
initialize: function() {}
});
var TextareaElement = Class.create();
Object.extend(TextareaElement.prototype, TextElement.prototype);
Object.extend(TextareaElement.prototype,{
createEditUI: function() {
var elt = elem("textarea",  {
id: this.property,
rows: get(this.options, "rows"),
cols: get(this.options, "cols")
});
elt.innerHTML = this._value;
this.appendChild(elt);
},
initialize: function() {}
});
var IndexedViewElement = Class.create();
Object.extend(IndexedViewElement.prototype, DelegatingViewElement.prototype);
Object.extend(IndexedViewElement.prototype,{
baseProperty: null,
entryProperty: null,
row: null,
initialize: function(d) {
this.delegated = d;
this.delegated.indexedView = this;
},
decRowNumber: function() {
this.row = this.row - 1;
},
initEntry: function(_baseProperty,counter,_entryProperty,rowNum,rowValue) {
this.baseProperty = _baseProperty;
this.entryProperty = _entryProperty;
this.delegated.property = _baseProperty + ":" + counter;
this.row = rowNum;
this.delegated._value = get(rowValue, this.entryProperty);
},
getIndexedProperty: function() {
return this.baseProperty + "[" + this.row + "]." + this.entryProperty;
}
});
var PasswordElement = Class.create();
Object.extend(PasswordElement.prototype, TextElement.prototype);
Object.extend(PasswordElement.prototype,{
createEditUI: function() {
var elt = elem("input",  {
type: "password",id: this.property
});
this.setHtmlOptions(elt);
elt.value = this._value;
this.appendChild(elt);
},
initialize: function() {}
});
var NumberElement = Class.create();
Object.extend(NumberElement.prototype, TextElement.prototype);
Object.extend(NumberElement.prototype,{
formatValue: function(val) {
if (val != null && val != "") {
var fixedSizeParameter = get(this.options, "fixedSize");
if (fixedSizeParameter != null) {
var fixedSize = parseInt(fixedSizeParameter);
return parseFloat(val).toFixed(fixedSize);
}
}
return val;
},
setHtmlOptions: function(elt) {
this.setAttr(elt, "size", 10);
this.setAttr(elt, "maxlength", null);
this.setAttr(elt, "accesskey", null);
this.setAttr(elt, "title", null);
},
initialize: function() {}
});
var IdElement = Class.create();
Object.extend(IdElement.prototype, NumberElement.prototype);


