use BookStack\Activity\Models\View;
use BookStack\Activity\Tools\UserEntityWatchOptions;
use BookStack\Entities\Models\Bookshelf;
+use BookStack\Entities\Models\Page;
use BookStack\Entities\Repos\BookRepo;
use BookStack\Entities\Tools\BookContents;
use BookStack\Entities\Tools\Cloner;
$this->setPageTitle(trans('entities.books_create'));
+ $templates = Page::visible()
+ ->where('template', '=', true)
+ ->orderBy('name', 'asc')
+ ->get();
+
return view('books.create', [
'bookshelf' => $bookshelf,
+ 'templates' => $templates,
]);
}
'description' => ['string', 'max:1000'],
'image' => array_merge(['nullable'], $this->getImageValidationRules()),
'tags' => ['array'],
+ 'default_template' => ['nullable', 'exists:pages,id'],
]);
$bookshelf = null;
$this->checkOwnablePermission('book-update', $book);
$this->setPageTitle(trans('entities.books_edit_named', ['bookName' => $book->getShortName()]));
- return view('books.edit', ['book' => $book, 'current' => $book]);
+ $templates = Page::visible()
+ ->where('template', '=', true)
+ ->orderBy('name', 'asc')
+ ->get();
+
+ return view('books.edit', ['book' => $book, 'current' => $book, 'templates' => $templates]);
}
/**
'description' => ['string', 'max:1000'],
'image' => array_merge(['nullable'], $this->getImageValidationRules()),
'tags' => ['array'],
+ 'default_template' => ['nullable', 'exists:pages,id'],
]);
if ($request->has('image_reset')) {
use BookStack\Activity\Models\View;
use BookStack\Activity\Tools\CommentTree;
use BookStack\Activity\Tools\UserEntityWatchOptions;
+use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Page;
use BookStack\Entities\Repos\PageRepo;
use BookStack\Entities\Tools\BookContents;
$page = $this->pageRepo->getNewDraftPage($parent);
$this->pageRepo->publishDraft($page, [
'name' => $request->get('name'),
- 'html' => '',
]);
return redirect($page->getUrl('/edit'));
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
$this->checkOwnablePermission('page-delete', $page);
$this->setPageTitle(trans('entities.pages_delete_named', ['pageName' => $page->getShortName()]));
+ $times_used_as_template = Book::where('default_template', '=', $page->id)->count();
return view('pages.delete', [
'book' => $page->book,
'page' => $page,
'current' => $page,
+ 'times_used_as_template' => $times_used_as_template,
]);
}
public $searchFactor = 1.2;
- protected $fillable = ['name', 'description'];
+ protected $fillable = ['name', 'description', 'default_template'];
protected $hidden = ['pivot', 'image_id', 'deleted_at'];
/**
return 'cover_book';
}
+ /**
+ * Get the Page that is used as default template for newly created pages within this Book.
+ */
+ public function defaultTemplate(): BelongsTo
+ {
+ return $this->belongsTo(Page::class, 'default_template');
+ }
+
/**
* Get all pages within this book.
*/
$page->book_id = $parent->id;
}
+ if ($page->book->defaultTemplate) {
+ $page->forceFill([
+ 'html' => $page->book->defaultTemplate->html,
+ ]);
+ }
+
$page->save();
$page->refresh()->rebuildPermissions();
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddDefaultTemplateToBooks extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('books', function (Blueprint $table) {
+ $table->integer('default_template')->nullable();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('books', function (Blueprint $table) {
+ $table->dropColumn('default_template');
+ });
+ }
+}
'pages_delete_draft' => 'Delete Draft Page',
'pages_delete_success' => 'Page deleted',
'pages_delete_draft_success' => 'Draft page deleted',
+ 'pages_delete_warning_template' => '{0}|{1}Be careful: this page is used as a template for :count book.|[2,*]Be careful: this page is used as a template for :count books.',
'pages_delete_confirm' => 'Are you sure you want to delete this page?',
'pages_delete_draft_confirm' => 'Are you sure you want to delete this draft page?',
'pages_editing_named' => 'Editing Page :pageName',
'templates_replace_content' => 'Replace page content',
'templates_append_content' => 'Append to page content',
'templates_prepend_content' => 'Prepend to page content',
+ 'default_template' => 'Default Page Template',
+ 'default_template_explain' => "Assign a default template that will be used for all new pages in this book.",
// Profile View
'profile_user_for_x' => 'User for :time',
&.flexible input {
width: 100%;
}
- .search-box-cancel {
+ button.search-box-cancel {
left: auto;
right: 0;
}
<main class="content-wrap card">
<h1 class="list-heading">{{ trans('entities.books_create') }}</h1>
<form action="{{ isset($bookshelf) ? $bookshelf->getUrl('/create-book') : url('/books') }}" method="POST" enctype="multipart/form-data">
- @include('books.parts.form', ['returnLocation' => isset($bookshelf) ? $bookshelf->getUrl() : url('/books')])
+ @include('books.parts.form', [
+ 'templates' => $templates,
+ 'returnLocation' => isset($bookshelf) ? $bookshelf->getUrl() : url('/books')
+ ])
</form>
</main>
</div>
<h1 class="list-heading">{{ trans('entities.books_edit') }}</h1>
<form action="{{ $book->getUrl() }}" method="POST" enctype="multipart/form-data">
<input type="hidden" name="_method" value="PUT">
- @include('books.parts.form', ['model' => $book, 'returnLocation' => $book->getUrl()])
+ @include('books.parts.form', [
+ 'model' => $book,
+ 'templates' => $templates,
+ 'returnLocation' => $book->getUrl()
+ ])
</form>
</main>
</div>
</div>
+<div class="form-group collapsible" component="collapsible" id="template-control">
+ <button refs="collapsible@trigger" type="button" class="collapse-title text-primary" aria-expanded="false">
+ <label for="template-manager">{{ trans('entities.default_template') }}</label>
+ </button>
+ <div refs="collapsible@content" class="collapse-content">
+ @include('entities.template-manager', ['entity' => $book ?? null, 'templates' => $templates])
+ </div>
+</div>
+
<div class="form-group text-right">
<a href="{{ $returnLocation }}" class="button outline">{{ trans('common.cancel') }}</a>
<button type="submit" class="button">{{ trans('entities.books_save') }}</button>
--- /dev/null
+<p class="text-muted small">
+ {!! nl2br(e(trans('entities.default_template_explain'))) !!}
+</p>
+
+<select name="default_template" id="default_template">
+ <option value="">---</option>
+ @foreach ($templates as $template)
+ <option @if(isset($entity) && $entity->default_template === $template->id) selected @endif value="{{ $template->id }}">{{ $template->name }}</option>
+ @endforeach
+</select>
\ No newline at end of file
<div class="card content-wrap auto-height">
<h1 class="list-heading">{{ $page->draft ? trans('entities.pages_delete_draft') : trans('entities.pages_delete') }}</h1>
+ @if ($times_used_as_template > 0)
+ <p>{{ trans_choice('entities.pages_delete_warning_template', $times_used_as_template) }}</p>
+ @endif
<div class="grid half v-center">
<div>
<div class="form-group title-input">
<label for="name">{{ trans('entities.pages_name') }}</label>
- @include('form.text', ['name' => 'name'])
+ @include('form.text', ['name' => 'name', 'autofocus' => true])
</div>
<div class="form-group text-right">
<div class="search-box flexible mb-m" style="display: {{ count($templates) > 0 ? 'block' : 'none' }}">
<input refs="template-manager@searchInput" type="text" name="template-search" placeholder="{{ trans('common.search') }}">
<button refs="template-manager@searchButton" tabindex="-1" type="button">@icon('search')</button>
- <button refs="template-manager@searchCancel" class="search-box-cancel text-neg" type="button" style="display: none">@icon('close')</button>
+ <button refs="template-manager@searchCancel" class="search-box-cancel text-neg" tabindex="-1" type="button" style="display: none">@icon('close')</button>
</div>
<div refs="template-manager@list">