Now we have header image on terms
This commit is contained in:
parent
4c4c0cb063
commit
228592bfa2
|
@ -450,9 +450,9 @@
|
|||
}
|
||||
},
|
||||
"babel-core": {
|
||||
"version": "6.26.0",
|
||||
"resolved": "https://registry.npmjs.org/babel-core/-/babel-core-6.26.0.tgz",
|
||||
"integrity": "sha1-rzL3izGm/O8RnIew/Y2XU/A6C7g=",
|
||||
"version": "6.26.2",
|
||||
"resolved": "https://registry.npmjs.org/babel-core/-/babel-core-6.26.2.tgz",
|
||||
"integrity": "sha512-rFKFnHY8sbRSqja2O5eTx0z0Na5hukdtsFt7X9xdBFXMurrJ5YoY78Y/2/EuNZIaDQKEJSfxSMePfsymxt0CZg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"babel-code-frame": "^6.26.0",
|
||||
|
@ -465,21 +465,21 @@
|
|||
"babel-traverse": "^6.26.0",
|
||||
"babel-types": "^6.26.0",
|
||||
"babylon": "^6.18.0",
|
||||
"convert-source-map": "^1.5.0",
|
||||
"debug": "^2.6.8",
|
||||
"convert-source-map": "^1.5.1",
|
||||
"debug": "^2.6.9",
|
||||
"json5": "^0.5.1",
|
||||
"lodash": "^4.17.4",
|
||||
"minimatch": "^3.0.4",
|
||||
"path-is-absolute": "^1.0.1",
|
||||
"private": "^0.1.7",
|
||||
"private": "^0.1.8",
|
||||
"slash": "^1.0.0",
|
||||
"source-map": "^0.5.6"
|
||||
"source-map": "^0.5.7"
|
||||
}
|
||||
},
|
||||
"babel-generator": {
|
||||
"version": "6.26.0",
|
||||
"resolved": "https://registry.npmjs.org/babel-generator/-/babel-generator-6.26.0.tgz",
|
||||
"integrity": "sha1-rBriAHC3n248odMmlhMFN3TyDcU=",
|
||||
"version": "6.26.1",
|
||||
"resolved": "https://registry.npmjs.org/babel-generator/-/babel-generator-6.26.1.tgz",
|
||||
"integrity": "sha512-HyfwY6ApZj7BYTcJURpM5tznulaBvyio7/0d4zFOeMPUmfxkCjHocCuoLa2SAGzBI8AREcH3eP3758F672DppA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"babel-messages": "^6.23.0",
|
||||
|
@ -488,7 +488,7 @@
|
|||
"detect-indent": "^4.0.0",
|
||||
"jsesc": "^1.3.0",
|
||||
"lodash": "^4.17.4",
|
||||
"source-map": "^0.5.6",
|
||||
"source-map": "^0.5.7",
|
||||
"trim-right": "^1.0.1"
|
||||
}
|
||||
},
|
||||
|
@ -7252,9 +7252,7 @@
|
|||
"nan": {
|
||||
"version": "2.10.0",
|
||||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz",
|
||||
"integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA=="
|
||||
},
|
||||
"nanomatch": {
|
||||
"version": "1.2.9",
|
||||
|
@ -7370,9 +7368,9 @@
|
|||
}
|
||||
},
|
||||
"node-sass": {
|
||||
"version": "4.8.3",
|
||||
"resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.8.3.tgz",
|
||||
"integrity": "sha512-tfFWhUsCk/Y19zarDcPo5xpj+IW3qCfOjVdHtYeG6S1CKbQOh1zqylnQK6cV3z9k80yxAnFX9Y+a9+XysDhhfg==",
|
||||
"version": "4.9.0",
|
||||
"resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.9.0.tgz",
|
||||
"integrity": "sha512-QFHfrZl6lqRU3csypwviz2XLgGNOoWQbo2GOvtsfQqOfL4cy1BtWnhx/XUeAO9LT3ahBzSRXcEO6DdvAH9DzSg==",
|
||||
"requires": {
|
||||
"async-foreach": "^0.1.3",
|
||||
"chalk": "^1.1.1",
|
||||
|
@ -7403,11 +7401,6 @@
|
|||
"lru-cache": "^4.0.1",
|
||||
"which": "^1.2.9"
|
||||
}
|
||||
},
|
||||
"nan": {
|
||||
"version": "2.10.0",
|
||||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz",
|
||||
"integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -11571,68 +11564,11 @@
|
|||
"vue-template-es2015-compiler": "^1.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ansi-styles": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
|
||||
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"color-convert": "^1.9.0"
|
||||
}
|
||||
},
|
||||
"chalk": {
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.2.tgz",
|
||||
"integrity": "sha512-ZM4j2/ld/YZDc3Ma8PgN7gyAk+kHMMMyzLNryCPGhWrsfAuDVeuid5bpRFTDgMH9JBK2lA4dyyAkkZYF/WcqDQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ansi-styles": "^3.2.1",
|
||||
"escape-string-regexp": "^1.0.5",
|
||||
"supports-color": "^5.3.0"
|
||||
}
|
||||
},
|
||||
"has-flag": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
||||
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
|
||||
"dev": true
|
||||
},
|
||||
"loader-utils": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.1.0.tgz",
|
||||
"integrity": "sha1-yYrvSIvM7aL/teLeZG1qdUQp9c0=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"big.js": "^3.1.3",
|
||||
"emojis-list": "^2.0.0",
|
||||
"json5": "^0.5.0"
|
||||
}
|
||||
},
|
||||
"postcss": {
|
||||
"version": "6.0.21",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-6.0.21.tgz",
|
||||
"integrity": "sha512-y/bKfbQz2Nn/QBC08bwvYUxEFOVGfPIUOTsJ2CK5inzlXW9SdYR1x4pEsG9blRAF/PX+wRNdOah+gx/hv4q7dw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"chalk": "^2.3.2",
|
||||
"source-map": "^0.6.1",
|
||||
"supports-color": "^5.3.0"
|
||||
}
|
||||
},
|
||||
"source-map": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
|
||||
"dev": true
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "5.3.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.3.0.tgz",
|
||||
"integrity": "sha512-0aP01LLIskjKs3lq52EC0aGBAJhLq7B2Rd8HC/DR/PtNNpcLilNmHC12O+hu0usQpo7wtHNRqtrhBwtDb0+dNg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"has-flag": "^3.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -11649,19 +11585,6 @@
|
|||
"requires": {
|
||||
"hash-sum": "^1.0.2",
|
||||
"loader-utils": "^1.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"loader-utils": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.1.0.tgz",
|
||||
"integrity": "sha1-yYrvSIvM7aL/teLeZG1qdUQp9c0=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"big.js": "^3.1.3",
|
||||
"emojis-list": "^2.0.0",
|
||||
"json5": "^0.5.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"vue-template-compiler": {
|
||||
|
|
|
@ -41,8 +41,8 @@
|
|||
<div class="column">
|
||||
<b-field
|
||||
:addons="false"
|
||||
:type="(formErrors.name !== '' && formErrors.name !== undefined) ? 'is-danger' : ''"
|
||||
:message="formErrors.name">
|
||||
:type="((formErrors.name !== '' || formErrors.repeated !== '') && (formErrors.name !== undefined || formErrors.repeated !== undefined )) ? 'is-danger' : ''"
|
||||
:message="formErrors.name ? formErrors : formErrors.repeated">
|
||||
<label class="label">
|
||||
{{ $i18n.get('label_name') }}
|
||||
<span class="required-term-asterisk">*</span>
|
||||
|
@ -52,7 +52,8 @@
|
|||
</label>
|
||||
<b-input
|
||||
v-model="editForm.name"
|
||||
name="name"/>
|
||||
name="name"
|
||||
@focus="clearErrors({ name: 'name', repeated: 'repeated' })"/>
|
||||
</b-field>
|
||||
|
||||
<b-field
|
||||
|
@ -68,7 +69,8 @@
|
|||
<b-input
|
||||
type="textarea"
|
||||
name="description"
|
||||
v-model="editForm.description"/>
|
||||
v-model="editForm.description"
|
||||
@focus="clearErrors('description')"/>
|
||||
</b-field>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -113,7 +115,6 @@
|
|||
...mapActions('category', [
|
||||
'sendTerm',
|
||||
'updateTerm',
|
||||
'updateTermHeaderImage'
|
||||
]),
|
||||
...mapGetters('category', [
|
||||
'getTerms'
|
||||
|
@ -125,7 +126,8 @@
|
|||
categoryId: this.categoryId,
|
||||
name: this.editForm.name,
|
||||
description: this.editForm.description,
|
||||
parent: this.editForm.parent
|
||||
parent: this.editForm.parent,
|
||||
headerImageId: this.editForm.header_image_id,
|
||||
})
|
||||
.then(() => {
|
||||
this.editForm = {};
|
||||
|
@ -147,7 +149,8 @@
|
|||
termId: this.editForm.id,
|
||||
name: this.editForm.name,
|
||||
description: this.editForm.description,
|
||||
parent: this.editForm.parent
|
||||
parent: this.editForm.parent,
|
||||
headerImageId: this.editForm.header_image_id,
|
||||
})
|
||||
.then(() => {
|
||||
this.editForm.saved = true;
|
||||
|
@ -168,28 +171,18 @@
|
|||
this.$emit('onEditionCanceled', this.editForm);
|
||||
},
|
||||
deleteHeaderImage() {
|
||||
|
||||
this.updateHeaderImage({
|
||||
termId: this.editForm.id,
|
||||
headerImageId: 0
|
||||
})
|
||||
.then(() => {
|
||||
this.editForm.header_image = false;
|
||||
})
|
||||
.catch((error) => {
|
||||
this.$console.error(error);
|
||||
});
|
||||
this.editForm = Object.assign({},
|
||||
this.editForm,
|
||||
{
|
||||
header_image_id: "0",
|
||||
header_image: false
|
||||
}
|
||||
);
|
||||
},
|
||||
editImage(event) {
|
||||
'use strict';
|
||||
event.preventDefault();
|
||||
|
||||
// If the media frame already exists, reopen it.
|
||||
if ( this.frameUploader ) {
|
||||
this.frameUploader.open();
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a new media frame
|
||||
this.frameUploader = wp.media.frames.frame_uploader = wp.media({
|
||||
frame: 'select',
|
||||
|
@ -205,11 +198,11 @@
|
|||
uploader: true,
|
||||
states: [
|
||||
new wp.media.controller.Library({
|
||||
title: 'Corta pra mim! Põe exclusivo, dá trabalho pra fazer!',
|
||||
library: wp.media.query({ type: 'image' }),
|
||||
multiple: false,
|
||||
date: false,
|
||||
priority: 20,
|
||||
title: 'Corta pra mim!',
|
||||
library: wp.media.query({type: 'image'}),
|
||||
multiple: false,
|
||||
date: false,
|
||||
priority: 20,
|
||||
suggestedWidth: 1000,
|
||||
suggestedHeight: 200
|
||||
}),
|
||||
|
@ -234,46 +227,44 @@
|
|||
});
|
||||
|
||||
this.frameUploader.on('select', () => {
|
||||
this.frameUploader.state('cropper').set( 'canSkipCrop', true );
|
||||
this.frameUploader.state('cropper').set('canSkipCrop', true);
|
||||
this.frameUploader.setState('cropper');
|
||||
});
|
||||
|
||||
this.frameUploader.on('skippedcrop', () => {
|
||||
let media = this.frameUploader.state().get( 'selection' ).first().toJSON();
|
||||
let media = this.frameUploader.state().get('selection').first().toJSON();
|
||||
|
||||
this.updateTermHeaderImage({
|
||||
categoryId: this.categoryId,
|
||||
termId: this.editForm.id,
|
||||
headerImageId: media.id
|
||||
})
|
||||
.then((res) => {
|
||||
this.editForm.header_image = res.header_image;
|
||||
})
|
||||
.catch((error) => {
|
||||
this.$console.error(error);
|
||||
});
|
||||
this.editForm = Object.assign({},
|
||||
this.editForm,
|
||||
{
|
||||
header_image_id: media.id.toString(),
|
||||
header_image: media.url
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
this.frameUploader.on('cropped', (croppedImage) => {
|
||||
|
||||
// it is not cropping where we choose, but almost there
|
||||
|
||||
this.updateTermHeaderImage({
|
||||
categoryId: this.categoryId,
|
||||
termId: this.editForm.id,
|
||||
headerImageId: croppedImage.attachment_id
|
||||
})
|
||||
.then((res) => {
|
||||
this.editForm.header_image = res.header_image;
|
||||
})
|
||||
.catch((error) => {
|
||||
this.$console.error(error);
|
||||
});
|
||||
|
||||
this.editForm = Object.assign({},
|
||||
this.editForm,
|
||||
{
|
||||
header_image_id: croppedImage.attachment_id.toString(),
|
||||
header_image: croppedImage.url
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
this.frameUploader.open();
|
||||
},
|
||||
clearErrors(attributes) {
|
||||
if(attributes instanceof Object){
|
||||
for(let attribute in attributes){
|
||||
this.formErrors[attribute] = undefined;
|
||||
}
|
||||
} else {
|
||||
this.formErrors[attributes] = undefined;
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -274,12 +274,12 @@ export default {
|
|||
}
|
||||
|
||||
term.depth = termDepth;
|
||||
if (this.orderedTermsList[term.id] == undefined ) {
|
||||
if (this.orderedTermsList[term.id] === undefined ) {
|
||||
term.opened = false;
|
||||
term.saved = true ;
|
||||
} else {
|
||||
term.opened = (this.orderedTermsList[term.id].opened == undefined ? false : this.orderedTermsList[term.id].opened);
|
||||
term.saved = (this.orderedTermsList[term.id].saved == undefined ? true : this.orderedTermsList[term.id].saved);
|
||||
term.opened = (this.orderedTermsList[term.id].opened === undefined ? false : this.orderedTermsList[term.id].opened);
|
||||
term.saved = (this.orderedTermsList[term.id].saved === undefined ? true : this.orderedTermsList[term.id].saved);
|
||||
}
|
||||
if (term.taxonomy != null)
|
||||
this.orderedTermsList.push(JSON.parse(JSON.stringify(term)));
|
||||
|
|
|
@ -213,9 +213,9 @@ class Term extends Entity {
|
|||
if (!parent::validate())
|
||||
return false;
|
||||
|
||||
// $parent = $this->get_parent();
|
||||
// $name = $this->get_name();
|
||||
// $taxonomy = $this->get_taxonomy();
|
||||
$parent = $this->get_parent();
|
||||
$name = $this->get_name();
|
||||
$taxonomy = $this->get_taxonomy();
|
||||
|
||||
/**
|
||||
* Code from WordPress Core, taxonomy.php#2070
|
||||
|
@ -225,30 +225,31 @@ class Term extends Entity {
|
|||
* Prevent the creation of terms with duplicate names at the same level of a taxonomy hierarchy,
|
||||
* unless a unique slug has been explicitly provided.
|
||||
*/
|
||||
// $name_matches = get_terms( $taxonomy, array(
|
||||
// 'name' => $name,
|
||||
// 'hide_empty' => false,
|
||||
// 'parent' => $parent,
|
||||
// ) );
|
||||
$name_matches = get_terms( $taxonomy, array(
|
||||
'name' => $name,
|
||||
'hide_empty' => false,
|
||||
'parent' => $parent,
|
||||
'exclude' => $this->get_id()
|
||||
) );
|
||||
|
||||
/*
|
||||
* The `name` match in `get_terms()` doesn't differentiate accented characters,
|
||||
* so we do a stricter comparison here.
|
||||
*/
|
||||
// $name_match = null;
|
||||
// if ( $name_matches ) {
|
||||
// foreach ( $name_matches as $_match ) {
|
||||
// if ( is_object($_match) && isset($_match) && strtolower( $name ) === strtolower( $_match->name ) ) {
|
||||
// $name_match = $_match;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if ($name_match) {
|
||||
// $this->add_error( 'repeated', __('You can not have two terms with the same name at the same level', 'tainacan') );
|
||||
// return false;
|
||||
// }
|
||||
$name_match = null;
|
||||
if ( $name_matches ) {
|
||||
foreach ( $name_matches as $_match ) {
|
||||
if ( is_object($_match) && isset($_match) && strtolower( $name ) === strtolower( $_match->name ) ) {
|
||||
$name_match = $_match;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($name_match) {
|
||||
$this->add_error( 'repeated', __('You can not have two terms with the same name at the same level', 'tainacan') );
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->set_as_valid();
|
||||
return true;
|
||||
|
|
|
@ -112,12 +112,13 @@ export const fetchCategoryName = ({ commit }, categoryId) => {
|
|||
};
|
||||
|
||||
// CATEGORY TERMS
|
||||
export const sendTerm = ({commit}, { categoryId, name, description, parent }) => {
|
||||
export const sendTerm = ({commit}, { categoryId, name, description, parent, headerImageId }) => {
|
||||
return new Promise(( resolve, reject ) => {
|
||||
axios.tainacan.post('/taxonomy/' + categoryId + '/terms/', {
|
||||
name: name,
|
||||
description: description,
|
||||
parent: parent
|
||||
parent: parent,
|
||||
header_image_id: headerImageId,
|
||||
})
|
||||
.then( res => {
|
||||
let term = res.data;
|
||||
|
@ -144,12 +145,13 @@ export const deleteTerm = ({ commit }, { categoryId, termId }) => {
|
|||
});
|
||||
};
|
||||
|
||||
export const updateTerm = ({ commit }, { categoryId, termId, name, description, parent }) => {
|
||||
export const updateTerm = ({ commit }, { categoryId, termId, name, description, parent, headerImageId }) => {
|
||||
return new Promise(( resolve, reject ) => {
|
||||
axios.tainacan.patch(`/taxonomy/${categoryId}/terms/${termId}`, {
|
||||
name: name,
|
||||
description: description,
|
||||
parent: parent
|
||||
parent: parent,
|
||||
header_image_id: headerImageId,
|
||||
})
|
||||
.then( res => {
|
||||
let term = res.data;
|
||||
|
@ -162,21 +164,6 @@ export const updateTerm = ({ commit }, { categoryId, termId, name, description,
|
|||
});
|
||||
};
|
||||
|
||||
export const updateTermHeaderImage = ({ commit }, { categoryId, termId, headerImageId }) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.tainacan.patch(`/taxonomy/${categoryId}/terms/${termId}`, {
|
||||
header_image_id: headerImageId + ''
|
||||
}).then( res => {
|
||||
let term = res.data;
|
||||
commit('setSingleTerm', term);
|
||||
resolve( term );
|
||||
}).catch( error => {
|
||||
reject({ error_message: error['response']['data'].error_message, errors: error['response']['data'].errors });
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchTerms = ({ commit }, categoryId ) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.tainacan.get(`/taxonomy/${categoryId}/terms/?hideempty=0`)
|
||||
|
|
Loading…
Reference in New Issue