Commit realizado el 12:13:52 08-04-2024
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export default window.et_theme_options_data;
|
@@ -0,0 +1,4 @@
|
||||
// Portability states.
|
||||
export const PORTABILITY_STATE_DEFAULT = 'default';
|
||||
export const PORTABILITY_STATE_EXPORT_THEME_OPTIONS = 'export';
|
||||
export const PORTABILITY_STATE_IMPORT_THEME_OPTIONS = 'import';
|
@@ -0,0 +1,23 @@
|
||||
// External dependencies.
|
||||
import { get } from 'lodash';
|
||||
|
||||
// Internal dependencies.
|
||||
import config from './config';
|
||||
|
||||
|
||||
const i18n = (context, key, ...args) => {
|
||||
const value = get(context, key, '');
|
||||
|
||||
if ('production' !== process.env.NODE_ENV && '' === value) {
|
||||
console.error('Failed to find i18n string:', key);
|
||||
}
|
||||
|
||||
if (args.length > 0) {
|
||||
const sprintf = get(window, 'wp.i18n.sprintf');
|
||||
return sprintf(value, ...args);
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
export default (path, key, ...args) => i18n(config.i18n, [path, key], ...args);
|
@@ -0,0 +1,26 @@
|
||||
// External dependencies.
|
||||
import $ from 'jquery';
|
||||
|
||||
// Internal dependencies.
|
||||
import config from './config';
|
||||
|
||||
|
||||
export const request = (method, data, options = {}) => {
|
||||
const deferred = $.ajax({
|
||||
type: method,
|
||||
url: config.api,
|
||||
dataType: 'json',
|
||||
data,
|
||||
...options,
|
||||
});
|
||||
|
||||
return Promise.resolve(deferred.promise())
|
||||
.then(response => {
|
||||
if (false === response.success) {
|
||||
return Promise.reject(response.data || {});
|
||||
}
|
||||
return Promise.resolve(response.data);
|
||||
});
|
||||
};
|
||||
|
||||
export const post = (data, options = {}) => request('POST', data, options);
|
@@ -0,0 +1,12 @@
|
||||
// Set global variable to detect new library item creation.
|
||||
window.themeOptionsLibraryItemsLoaded = {};
|
||||
|
||||
export const setThemeOptionsLibraryItemsLoaded = (context, flag) => {
|
||||
window.themeOptionsLibraryItemsLoaded = {
|
||||
[context] : flag,
|
||||
};
|
||||
};
|
||||
|
||||
export const setThemeOptionsLibraryToken = (token) => {
|
||||
window.globalCloudToken = token;
|
||||
};
|
@@ -0,0 +1,81 @@
|
||||
import {
|
||||
noop,
|
||||
trim,
|
||||
set,
|
||||
} from 'lodash';
|
||||
|
||||
import config from '@common-ui/lib/config';
|
||||
import { post } from '@common-ui/lib/request';
|
||||
import { saveToCloudPure } from '@cloud/app/lib/api';
|
||||
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
const saveThemeOptionsToLocal = (item, content) => {
|
||||
const {
|
||||
item_name,
|
||||
selected_cats,
|
||||
new_category_name,
|
||||
new_tag_name,
|
||||
builtFor,
|
||||
} = item;
|
||||
|
||||
const {
|
||||
nonces,
|
||||
post_types,
|
||||
} = config;
|
||||
|
||||
return post({
|
||||
action: 'et_library_save_item',
|
||||
et_library_save_item_nonce: nonces.et_library_save_item,
|
||||
post_type: post_types.et_theme_options,
|
||||
item_name,
|
||||
selected_cats,
|
||||
new_category_name,
|
||||
new_tag_name,
|
||||
content,
|
||||
builtFor,
|
||||
});
|
||||
};
|
||||
|
||||
// eslint-disable-next-line arrow-parens
|
||||
const sanitizeCommaSeparatedTaxNames = (taxName) => {
|
||||
const categoryName = 'string' === typeof taxName && taxName ? taxName : '';
|
||||
|
||||
return categoryName.split(',').map(newCategory => trim(newCategory));
|
||||
};
|
||||
|
||||
const saveThemeOptionsToCloud = async (obj, content) => {
|
||||
const {
|
||||
builtFor,
|
||||
item_name,
|
||||
new_category_name,
|
||||
new_tag_name,
|
||||
providedBaseUrl,
|
||||
selected_cats,
|
||||
selected_tags,
|
||||
} = obj;
|
||||
|
||||
const newCategories = sanitizeCommaSeparatedTaxNames(new_category_name);
|
||||
const newTags = sanitizeCommaSeparatedTaxNames(new_tag_name);
|
||||
const termsData = {
|
||||
tags: [...selected_tags, ...newTags],
|
||||
categories: [...selected_cats, ...newCategories],
|
||||
};
|
||||
|
||||
const newCloudItem = {
|
||||
title: item_name,
|
||||
content,
|
||||
status: 'publish',
|
||||
};
|
||||
|
||||
if (builtFor) {
|
||||
set(newCloudItem, 'meta._built_for', builtFor);
|
||||
}
|
||||
|
||||
return saveToCloudPure('theme-options', newCloudItem, termsData, noop, 0, providedBaseUrl);
|
||||
};
|
||||
/* eslint-enable */
|
||||
|
||||
export {
|
||||
saveThemeOptionsToCloud,
|
||||
saveThemeOptionsToLocal,
|
||||
};
|
Reference in New Issue
Block a user