xooki.action.createChildPage = function()

in xookiEdit.js [335:376]


xooki.action.createChildPage = function (child) {
    if (typeof child.meta == 'undefined' || typeof child.meta.level == 'undefined') {
        if (typeof child.meta == 'undefined') child.meta = {};
        child.meta.level = child.id.split('/').length - 1;
    }
        
    var pagetpl = xooki.url.loadURL(cu("blankPageTpl"));
    if (pagetpl != null) {
        var childURL = pu(child.id);
        var localPath = xooki.io.getLocalPath(childURL);
        var original = xooki.io.loadFile(localPath);
        if (original != null) {
            if (!window.confirm(t("File for child page:\n${0}\nalready exists.\nAre you sure you want to continue and overwrite it?", localPath))) 
                return;
        }
        
        xooki.page.children.push(child);
        xooki.toc.save();
        
        // usually used by templates
        if (typeof child.relroot == 'undefined') {
            child.relroot = "";
        	for (var i=0; i < child.meta.level; i++) {
        		child.relroot += "../";
        	}
        }
        child.level = child.meta.level;
		var revised = xooki.string.processTemplate(pagetpl, child);
    	var save;
    	try {
    		// Save new file
    		save = xooki.io.saveFile(localPath,xooki.io.fixEOL(revised));
    	} catch (e) {
    		xooki.error(e);
    	} 
        if(save) {
    		// go to child page
            window.location = childURL;
    	} else
    		xooki.error(t("Impossible to save changes to ${0}", localPath));
    }
}