FIX: Associate category logo and background to uploads record.

This commit is contained in:
Guo Xiang Tan
2016-12-02 15:15:34 +08:00
parent beb8245d04
commit 9a800107cb
19 changed files with 105 additions and 45 deletions

View File

@@ -1,2 +1,40 @@
import { buildCategoryPanel } from 'discourse/components/edit-category-panel';
export default buildCategoryPanel('images');
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
export default buildCategoryPanel('images').extend({
@computed('category.uploaded_background.url')
backgroundImageUrl(uploadedBackgroundUrl) {
return uploadedBackgroundUrl || '';
},
@computed('category.uploaded_background.id')
backgroundImageId(uploadedBackgroundId) {
return uploadedBackgroundId || null;
},
@computed('category.uploaded_logo.url')
logoImageUrl(uploadedLogoUrl) {
return uploadedLogoUrl || '';
},
@computed('category.uploaded_logo.id')
logoImageId(uploadedLogoId) {
return uploadedLogoId || null;
},
@observes("backgroundImageUrl", "backgroundImageId")
_setBackgroundUpload() {
this.set("category.uploaded_background", Ember.Object.create({
id: this.get('backgroundImageId'),
url: this.get('backgroundImageUrl')
}));
},
@observes("logoImageUrl", "logoImageId")
_setLogoUpload() {
this.set("category.uploaded_logo", Ember.Object.create({
id: this.get('logoImageId'),
url: this.get('logoImageUrl')
}));
}
});

View File

@@ -12,11 +12,13 @@ export default Em.Component.extend(UploadMixin, {
uploadDone(upload) {
this.set("imageUrl", upload.url);
this.set("imageId", upload.id);
},
actions: {
trash() {
this.set("imageUrl", null);
this.set("imageId", null);
}
}
});

View File

@@ -91,8 +91,8 @@ const Category = RestModel.extend({
email_in: this.get('email_in'),
email_in_allow_strangers: this.get('email_in_allow_strangers'),
parent_category_id: this.get('parent_category_id'),
logo_url: this.get('logo_url'),
background_url: this.get('background_url'),
uploaded_logo_id: this.get('uploaded_logo.id'),
uploaded_background_id: this.get('uploaded_background.id'),
allow_badges: this.get('allow_badges'),
custom_fields: this.get('custom_fields'),
topic_template: this.get('topic_template'),

View File

@@ -11,7 +11,7 @@
</thead>
<tbody>
{{#each categories as |c|}}
<tr data-category-id={{c.id}} class="{{if c.description_excerpt 'has-description' 'no-description'}} {{if c.logo_url 'has-logo' 'no-logo'}}">
<tr data-category-id={{c.id}} class="{{if c.description_excerpt 'has-description' 'no-description'}} {{if c.uploaded_logo.url 'has-logo' 'no-logo'}}">
<td class="category" style={{border-color c.color}}>
<div>
{{category-title-link category=c}}

View File

@@ -5,7 +5,7 @@
<span class="category-name">{{category.name}}</span>
{{#if category.logo_url}}
<div>{{cdn-img src=category.logo_url class="category-logo"}}</div>
{{#if category.uploaded_logo.url}}
<div>{{cdn-img src=category.uploaded_logo.url class="category-logo"}}</div>
{{/if}}
</a>

View File

@@ -1,9 +1,16 @@
<section class='field'>
<label>{{i18n 'category.logo'}}</label>
{{image-uploader imageUrl=category.logo_url type="category_logo" class="no-repeat"}}
{{image-uploader
imageId=logoImageId
imageUrl=logoImageUrl
type="category_logo"
class="no-repeat"}}
</section>
<section class='field'>
<label>{{i18n 'category.background_image'}}</label>
{{image-uploader imageUrl=category.background_url type="category_background"}}
{{image-uploader
imageId=backgroundImageId
imageUrl=backgroundImageUrl
type="category_background"}}
</section>