fix software inputfilter

parent d1152c52
This diff is collapsed.
...@@ -192,6 +192,12 @@ return function (Slim\App $app) { ...@@ -192,6 +192,12 @@ return function (Slim\App $app) {
); );
}; };
$container[Middleware\InputFilterSoftware::class] = function ($c) {
return new Middleware\InputFilterSoftware(
$c->get(InputFilter\Software::class)
);
};
$container[Middleware\FetchSchoolFromIdentity::class] = function ($c) { $container[Middleware\FetchSchoolFromIdentity::class] = function ($c) {
return new Middleware\FetchSchoolFromIdentity($c['authentication_service']); return new Middleware\FetchSchoolFromIdentity($c['authentication_service']);
}; };
...@@ -227,6 +233,10 @@ return function (Slim\App $app) { ...@@ -227,6 +233,10 @@ return function (Slim\App $app) {
); );
}; };
$container[InputFilter\Software::class] = function ($c) {
return new InputFilter\Software();
};
}); });
$events('on', 'app.bootstrap', function ($app, $container) { $events('on', 'app.bootstrap', function ($app, $container) {
...@@ -255,7 +265,8 @@ return function (Slim\App $app) { ...@@ -255,7 +265,8 @@ return function (Slim\App $app) {
$this->delete('/assets', Action\Assets\DeleteAsset::class); $this->delete('/assets', Action\Assets\DeleteAsset::class);
$this->get('/software', Action\Software\ListAll::class)->setName('school.software'); $this->get('/software', Action\Software\ListAll::class)->setName('school.software');
$this->post('/software', Action\Software\PersistSoftware::class); $this->post('/software', Action\Software\PersistSoftware::class)
->add(Middleware\InputFilterSoftware::class);
$this->delete('/software', Action\Software\DeleteSoftware::class); $this->delete('/software', Action\Software\DeleteSoftware::class);
})->add(Middleware\FetchSchoolFromIdentity::class); })->add(Middleware\FetchSchoolFromIdentity::class);
......
...@@ -141,7 +141,15 @@ ...@@ -141,7 +141,15 @@
that.model.add(response); that.model.add(response);
} }
that.hide(); that.hide();
}); }).fail(function (xhr, err) {
var messages;
if (422 === xhr.status) {
messages = JSON.parse(xhr.responseText).messages || {};
utils.formMessages.render(that.form, messages);
} else {
alert('Προέκυψε κάποιο σφάλμα');
}
});;
}, },
removeSoftware: function () { removeSoftware: function () {
var that = this; var that = this;
......
...@@ -38,11 +38,6 @@ class Software ...@@ -38,11 +38,6 @@ class Software
->attach(new Validator\NotEmpty()) ->attach(new Validator\NotEmpty())
->attach(new Validator\StringLength(['min' => 3])); ->attach(new Validator\StringLength(['min' => 3]));
$school_id = new Input('school_id');
$school_id->setRequired(true)
->getValidatorChain()
->attach(new Validator\Digits());
$lab_id = new Input('lab_id'); $lab_id = new Input('lab_id');
$lab_id->setRequired(false) $lab_id->setRequired(false)
->getValidatorChain() ->getValidatorChain()
...@@ -58,13 +53,15 @@ class Software ...@@ -58,13 +53,15 @@ class Software
$url = new Input('url'); $url = new Input('url');
$url->setRequired(false) $url->setRequired(false)
->getValidatorChain() ->getValidatorChain()
->attach(new Validator\Hostname()); ->attach(new Validator\Uri([
'allowRelative' => false,
'allowAbsolute' => true,
]));
$this->inputFilter = new InputFilter(); $this->inputFilter = new InputFilter();
$this->inputFilter $this->inputFilter
->add($id) ->add($id)
->add($softwarecategory_id) ->add($softwarecategory_id)
->add($school_id)
->add($lab_id) ->add($lab_id)
->add($title) ->add($title)
->add($vendor) ->add($vendor)
......
...@@ -118,7 +118,7 @@ class LabService implements LabServiceInterface ...@@ -118,7 +118,7 @@ class LabService implements LabServiceInterface
$responsible = sprintf("%s %s", $responsible->name, $responsible->surname); $responsible = sprintf("%s %s", $responsible->name, $responsible->surname);
} }
$lab = $bean->export(); $lab = $bean->export();
$lab['attachment_file'] = basename($lab['attachment']); $lab['attachment_file'] = basename($lab['attachment']);
return array_merge($lab, [ return array_merge($lab, [
......
...@@ -66,8 +66,8 @@ class SoftwareService implements SoftwareServiceInterface ...@@ -66,8 +66,8 @@ class SoftwareService implements SoftwareServiceInterface
private function persistSoftware($software, array $data) private function persistSoftware($software, array $data)
{ {
if (!$data['lab_id']) { if (!isset($data['lab_id']) || empty($data['lab_id'])) {
$data['lab_id'] = NULL; $data['lab_id'] = null;
} }
$software->softwarecategory_id = $data['softwarecategory_id']; $software->softwarecategory_id = $data['softwarecategory_id'];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment