mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Proposals
This commit is contained in:
parent
89f3671205
commit
0658b77e71
@ -51,18 +51,47 @@ class ProposalTemplateController extends BaseController
|
||||
|
||||
public function create(ProposalTemplateRequest $request)
|
||||
{
|
||||
$data = [
|
||||
'account' => auth()->user()->account,
|
||||
$data = array_merge($this->getViewmodel(), [
|
||||
'template' => null,
|
||||
'method' => 'POST',
|
||||
'url' => 'proposals/templates',
|
||||
'title' => trans('texts.new_proposal_template'),
|
||||
'templates' => ProposalTemplate::scope()->orderBy('name')->get(),
|
||||
];
|
||||
]);
|
||||
|
||||
return View::make('proposals/templates/edit', $data);
|
||||
}
|
||||
|
||||
private function getViewmodel()
|
||||
{
|
||||
$customTemplates = ProposalTemplate::scope()->orderBy('name')->get();
|
||||
$defaultTemplates = ProposalTemplate::whereNull('account_id')->orderBy('public_id')->get();
|
||||
|
||||
$customLabel = trans('texts.custom');
|
||||
$defaultLabel = trans('texts.default');
|
||||
|
||||
foreach ($customTemplates as $template) {
|
||||
if (! isset($options[$customLabel])) {
|
||||
$options[$customLabel] = [];
|
||||
}
|
||||
$options[trans('texts.custom')][$template->public_id] = $template->name;
|
||||
}
|
||||
foreach ($defaultTemplates as $template) {
|
||||
if (! isset($options[$defaultLabel])) {
|
||||
$options[$defaultLabel] = [];
|
||||
}
|
||||
$options[trans('texts.default')][$template->public_id] = $template->name;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'account' => auth()->user()->account,
|
||||
'customTemplates' => $customTemplates,
|
||||
'defaultTemplates' => $defaultTemplates,
|
||||
'templateOptions' => $options,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function show($publicId)
|
||||
{
|
||||
Session::reflash();
|
||||
@ -86,14 +115,12 @@ class ProposalTemplateController extends BaseController
|
||||
$url = 'proposals/templates/' . $template->public_id;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'account' => auth()->user()->account,
|
||||
$data = array_merge($this->getViewmodel(), [
|
||||
'template' => $template,
|
||||
'method' => $method,
|
||||
'url' => $url,
|
||||
'title' => trans('texts.edit_proposal_template'),
|
||||
'templates' => ProposalTemplate::scope()->orderBy('name')->get(),
|
||||
];
|
||||
]);
|
||||
|
||||
return View::make('proposals/templates/edit', $data);
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ class DatabaseSeeder extends Seeder
|
||||
$this->call('GatewayTypesSeeder');
|
||||
$this->call('BanksSeeder');
|
||||
$this->call('InvoiceStatusSeeder');
|
||||
$this->call('ProposalTemplatesSeeder');
|
||||
$this->call('PaymentStatusSeeder');
|
||||
$this->call('CurrenciesSeeder');
|
||||
$this->call('DateFormatsSeeder');
|
||||
|
@ -23,34 +23,22 @@ class ProposalTemplatesSeeder extends Seeder
|
||||
|
||||
for ($i = 0; $i < count($designs); $i++) {
|
||||
$design = $designs[$i];
|
||||
$fileName = storage_path() . '/templates/' . strtolower($design) . '.js';
|
||||
if (file_exists($fileName)) {
|
||||
$pdfmake = file_get_contents($fileName);
|
||||
if ($pdfmake) {
|
||||
$record = InvoiceDesign::whereName($design)->first();
|
||||
if (! $record) {
|
||||
$record = new InvoiceDesign();
|
||||
$record->id = $i + 1;
|
||||
$record->name = $design;
|
||||
}
|
||||
$record->pdfmake = json_encode(json_decode($pdfmake)); // remove the white space
|
||||
$record->save();
|
||||
}
|
||||
}
|
||||
$baseFileName = storage_path() . '/templates/' . strtolower($design);
|
||||
$htmlFileName = $baseFileName . '.html';
|
||||
$cssFileName = $baseFileName . '.css';
|
||||
if (file_exists($htmlFileName) && file_exists($cssFileName)) {
|
||||
$template = ProposalTemplate::whereName($design)->whereAccountId(0)->first();
|
||||
|
||||
if (! $template) {
|
||||
$template = new ProposalTemplate();
|
||||
$template->public_id = $i + 1;
|
||||
$template->name = $design;
|
||||
}
|
||||
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
$name = 'Custom' . $i;
|
||||
$id = $i + 10;
|
||||
|
||||
if (InvoiceDesign::whereName($name)->orWhere('id', '=', $id)->first()) {
|
||||
continue;
|
||||
$template->html = file_get_contents($htmlFileName);
|
||||
$template->css = file_get_contents($cssFileName);
|
||||
$template->save();
|
||||
}
|
||||
|
||||
InvoiceDesign::create([
|
||||
'id' => $id,
|
||||
'name' => $name,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ class UpdateSeeder extends Seeder
|
||||
$this->call('CurrenciesSeeder');
|
||||
$this->call('DateFormatsSeeder');
|
||||
$this->call('InvoiceDesignsSeeder');
|
||||
$this->call('ProposalTemplatesSeeder');
|
||||
$this->call('PaymentTermsSeeder');
|
||||
$this->call('PaymentTypesSeeder');
|
||||
$this->call('LanguageSeeder');
|
||||
|
@ -2733,6 +2733,7 @@ $LANG = array(
|
||||
'proposal_subject' => 'New proposal :number from :account',
|
||||
'proposal_message' => 'To view your proposal for :amount, click the link below.',
|
||||
'emailed_proposal' => 'Successfully emailed proposal',
|
||||
'load_template' => 'Load Template',
|
||||
|
||||
);
|
||||
|
||||
|
@ -34,12 +34,6 @@
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
{!! Former::text('name') !!}
|
||||
|
||||
<!--
|
||||
{!! Former::select('proposal_template_id')->addOption('', '')
|
||||
->label(trans('texts.template'))
|
||||
->addGroupClass('template-select') !!}
|
||||
-->
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
{!! Former::textarea('private_notes') !!}
|
||||
@ -51,6 +45,15 @@
|
||||
</div>
|
||||
|
||||
<center class="buttons">
|
||||
|
||||
{!! Former::select()
|
||||
->style('display:inline;width:170px;background-color:white !important')
|
||||
->placeholder(trans('texts.load_template'))
|
||||
->onchange('onTemplateSelectChange()')
|
||||
->addClass('template-select')
|
||||
->options($templateOptions)
|
||||
->raw() !!}
|
||||
|
||||
@include('proposals.grapesjs_help')
|
||||
|
||||
{!! Button::normal(trans('texts.cancel'))
|
||||
@ -74,8 +77,11 @@
|
||||
<div id="gjs"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var templates = {!! $templates !!};
|
||||
var templateMap = {};
|
||||
var customTemplates = {!! $customTemplates !!};
|
||||
var customTemplateMap = {};
|
||||
|
||||
var defaultTemplates = {!! $defaultTemplates !!};
|
||||
var defaultTemplateMap = {};
|
||||
|
||||
function onFormSubmit() {
|
||||
$('#html').val(grapesjsEditor.getHtml());
|
||||
@ -84,16 +90,29 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
$(function() {
|
||||
/*
|
||||
var $proposal_templateSelect = $('select#template_id');
|
||||
for (var i = 0; i < templates.length; i++) {
|
||||
var template = templates[i];
|
||||
templateMap[template.public_id] = template;
|
||||
$templateSelect.append(new Option(template.name, template.public_id));
|
||||
function onTemplateSelectChange() {
|
||||
var templateId = $('.template-select').val();
|
||||
var group = $('.template-select :selected').parent().attr('label');
|
||||
|
||||
if (group == "{{ trans('texts.default') }}") {
|
||||
var template = defaultTemplateMap[templateId];
|
||||
} else {
|
||||
var template = customTemplateMap[templateId];
|
||||
}
|
||||
|
||||
|
||||
$('.template-select').val(null).blur();
|
||||
}
|
||||
|
||||
$(function() {
|
||||
for (var i=0; i<customTemplates.length; i++) {
|
||||
var template = customTemplates[i];
|
||||
customTemplateMap[template.public_id] = template;
|
||||
}
|
||||
for (var i=0; i<defaultTemplates.length; i++) {
|
||||
var template = defaultTemplates[i];
|
||||
defaultTemplateMap[template.public_id] = template;
|
||||
}
|
||||
@include('partials/entity_combobox', ['entityType' => ENTITY_PROPOSAL_TEMPLATE])
|
||||
*/
|
||||
})
|
||||
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user