Browse Source

Add html support

tags/0.1.0-beta.2
Sajjad Hashemian 3 years ago
parent
commit
1d35410d77
No account linked to committer's email address

+ 19
- 2
js/admin/dist/extension.js View File

@@ -65,6 +65,7 @@ System.register('sijad/pages/components/EditPageModal', ['flarum/components/Moda
this.slug = m.prop(this.page.slug() || '');
this.pageContent = m.prop(this.page.content() || '');
this.isHidden = m.prop(this.page.isHidden() && true);
this.isHtml = m.prop(this.page.isHtml() && true);
}
}, {
key: 'className',
@@ -141,6 +142,20 @@ System.register('sijad/pages/components/EditPageModal', ['flarum/components/Moda
m(
'div',
{ className: 'Form-group' },
m(
'div',
null,
m(
'label',
{ className: 'checkbox' },
m('input', { type: 'checkbox', value: '1', checked: this.isHtml(), onchange: m.withAttr('checked', this.isHtml) }),
app.translator.trans('sijad-pages.admin.edit_page.html_label')
)
)
),
m(
'div',
{ className: 'Form-group' },
Button.component({
type: 'submit',
className: 'Button Button--primary EditPageModal-save',
@@ -169,7 +184,8 @@ System.register('sijad/pages/components/EditPageModal', ['flarum/components/Moda
title: this.pageTitle(),
slug: this.slug(),
content: this.pageContent(),
isHidden: this.isHidden()
isHidden: this.isHidden(),
isHtml: this.isHtml()
}, { errorHandler: this.onerror.bind(this) }).then(this.hide.bind(this)).catch(function () {
_this3.loading = false;
m.redraw();
@@ -589,7 +605,8 @@ System.register('sijad/pages/models/Page', ['flarum/Model', 'flarum/utils/mixin'
contentHtml: Model.attribute('contentHtml'),
contentPlain: computed('contentHtml', getPlainContent),
slug: Model.attribute('slug'),
isHidden: Model.attribute('isHidden')
isHidden: Model.attribute('isHidden'),
isHtml: Model.attribute('isHtml')
}));

_export('default', Page);

+ 11
- 0
js/admin/src/components/EditPageModal.js View File

@@ -16,6 +16,7 @@ export default class EditPageModal extends Modal {
this.slug = m.prop(this.page.slug() || '');
this.pageContent = m.prop(this.page.content() || '');
this.isHidden = m.prop(this.page.isHidden() && true);
this.isHtml = m.prop(this.page.isHtml() && true);
}

className() {
@@ -62,6 +63,15 @@ export default class EditPageModal extends Modal {
</label>
</div>
</div>

<div className="Form-group">
<div>
<label className="checkbox">
<input type="checkbox" value="1" checked={this.isHtml()} onchange={m.withAttr('checked', this.isHtml)}/>
{app.translator.trans('sijad-pages.admin.edit_page.html_label')}
</label>
</div>
</div>
<div className="Form-group">
{Button.component({
type: 'submit',
@@ -90,6 +100,7 @@ export default class EditPageModal extends Modal {
slug: this.slug(),
content: this.pageContent(),
isHidden: this.isHidden(),
isHtml: this.isHtml(),
}, {errorHandler: this.onerror.bind(this)})
.then(this.hide.bind(this))
.catch(() => {

+ 2
- 1
js/forum/dist/extension.js View File

@@ -213,7 +213,8 @@ System.register('sijad/pages/models/Page', ['flarum/Model', 'flarum/utils/mixin'
contentHtml: Model.attribute('contentHtml'),
contentPlain: computed('contentHtml', getPlainContent),
slug: Model.attribute('slug'),
isHidden: Model.attribute('isHidden')
isHidden: Model.attribute('isHidden'),
isHtml: Model.attribute('isHtml')
}));

_export('default', Page);

+ 2
- 1
js/lib/models/Page.js View File

@@ -11,5 +11,6 @@ export default class Page extends mixin(Model, {
contentHtml: Model.attribute('contentHtml'),
contentPlain: computed('contentHtml', getPlainContent),
slug: Model.attribute('slug'),
isHidden: Model.attribute('isHidden')
isHidden: Model.attribute('isHidden'),
isHtml: Model.attribute('isHtml')
}) {}

+ 1
- 0
locale/en.yml View File

@@ -14,6 +14,7 @@ sijad-pages:
delete_page_button: Delete Page
delete_page_confirmation: "Are you sure you want to delete this page?"
hidden_label: Save as Draft
html_label: Enable Html
slug_label: => sijad-pages.ref.slug
slug_placeholder: => sijad-pages.ref.slug
submit_button: => core.ref.save_changes

+ 1
- 0
locale/ru.yml View File

@@ -14,6 +14,7 @@ sijad-pages:
delete_page_button: Удалить страницу
delete_page_confirmation: "Вы уверены, что хотите удалить эту страницу?"
hidden_label: Сохранить как черновик
html_label: Enable Html
slug_label: => sijad-pages.ref.slug
slug_placeholder: => sijad-pages.ref.slug
submit_button: => core.ref.save_changes

+ 10
- 0
migrations/2016_08_28_180020_add_is_html.php View File

@@ -0,0 +1,10 @@
<?php

use Flarum\Database\Migration;

return Migration::addColumns(
'pages',
[
'is_html' => ['boolean', 'default' => 0]
]
);

+ 1
- 1
src/Api/Serializer/PageSerializer.php View File

@@ -22,7 +22,7 @@ class PageSerializer extends AbstractSerializer
'slug' => $page->slug,
'time' => $page->time,
'editTime' => $page->edit_time,
'contentHtml' => $page->content_html,
'contentHtml' => $page->is_html ? nl2br($page->content) : $page->content_html,
];

if ($this->actor->isAdmin()) {

+ 4
- 0
src/Command/EditPageHandler.php View File

@@ -64,6 +64,10 @@ class EditPageHandler
$page->is_hidden = $attributes['isHidden'];
}

if (isset($attributes['isHtml'])) {
$page->is_html = $attributes['isHtml'];
}

$page->edit_time = time();

$this->validator->assertValid($page->getDirty());

+ 9
- 0
src/Page.php View File

@@ -13,6 +13,15 @@ class Page extends AbstractModel
protected $table = 'pages';

/**
* @var array
*/
protected $casts = [
'id' => 'integer',
'is_hidden' => 'boolean',
'is_html' => 'boolean',
];

/**
* {@inheritdoc}
*/
protected $dates = ['time', 'edit_time'];

Loading…
Cancel
Save