Add import form and templates
modifié: core/lib/Thelia/Config/Resources/form.xml nouveau fichier: core/lib/Thelia/Form/ImportForm.php nouveau fichier: templates/backOffice/default/ajax/import-modal.html modifié: templates/backOffice/default/import-page.html modifié: templates/backOffice/default/import.html
This commit is contained in:
@@ -134,6 +134,7 @@
|
|||||||
<form name="thelia.images-and-documents-cache.flush" class="Thelia\Form\Cache\ImagesAndDocumentsCacheFlushForm"/>
|
<form name="thelia.images-and-documents-cache.flush" class="Thelia\Form\Cache\ImagesAndDocumentsCacheFlushForm"/>
|
||||||
|
|
||||||
<form name="thelia.export" class="Thelia\Form\ExportForm" />
|
<form name="thelia.export" class="Thelia\Form\ExportForm" />
|
||||||
|
<form name="thelia.import" class="Thelia\Form\ImportForm" />
|
||||||
|
|
||||||
</forms>
|
</forms>
|
||||||
|
|
||||||
|
|||||||
60
core/lib/Thelia/Form/ImportForm.php
Normal file
60
core/lib/Thelia/Form/ImportForm.php
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
/*************************************************************************************/
|
||||||
|
/* This file is part of the Thelia package. */
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) OpenStudio */
|
||||||
|
/* email : dev@thelia.net */
|
||||||
|
/* web : http://www.thelia.net */
|
||||||
|
/* */
|
||||||
|
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||||
|
/* file that was distributed with this source code. */
|
||||||
|
/*************************************************************************************/
|
||||||
|
|
||||||
|
namespace Thelia\Form;
|
||||||
|
use Thelia\Core\Translation\Translator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ImportForm
|
||||||
|
* @package Thelia\Form
|
||||||
|
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||||
|
*/
|
||||||
|
class ImportForm extends BaseForm
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* in this function you add all the fields you need for your Form.
|
||||||
|
* Form this you have to call add method on $this->formBuilder attribute :
|
||||||
|
*
|
||||||
|
* $this->formBuilder->add("name", "text")
|
||||||
|
* ->add("email", "email", array(
|
||||||
|
* "attr" => array(
|
||||||
|
* "class" => "field"
|
||||||
|
* ),
|
||||||
|
* "label" => "email",
|
||||||
|
* "constraints" => array(
|
||||||
|
* new \Symfony\Component\Validator\Constraints\NotBlank()
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
* ->add('age', 'integer');
|
||||||
|
*
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
protected function buildForm()
|
||||||
|
{
|
||||||
|
$this->formBuilder->add("file_upload", "file", array(
|
||||||
|
"label" => Translator::getInstance()->trans("File to upload"),
|
||||||
|
"label_attr" => ["for" => "file_to_upload"],
|
||||||
|
"required" => true,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string the name of you form. This name must be unique
|
||||||
|
*/
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return "thelia_import";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
22
templates/backOffice/default/ajax/import-modal.html
Normal file
22
templates/backOffice/default/ajax/import-modal.html
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{form name="thelia.import"}
|
||||||
|
<form action="{$URL}" method="post" {form_enctype form=$form}>
|
||||||
|
<div class="modal fade" id="real-import-modal" tabindex="-1" role="dialog" aria-labelledby="import-modal-label" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
|
||||||
|
<h4 class="modal-title" id="import-modal-label">Import: {$TITLE}</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
{custom_render_form_field form=$form field="file_upload"}
|
||||||
|
<input type="file" required aria-required="true" name="{$name}" id="{$label_attr.for}" />
|
||||||
|
{/custom_render_form_field}
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="submit" class="btn btn-primary" title="{intl l="Import this file"}">{intl l="Import this file"}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{/form}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
{extends file="admin-layout.tpl"}
|
||||||
|
|
||||||
|
{block name="no-return-functions"}
|
||||||
|
{$admin_current_location = 'tools'}
|
||||||
|
{/block}
|
||||||
|
|
||||||
|
{block name="page-title"}{intl l='Import'}: {$TITLE}{/block}
|
||||||
|
|
||||||
|
{block name="check-resource"}admin.import{/block}
|
||||||
|
{block name="check-access"}view{/block}
|
||||||
|
|
||||||
|
{block name="main-content"}
|
||||||
|
<div class="container" id="wrapper">
|
||||||
|
|
||||||
|
<nav>
|
||||||
|
<ul class="breadcrumb">
|
||||||
|
<li><a href="{url path='admin/home'}">{intl l='Home'}</a></li>
|
||||||
|
<li><a href="{url path='admin/tools'}">{intl l='Tools'}</a></li>
|
||||||
|
<li><a href="{url path='admin/import'}">{intl l="Imports"}</a></li>
|
||||||
|
<li>{intl l="Import"}: {$TITLE}</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
{form name="thelia.import"}
|
||||||
|
{if $form_error}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="alert alert-danger">{$form_error_message}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="general-block-decorator">
|
||||||
|
|
||||||
|
<div class="title title-without-tabs">
|
||||||
|
{intl l='Import'}: {$TITLE}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form action="{$URL}" method="post" {form_enctype form=$form}>
|
||||||
|
{custom_render_form_field form=$form field="file_upload"}
|
||||||
|
<input type="file" required aria-required="true" name="{$name}" id="{$label_attr.for}" />
|
||||||
|
{/custom_render_form_field}
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-primary" title="{intl l="Import this file"}">{intl l="Import this file"}</button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/form}
|
||||||
|
{/block}
|
||||||
|
|
||||||
|
{block name="javascript-last-call"}
|
||||||
|
{module_include location='configuration-js'}
|
||||||
|
{/block}
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
{assign url_import "import_order="|cat:$import_order}
|
{assign url_import "import_order="|cat:$import_order}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
<div id="import-modal"></div>
|
||||||
|
|
||||||
<div class="configuration">
|
<div class="configuration">
|
||||||
|
|
||||||
@@ -33,6 +34,7 @@
|
|||||||
{module_include location='tools_top'}
|
{module_include location='tools_top'}
|
||||||
|
|
||||||
{loop name="import-category" type="import-category" order=$category_order}
|
{loop name="import-category" type="import-category" order=$category_order}
|
||||||
|
{assign category_title $TITLE}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="general-block-decorator">
|
<div class="general-block-decorator">
|
||||||
@@ -80,7 +82,7 @@
|
|||||||
{$ID}
|
{$ID}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{$URL}">{$TITLE}</a>
|
<a href="#category_{$category_title}" class="btn-show-import-modal" data-id="{$ID}" data-url="{$URL}">{$TITLE}</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{$DESCRIPTION}
|
{$DESCRIPTION}
|
||||||
@@ -96,7 +98,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<a class="btn btn-default btn-xs" href="{$URL}" title="{intl l="Do this import"}">
|
<a class="btn btn-default btn-xs btn-show-import-modal" href="#category_{$category_title}" data-id="{$ID}" data-url="{$URL}" title="{intl l="Do this import"}">
|
||||||
<span class="glyphicon glyphicon-open"></span>
|
<span class="glyphicon glyphicon-open"></span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -123,35 +125,27 @@
|
|||||||
</div>
|
</div>
|
||||||
{/block}
|
{/block}
|
||||||
|
|
||||||
|
|
||||||
{block name="javascript-initialization"}
|
|
||||||
{javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'}
|
|
||||||
<script src="{$asset_url}"></script>
|
|
||||||
{/javascripts}
|
|
||||||
{/block}
|
|
||||||
|
|
||||||
{block name="javascript-last-call"}
|
{block name="javascript-last-call"}
|
||||||
<!-- -->
|
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var compression_switch = $(".import-compression-switch");
|
var import_modal = $("#import-modal");
|
||||||
var compression_row = $(".import-compression-selection-row");
|
|
||||||
|
|
||||||
compression_switch.on("switch-change", function(e, data) {
|
$(".btn-show-import-modal").click(function() {
|
||||||
var is_checked = data.value;
|
|
||||||
|
|
||||||
if (is_checked) {
|
var import_id = $(this).data("id");
|
||||||
compression_row.show();
|
|
||||||
} else {
|
/**
|
||||||
compression_row.hide();
|
* If we can't load the modal form, redirect to a page where the form is too.
|
||||||
}
|
*/
|
||||||
|
$.ajax(
|
||||||
|
$(this).data("url")
|
||||||
|
).success(function(data) {
|
||||||
|
import_modal.html(data);
|
||||||
|
$("#real-import-modal").modal();
|
||||||
|
}).fail(function() {
|
||||||
|
window.location.replace("{url path='/admin/import/'}"+import_id);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($("input[type=checkbox]", compression_switch).is(":checked")) {
|
|
||||||
compression_row.show();
|
|
||||||
} else {
|
|
||||||
compression_row.hide();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{module_include location='configuration-js'}
|
{module_include location='configuration-js'}
|
||||||
|
|||||||
Reference in New Issue
Block a user