And now it has crashed: see screenshot for error details and below for debug:
I hope you can help as I really need to get this theme setup and finalised.
/* global
ajaxurl, templateInfo, DataProviderHelper, SessionTimeoutError, ErrorUtility, ServerPermissionError, ErrorHelper,
FarmDeletedError
*/
var DataProvider = {};
(function() {
'use strict';
function getCmsError(response) {
var permissionErrorRegex = /.*\[permission_denied\](.*)\[permission_denied\]$/;
var error = null;
if (response === 'session_error' || response === '-1' || response === '0') {
error = new SessionTimeoutError();
error.loginUrl = templateInfo.login_page;
} else if (ErrorHelper.isThemlerHomePage(response)) {
error = new FarmDeletedError();
} else if (typeof response === 'string' && permissionErrorRegex.test(response)) {
error = new ServerPermissionError(response.match(permissionErrorRegex)[1]);
}
return error;
}
function ajaxFailHandler(url, xhr, status, callback) {
var response = getCmsError(xhr.responseText);
if (response) {
callback(response);
} else {
var error = ErrorUtility.createRequestError(url, xhr, status, 'Request fail');
callback(error);
}
}
DataProvider.doExport = function doExport(exportData, callback) {
var request = {
'save': {
'post': {
data: JSON.stringify(exportData),
action: "theme_template_export",
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
},
'url': ajaxurl
},
'clear': {
'post': {
action: "theme_template_clear",
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
},
'url': ajaxurl
},
'errorHandler': getCmsError
};
DataProviderHelper.saveChunks(request, function(error) {
if (!error) {
DataProvider.reloadTemplatesInfo(callback);
} else {
callback(error);
}
});
};
DataProvider.getTheme = function getTheme(themeName, callback) {
if (!callback || typeof callback !== 'function') {
throw DataProviderHelper.getResultError('Invalid callback');
}
themeName = (themeName || '' !== themeName) ? themeName : templateInfo.base_template_name;
window.jQuery.ajax({
url: ajaxurl,
type: 'POST',
dataType: 'json',
data: ({
action: 'theme_get_theme',
isUrl: false,
themeName: themeName,
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
})
}).done(function getThemeSuccess(data, status, xhr) {
var error = getCmsError(xhr.responseText);
if (error) {
callback(error);
} else if ($.isArray(data) && !data.length) {
callback(null);
} else if (data) {
callback(null, data);
} else {
var invalidResponseError = ErrorUtility.createRequestError(ajaxurl, xhr, status, 'getTheme() server error: ' + data);
callback(invalidResponseError);
}
}).fail(function getThemeFail(xhr, status) {
ajaxFailHandler(ajaxurl, xhr, status, callback);
});
};
DataProvider.updatePreviewTheme = function updatePreviewTheme(callback) {
if (!callback || typeof callback !== 'function') {
throw DataProviderHelper.getResultError('Invalid callback');
}
window.jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: ({
action: 'theme_update_preview',
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
})
}).done(function updatePreviewSuccess(data, status, xhr) {
var error = getCmsError(xhr.responseText);
if (error) {
callback(error);
} else if ('1' === data) {
callback(null);
} else {
var invalidResponseError = ErrorUtility.createRequestError(ajaxurl, xhr, status, 'updatePreview() server error: ' + data);
callback(invalidResponseError);
}
}).fail(function updatePreviewFail(xhr, status) {
ajaxFailHandler(ajaxurl, xhr, status, callback);
});
};
DataProvider.load = function () {
return templateInfo.projectData;
};
DataProvider.save = function save(saveData, callback) {
var request = {
'save': {
'post': {
data: JSON.stringify(saveData),
action: "theme_save_project",
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
},
'url': ajaxurl
},
'clear': {
'post': {
action: "theme_template_clear",
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
},
'url': ajaxurl
},
'errorHandler': getCmsError
};
DataProviderHelper.saveChunks(request, callback);
};
DataProvider.rename = function rename(themeName, callback) {
if (!callback || typeof callback !== 'function') {
throw DataProviderHelper.getResultError('Invalid callback');
}
window.jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: ({
action: 'theme_rename',
themeName: themeName,
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
})
}).done(function renameSuccess(data, status, xhr) {
var error = getCmsError(xhr.responseText);
if (error) {
callback(error);
} else if('1' === data) {
callback(null, window.location.href);
} else {
var invalidResponseError = ErrorUtility.createRequestError(ajaxurl, xhr, status, 'rename() server error: ' + data);
callback(invalidResponseError);
}
}).fail(function renameFail(xhr, status) {
ajaxFailHandler(ajaxurl, xhr, status, callback);
});
};
DataProvider.canRename = function canRename(themeName, callback) {
if (!callback || typeof callback !== 'function') {
throw DataProviderHelper.getResultError('Invalid callback');
}
window.jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: ({
action: 'theme_can_rename',
themeName: themeName,
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
})
}).done(function canRenameSuccess(data, status, xhr) {
var error = getCmsError(xhr.responseText);
if (error) {
callback(error);
} else if('true' === data) {
callback(null, true);
} else if('false' === data) {
callback(null, false);
} else {
var invalidResponseError = ErrorUtility.createRequestError(ajaxurl, xhr, status, 'canRename() server error: ' + data);
callback(invalidResponseError);
}
}).fail(function canRenameFail(xhr, status) {
ajaxFailHandler(ajaxurl, xhr, status, callback);
});
};
DataProvider.reloadTemplatesInfo = function reloadTemplatesInfo(callback) {
if (!callback || typeof callback !== 'function') {
throw DataProviderHelper.getResultError('Invalid callback');
}
window.jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: ({
action: 'theme_reload_info',
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
})
}).done(function reloadInfoSuccess(data, status, xhr) {
var error = getCmsError(xhr.responseText);
if (error) {
callback(error);
} else {
var info;
try {
info = JSON.parse(data);
} catch(e) {
error = new Error(e);
error.args = { parseArgument: data };
callback(error);
return;
}
$.each(info, function(key, value) {
templateInfo[key] = value;
});
callback(null);
}
}).fail(function reloadInfoFail(xhr, status) {
ajaxFailHandler(ajaxurl, xhr, status, callback);
});
};
DataProvider.backToAdmin = function backToAdmin() {
// выкидывает на базовую Ñтраницу backend-а
window.top.location = templateInfo.admin_url;
};
DataProvider.getAllCssJsSources = function getAllCssJsSources() {
return templateInfo.cssJsSources;
};
DataProvider.getMd5Hashes = function getMd5Hashes() {
return templateInfo.md5Hashes;
};
DataProvider.convertHtmlToCms = function convertHtmlToCms(fso, control) {
if (fso.exists('page.html')) {
var control_view = fso.read('page.html');
if ($.trim(control_view) === '') {
return fso;
}
if (false === /<\?php test(control_view))="" {="" var="" control_name="control.constructorName.toLowerCase()" +="" '_'="" +="" control.id;="" fso.write('page.html',=""></\?php><?php include(="" stylesheetpath="" .="" '/fragments/"="" +="" control_name="" +="" ".php');=""?>");
fso.write('fragments/' + control_name + '.php', control_view);
}
}
return fso;
};
DataProvider.getInfo = function getInfo(){
var previewUrl = 'preview=1&template=' + templateInfo.template_name + '&stylesheet=' + templateInfo.template_name + '&preview_iframe=1&TB_iframe=true';
var templates = {};
templates.home = templateInfo.home_url + '/?' + previewUrl;
templates.default = templateInfo.home_url + '/?cat=1&' + previewUrl;
if (templateInfo.woocommerce_enabled) {
templates.products = templateInfo.home_url + '/?post_type=product&' + previewUrl;
if (templateInfo.templates.product_url) {
templates.productOverview = templateInfo.home_url + '/?' + templateInfo.templates.product_url + previewUrl;
}
templates.shoppingCartTemplate = templateInfo.home_url + '/?' + templateInfo.templates.cart_url + previewUrl;
} else {
templates.products = templateInfo.home_url + '/wp-content/themes/' + templateInfo.template_name + '/no-woocommerce-template.php';
}
if (templateInfo.templates.blogpage_url){
templates.blogTemplate = templateInfo.home_url + '/?' + templateInfo.templates.blogpage_url + previewUrl;
} else {
templates.blogTemplate = templateInfo.home_url + '/wp-content/themes/' + templateInfo.template_name + '/no-blog-template.php';
}
if (templateInfo.templates.singlepost_url) {
templates.singlePostTemplate = templateInfo.home_url + '/?' + templateInfo.templates.singlepost_url + previewUrl;
}
if (templateInfo.templates.page_url) {
templates.pageTemplate = templateInfo.home_url + '/?' + templateInfo.templates.page_url + previewUrl;
}
templates.template404 = templateInfo.home_url + '/?page_id=1234567&' + previewUrl;
if (templateInfo.templates.fdm_menu_url){
templates.fdmMenuTemplate = templateInfo.home_url + '/?' + templateInfo.templates.fdm_menu_url + previewUrl;
}
if (templateInfo.templates.fdm_menu_item_url){
templates.fdmMenuItemTemplate = templateInfo.home_url + '/?' + templateInfo.templates.fdm_menu_item_url + previewUrl;
}
var infoData = {};
infoData.cmsName = 'WordPress';
infoData.cmsVersion = templateInfo.cms_version;
infoData.adminPage = templateInfo.admin_url;
infoData.startPage = templateInfo.home_url + '/?' + previewUrl;
infoData.templates = templates;
infoData.thumbnails = [{name: "screenshot.png", width: 600, height: 450}];
infoData.isThemeActive = true;
infoData.themeName = templateInfo.base_template_name;
return infoData;
};
DataProvider.getFiles = function getFiles(mask, filter, callback) {
if (!callback || typeof callback !== 'function') {
throw DataProviderHelper.getResultError('Invalid callback');
}
window.jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: ({
action: 'theme_get_files',
mask: mask,
filter:filter,
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
})
}).done(function getFilesSuccess(data, status, xhr) {
var error = getCmsError(xhr.responseText);
if (error) {
callback(error);
} else if('string' === typeof data) {
var files;
try {
files = JSON.parse(data);
} catch(e) {
callback(e);
return;
}
callback(null, files);
} else {
var invalidResponseError = ErrorUtility.createRequestError(ajaxurl, xhr, status, 'getFiles() server error: ' + data);
callback(invalidResponseError);
}
}).fail(function getFilesFail(xhr, status) {
ajaxFailHandler(ajaxurl, xhr, status, callback);
});
};
DataProvider.setFiles = function setFiles(files, callback) {
if (!callback || typeof callback !== 'function') {
throw DataProviderHelper.getResultError('Invalid callback');
}
window.jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: ({
action: 'theme_set_files',
files: JSON.stringify(files),
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
})
}).done(function setFilesSuccess(data, status, xhr) {
var error = getCmsError(xhr.responseText);
if (error) {
callback(error);
} else if('1' === data) {
callback(null);
} else {
var invalidResponseError = ErrorUtility.createRequestError(ajaxurl, xhr, status, 'setFiles() server error: ' + data);
callback(invalidResponseError);
}
}).fail(function setFilesFail(xhr, status) {
ajaxFailHandler(ajaxurl, xhr, status, callback);
});
};
})();
And now it has crashed: see screenshot for error details and below for debug:
I hope you can help as I really need to get this theme setup and finalised.
/* global
ajaxurl, templateInfo, DataProviderHelper, SessionTimeoutError, ErrorUtility, ServerPermissionError, ErrorHelper,
FarmDeletedError
*/
var DataProvider = {};
(function() {
'use strict';
function getCmsError(response) {
var permissionErrorRegex = /.*\[permission_denied\](.*)\[permission_denied\]$/;
var error = null;
if (response === 'session_error' || response === '-1' || response === '0') {
error = new SessionTimeoutError();
error.loginUrl = templateInfo.login_page;
} else if (ErrorHelper.isThemlerHomePage(response)) {
error = new FarmDeletedError();
} else if (typeof response === 'string' && permissionErrorRegex.test(response)) {
error = new ServerPermissionError(response.match(permissionErrorRegex)[1]);
}
return error;
}
function ajaxFailHandler(url, xhr, status, callback) {
var response = getCmsError(xhr.responseText);
if (response) {
callback(response);
} else {
var error = ErrorUtility.createRequestError(url, xhr, status, 'Request fail');
callback(error);
}
}
DataProvider.doExport = function doExport(exportData, callback) {
var request = {
'save': {
'post': {
data: JSON.stringify(exportData),
action: "theme_template_export",
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
},
'url': ajaxurl
},
'clear': {
'post': {
action: "theme_template_clear",
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
},
'url': ajaxurl
},
'errorHandler': getCmsError
};
DataProviderHelper.saveChunks(request, function(error) {
if (!error) {
DataProvider.reloadTemplatesInfo(callback);
} else {
callback(error);
}
});
};
DataProvider.getTheme = function getTheme(themeName, callback) {
if (!callback || typeof callback !== 'function') {
throw DataProviderHelper.getResultError('Invalid callback');
}
themeName = (themeName || '' !== themeName) ? themeName : templateInfo.base_template_name;
window.jQuery.ajax({
url: ajaxurl,
type: 'POST',
dataType: 'json',
data: ({
action: 'theme_get_theme',
isUrl: false,
themeName: themeName,
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
})
}).done(function getThemeSuccess(data, status, xhr) {
var error = getCmsError(xhr.responseText);
if (error) {
callback(error);
} else if ($.isArray(data) && !data.length) {
callback(null);
} else if (data) {
callback(null, data);
} else {
var invalidResponseError = ErrorUtility.createRequestError(ajaxurl, xhr, status, 'getTheme() server error: ' + data);
callback(invalidResponseError);
}
}).fail(function getThemeFail(xhr, status) {
ajaxFailHandler(ajaxurl, xhr, status, callback);
});
};
DataProvider.updatePreviewTheme = function updatePreviewTheme(callback) {
if (!callback || typeof callback !== 'function') {
throw DataProviderHelper.getResultError('Invalid callback');
}
window.jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: ({
action: 'theme_update_preview',
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
})
}).done(function updatePreviewSuccess(data, status, xhr) {
var error = getCmsError(xhr.responseText);
if (error) {
callback(error);
} else if ('1' === data) {
callback(null);
} else {
var invalidResponseError = ErrorUtility.createRequestError(ajaxurl, xhr, status, 'updatePreview() server error: ' + data);
callback(invalidResponseError);
}
}).fail(function updatePreviewFail(xhr, status) {
ajaxFailHandler(ajaxurl, xhr, status, callback);
});
};
DataProvider.load = function () {
return templateInfo.projectData;
};
DataProvider.save = function save(saveData, callback) {
var request = {
'save': {
'post': {
data: JSON.stringify(saveData),
action: "theme_save_project",
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
},
'url': ajaxurl
},
'clear': {
'post': {
action: "theme_template_clear",
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
},
'url': ajaxurl
},
'errorHandler': getCmsError
};
DataProviderHelper.saveChunks(request, callback);
};
DataProvider.rename = function rename(themeName, callback) {
if (!callback || typeof callback !== 'function') {
throw DataProviderHelper.getResultError('Invalid callback');
}
window.jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: ({
action: 'theme_rename',
themeName: themeName,
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
})
}).done(function renameSuccess(data, status, xhr) {
var error = getCmsError(xhr.responseText);
if (error) {
callback(error);
} else if('1' === data) {
callback(null, window.location.href);
} else {
var invalidResponseError = ErrorUtility.createRequestError(ajaxurl, xhr, status, 'rename() server error: ' + data);
callback(invalidResponseError);
}
}).fail(function renameFail(xhr, status) {
ajaxFailHandler(ajaxurl, xhr, status, callback);
});
};
DataProvider.canRename = function canRename(themeName, callback) {
if (!callback || typeof callback !== 'function') {
throw DataProviderHelper.getResultError('Invalid callback');
}
window.jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: ({
action: 'theme_can_rename',
themeName: themeName,
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
})
}).done(function canRenameSuccess(data, status, xhr) {
var error = getCmsError(xhr.responseText);
if (error) {
callback(error);
} else if('true' === data) {
callback(null, true);
} else if('false' === data) {
callback(null, false);
} else {
var invalidResponseError = ErrorUtility.createRequestError(ajaxurl, xhr, status, 'canRename() server error: ' + data);
callback(invalidResponseError);
}
}).fail(function canRenameFail(xhr, status) {
ajaxFailHandler(ajaxurl, xhr, status, callback);
});
};
DataProvider.reloadTemplatesInfo = function reloadTemplatesInfo(callback) {
if (!callback || typeof callback !== 'function') {
throw DataProviderHelper.getResultError('Invalid callback');
}
window.jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: ({
action: 'theme_reload_info',
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
})
}).done(function reloadInfoSuccess(data, status, xhr) {
var error = getCmsError(xhr.responseText);
if (error) {
callback(error);
} else {
var info;
try {
info = JSON.parse(data);
} catch(e) {
error = new Error(e);
error.args = { parseArgument: data };
callback(error);
return;
}
$.each(info, function(key, value) {
templateInfo[key] = value;
});
callback(null);
}
}).fail(function reloadInfoFail(xhr, status) {
ajaxFailHandler(ajaxurl, xhr, status, callback);
});
};
DataProvider.backToAdmin = function backToAdmin() {
// выкидывает на базовую Ñтраницу backend-а
window.top.location = templateInfo.admin_url;
};
DataProvider.getAllCssJsSources = function getAllCssJsSources() {
return templateInfo.cssJsSources;
};
DataProvider.getMd5Hashes = function getMd5Hashes() {
return templateInfo.md5Hashes;
};
DataProvider.convertHtmlToCms = function convertHtmlToCms(fso, control) {
if (fso.exists('page.html')) {
var control_view = fso.read('page.html');
if ($.trim(control_view) === '') {
return fso;
}
if (false === /<\?php test(control_view))="" {="" var="" control_name="control.constructorName.toLowerCase()" +="" '_'="" +="" control.id;="" fso.write('page.html',=""></\?php><?php include(="" stylesheetpath="" .="" '/fragments/"="" +="" control_name="" +="" ".php');=""?>");
fso.write('fragments/' + control_name + '.php', control_view);
}
}
return fso;
};
DataProvider.getInfo = function getInfo(){
var previewUrl = 'preview=1&template=' + templateInfo.template_name + '&stylesheet=' + templateInfo.template_name + '&preview_iframe=1&TB_iframe=true';
var templates = {};
templates.home = templateInfo.home_url + '/?' + previewUrl;
templates.default = templateInfo.home_url + '/?cat=1&' + previewUrl;
if (templateInfo.woocommerce_enabled) {
templates.products = templateInfo.home_url + '/?post_type=product&' + previewUrl;
if (templateInfo.templates.product_url) {
templates.productOverview = templateInfo.home_url + '/?' + templateInfo.templates.product_url + previewUrl;
}
templates.shoppingCartTemplate = templateInfo.home_url + '/?' + templateInfo.templates.cart_url + previewUrl;
} else {
templates.products = templateInfo.home_url + '/wp-content/themes/' + templateInfo.template_name + '/no-woocommerce-template.php';
}
if (templateInfo.templates.blogpage_url){
templates.blogTemplate = templateInfo.home_url + '/?' + templateInfo.templates.blogpage_url + previewUrl;
} else {
templates.blogTemplate = templateInfo.home_url + '/wp-content/themes/' + templateInfo.template_name + '/no-blog-template.php';
}
if (templateInfo.templates.singlepost_url) {
templates.singlePostTemplate = templateInfo.home_url + '/?' + templateInfo.templates.singlepost_url + previewUrl;
}
if (templateInfo.templates.page_url) {
templates.pageTemplate = templateInfo.home_url + '/?' + templateInfo.templates.page_url + previewUrl;
}
templates.template404 = templateInfo.home_url + '/?page_id=1234567&' + previewUrl;
if (templateInfo.templates.fdm_menu_url){
templates.fdmMenuTemplate = templateInfo.home_url + '/?' + templateInfo.templates.fdm_menu_url + previewUrl;
}
if (templateInfo.templates.fdm_menu_item_url){
templates.fdmMenuItemTemplate = templateInfo.home_url + '/?' + templateInfo.templates.fdm_menu_item_url + previewUrl;
}
var infoData = {};
infoData.cmsName = 'WordPress';
infoData.cmsVersion = templateInfo.cms_version;
infoData.adminPage = templateInfo.admin_url;
infoData.startPage = templateInfo.home_url + '/?' + previewUrl;
infoData.templates = templates;
infoData.thumbnails = [{name: "screenshot.png", width: 600, height: 450}];
infoData.isThemeActive = true;
infoData.themeName = templateInfo.base_template_name;
return infoData;
};
DataProvider.getFiles = function getFiles(mask, filter, callback) {
if (!callback || typeof callback !== 'function') {
throw DataProviderHelper.getResultError('Invalid callback');
}
window.jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: ({
action: 'theme_get_files',
mask: mask,
filter:filter,
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
})
}).done(function getFilesSuccess(data, status, xhr) {
var error = getCmsError(xhr.responseText);
if (error) {
callback(error);
} else if('string' === typeof data) {
var files;
try {
files = JSON.parse(data);
} catch(e) {
callback(e);
return;
}
callback(null, files);
} else {
var invalidResponseError = ErrorUtility.createRequestError(ajaxurl, xhr, status, 'getFiles() server error: ' + data);
callback(invalidResponseError);
}
}).fail(function getFilesFail(xhr, status) {
ajaxFailHandler(ajaxurl, xhr, status, callback);
});
};
DataProvider.setFiles = function setFiles(files, callback) {
if (!callback || typeof callback !== 'function') {
throw DataProviderHelper.getResultError('Invalid callback');
}
window.jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: ({
action: 'theme_set_files',
files: JSON.stringify(files),
uid: templateInfo.user,
_ajax_nonce: templateInfo.nonce
})
}).done(function setFilesSuccess(data, status, xhr) {
var error = getCmsError(xhr.responseText);
if (error) {
callback(error);
} else if('1' === data) {
callback(null);
} else {
var invalidResponseError = ErrorUtility.createRequestError(ajaxurl, xhr, status, 'setFiles() server error: ' + data);
callback(invalidResponseError);
}
}).fail(function setFilesFail(xhr, status) {
ajaxFailHandler(ajaxurl, xhr, status, callback);
});
};
})();