var YaRu = {
onDialogLoad: function () {
if (window.yaWinArguments.hasData)
{
let grid = document.getElementById("livewindow-grid");
grid.setAttribute("hasJournal","yes");
this._loadYaRuFriends();
this._setEnabled(false);
}

if (window.yaWinArguments.domXMLResponse)
{
let domXMLResponse = window.yaWinArguments.domXMLResponse;
if (domXMLResponse.querySelector("ok").getAttribute("yaru_link"))
{
let destDoc = this.api.XMLUtils.getDOMParser(null,null,true).parseFromString("<emptyDoc/>","text/xml");
let xul = this.api.XMLUtils.transformXMLToFragment(domXMLResponse,this._xslBookmarksYaRuPostDoc(),destDoc);
document.getElementById("livewindow-post-props").appendChild(xul);
}

}

document.title = document.documentElement.getAttribute("yaTitleLiveWindow");
document.documentElement.getButton("cancel").label = this.getLocalizedString("closeWindowButtonLabel");
}
,
_xslBookmarksYaRuPostDoc: function () {
var xslDoc = null;
try {
let docURL = "native/fx/dialogs/bookmarks/xsl-yaru-post-props.xsl";
let channel = this.api.Package.getFileInputChannel(docURL);
xslDoc = this.api.XMLUtils.xmlDocFromStream(channel.contentStream,this.utils.newURI(this.api.Package.resolvePath(docURL),null,null),null,true);
return xslDoc;
}
catch (ex) {
this.api.logger.error(ex);
return null;
}

}
,
_getEnabled: function () {
return this.__enabled;
}
,
_setEnabled: function (val) {
this.__enabled = val;
document.documentElement.getButton("cancel").disabled = ! val;
}
,
onDialogUnload: function () {
var dontShow = document.getElementById("dont-show-again").checked;
this.fireEvent("accept",{
bookmarkData: window.yaWinArguments.data,
showYaRuWindow: ! dontShow});
}
,
_loadYaRuFriends: function () {
var finalWrapper = (function finalWrapper(xul) {
this._onYaRuUserFriendsDataCallback(xul);
window.sizeToContent();
this._setEnabled(true);
}
).bind(this);
window.yaWinArguments.services.getYaRuFriendsList(window.yaWinArguments.auth.user.name,finalWrapper,finalWrapper);
document.getElementById("livewindow-deck").selectedIndex = 0;
}
,
_onYaRuUserFriendsDataCallback: function (xul) {
var linksDiv = document.getElementById("livewindow-firends-links");
linksDiv.appendChild(xul);
document.getElementById("livewindow-deck").selectedIndex = 1;
}
};
