mirror of
https://gitnet.fr/deblan/gist.git
synced 2021-08-14 08:30:49 +02:00
refactoring, clone, cypher
This commit is contained in:
parent
1f65e8eb0b
commit
f781d06112
@ -24,7 +24,7 @@ class EditController extends Controller
|
||||
);
|
||||
|
||||
$form = new CreateGistForm($app['form.factory'], $app['translator'], $data);
|
||||
$form = $form->build();
|
||||
$form = $form->build()->getForm();
|
||||
|
||||
if ($request->isMethod('post')) {
|
||||
$form->submit($request);
|
||||
@ -54,7 +54,7 @@ class EditController extends Controller
|
||||
);
|
||||
|
||||
$form = new CloneGistForm($app['form.factory'], $app['translator'], $data);
|
||||
$form = $form->build();
|
||||
$form = $form->build()->getForm();
|
||||
|
||||
if ($request->isMethod('post')) {
|
||||
$form->submit($request);
|
||||
@ -63,7 +63,7 @@ class EditController extends Controller
|
||||
try {
|
||||
$gist = $app['gist']->commit($viewOptions['gist'], $form->getData());
|
||||
} catch (GitException $e) {
|
||||
|
||||
$gist = $viewOptions['gist'];
|
||||
}
|
||||
|
||||
$history = $app['gist']->getHistory($gist);
|
||||
|
@ -22,5 +22,10 @@ abstract class AbstractForm
|
||||
$this->builder = $formFactory->createBuilder('form', $data);
|
||||
}
|
||||
|
||||
public function getForm()
|
||||
{
|
||||
return $this->builder->getForm();
|
||||
}
|
||||
|
||||
abstract public function build(array $options = array());
|
||||
}
|
||||
|
@ -2,70 +2,18 @@
|
||||
|
||||
namespace Gist\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
|
||||
/**
|
||||
* Class CreateGistForm
|
||||
* @author Simon Vieille <simon@deblan.fr>
|
||||
*/
|
||||
class CloneGistForm extends AbstractForm
|
||||
class CloneGistForm extends CreateGistForm
|
||||
{
|
||||
public function build(array $options = array())
|
||||
{
|
||||
$this->builder->add(
|
||||
'content',
|
||||
'textarea',
|
||||
array(
|
||||
'required' => true,
|
||||
'attr' => array(
|
||||
'class' => 'form-control',
|
||||
'rows' => 10,
|
||||
),
|
||||
'constraints' => array(
|
||||
new NotBlank(array(
|
||||
'message' => $this->translator->trans('form.error.not_blank'),
|
||||
)),
|
||||
),
|
||||
)
|
||||
);
|
||||
parent::build($options);
|
||||
|
||||
$this->builder->add(
|
||||
'type',
|
||||
'choice',
|
||||
array(
|
||||
'required' => true,
|
||||
'choices' => $this->getTypes(),
|
||||
'constraints' => array(
|
||||
new NotBlank(),
|
||||
),
|
||||
)
|
||||
);
|
||||
$this->builder->remove('cipher');
|
||||
|
||||
return $this->builder->getForm();
|
||||
}
|
||||
|
||||
protected function getTypes()
|
||||
{
|
||||
$types = array(
|
||||
'xml' => '',
|
||||
'css' => '',
|
||||
'javascript' => '',
|
||||
'php' => '',
|
||||
'sql' => '',
|
||||
'yaml'=> '',
|
||||
'perl' => '',
|
||||
'c' => '',
|
||||
'asp' => '',
|
||||
'python' => '',
|
||||
'bash' => '',
|
||||
'actionscript3' => '',
|
||||
'text' => '',
|
||||
);
|
||||
|
||||
foreach ($types as $k => $v) {
|
||||
$types[$k] = $this->translator->trans('form.type.choice.'.$k);
|
||||
}
|
||||
|
||||
return $types;
|
||||
return $this->builder;
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ class CreateGistForm extends AbstractForm
|
||||
)
|
||||
);
|
||||
|
||||
return $this->builder->getForm();
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
protected function getTypes()
|
||||
|
@ -41,13 +41,6 @@
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
|
||||
<span id="cipher-label" data-tpl="{{ 'form.cipher.label'|trans }}">
|
||||
</span>
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
|
@ -35,6 +35,10 @@
|
||||
<div class="panel-heading">
|
||||
{% if not gist.cipher %}
|
||||
<div class="pull-right actions">
|
||||
<span class="btn btn-warning btn-xs">
|
||||
{{ commit|slice(0, 10) }}
|
||||
</span>
|
||||
|
||||
<a href="{{ path('raw', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm">
|
||||
<span class="glyphicon glyphicon-eye-open"></span>
|
||||
{{ 'gist.action.raw'|trans }}
|
||||
@ -51,29 +55,14 @@
|
||||
{% endif %}
|
||||
|
||||
{{ gist.title ? gist.title : 'gist.untitled'|trans }}
|
||||
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="tab-content">
|
||||
<div id="view" class="tab-pane active in">
|
||||
<div class="pull-right">
|
||||
<span class="btn btn-warning btn-xs">
|
||||
{{ commit|slice(0, 10) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="btn-toolbar">
|
||||
<div class="btn-group" id="languages">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
|
||||
Language XML
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="viewer">
|
||||
{% if gist.cipher %}
|
||||
<pre class="brush: js; syntaxhighlighter">{{ raw_content|raw }}</pre>
|
||||
<pre class="brush: {{ gist.type }}; syntaxhighlighter">{{ raw_content|raw }}</pre>
|
||||
{% else %}
|
||||
{{ content|raw }}
|
||||
{% endif %}
|
||||
|
@ -95,7 +95,9 @@ var mainEditorEvents = function() {
|
||||
}
|
||||
|
||||
var viewerEvents = function() {
|
||||
if (0 === $('.syntaxhighlighter').length) {
|
||||
var $render = $('.syntaxhighlighter');
|
||||
|
||||
if (0 === $render.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -104,10 +106,10 @@ var viewerEvents = function() {
|
||||
var parts = url.split('#key=');
|
||||
|
||||
if (parts.length === 2) {
|
||||
var decrypted = CryptoJS.AES.decrypt($('.syntaxhighlighter').html(), parts[1], {
|
||||
var decrypted = CryptoJS.AES.decrypt($render.html(), parts[1], {
|
||||
format: JsonFormatter
|
||||
});
|
||||
$('.syntaxhighlighter').text(decrypted.toString(CryptoJS.enc.Utf8));
|
||||
$render.text(decrypted.toString(CryptoJS.enc.Utf8));
|
||||
SyntaxHighlighter.all();
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user