+Rakka.$previewHeader = null;
+Rakka.$previewArea = null;
+
Rakka.editPage = function (pageName) {
var $area = Rakka.switchScreen();
var $area = Rakka.switchScreen();
$area.empty();
- $area.append($.H1({}, pageName == "" ? "Create page" : "Edit page"));
+ Rakka.$previewHeader = $( $.H1({}, "Preview") );
+ $area.append(Rakka.$previewHeader);
+ Rakka.$previewHeader.hide();
+ Rakka.$previewArea = $( $.DIV({className: "preview"}) );
+ $area.append(Rakka.$previewArea);
+ Rakka.$previewArea.hide();
+
+ $area.append($.H1({}, pageName == "" ? "Create page" : "Edit page"));
+
var fldPageName
= $.INPUT({type : "text", value: pageName});
= $.INPUT({type: "button", value: "Preview page"});
$(btnPreview).click(function () {
- throw new Error("FIXME: not implemented yet");
+ if (btnTypeRakka.checked) {
+ Rakka.previewRakkaPage(
+ fldPageName.value, fldRakkaSource.value);
+ }
+ else if (btnTypeBinary.checked) {
+ Rakka.previewBinaryPage(
+ fldPageName.value, fldUploadFile.value);
+ }
});
var btnSubmit
$area.append(pageEditor);
};
+Rakka.previewRakkaPage = function (pageName, source) {
+ Rakka.displayWaitingMessage("Loading... please wait.");
+
+ var url = Rakka.baseURI + "render/" + encodeURI(pageName);
+ $.ajax({
+ type : "POST",
+ url : url,
+ contentType: "text/x-rakka",
+ data : source,
+ processData: false,
+ success : function (resultDoc) {
+ Rakka.hideWaitingMessage();
+ Rakka.showPreview(resultDoc);
+ },
+ error : function (req) {
+ alert("Error: " + req.status + " " + req.statusText);
+ }
+ });
+};
+
+Rakka.showPreview = function (doc) {
+ Rakka.$previewArea.empty();
+
+ Rakka.$previewHeader.show();
+ Rakka.$previewArea.show();
+
+ var root = doc.documentElement;
+ var child = root.firstChild;
+ do {
+ if (child.nodeType == 1) {
+ // 要素だったので複製
+ Rakka.$previewArea.append(child.cloneNode(true));
+ }
+ } while (child = child.nextSibling);
+};
+
Rakka.submitTextPage = function (pageName, oldRevision, givenPageName, mimeType, text) {
var doc = document.implementation.createDocument(
"http://cielonegro.org/schema/Rakka/Page/1.0", "page", null);