-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpartners.php
More file actions
70 lines (56 loc) · 2.27 KB
/
partners.php
File metadata and controls
70 lines (56 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
include'vendor/autoload.php';
$app = new Warehouse();
$m = new Partner($app->db);
if ($id = $app->stickyGET('id')) {
$m->load($id);
}
switch ($app->stickyGET('action')) {
case 'edit':
case 'add':
$form = $app->layout->add(['ui'=>'segment'])->add(['Form', 'layout'=>'FormLayout/Columns']);
$type = $app->stickyGET('type');
$form->setModel($m);
$form->add(['Button','Cancel'])->link(['action'=>false]);
$form->onSubmit(function($form) use($type) {
$form->model['is_'.$type] = true;
$form->model->save();
return new \atk4\ui\jsExpression('document.location=[]', [$form->app->url([
'id'=>$form->model->id,
'action'=>false,
'type'=>false
])]);
});
exit;
case 'delete':
if (isset($_GET['confirm'])) {
$m->delete();
header('Location: '.$app->url(['action'=>false, 'id'=>false]));
exit;
}
$m = $app->layout->add(['Message', 'Are you sure you want to delete '.$m['name'].'?', 'negative']);
$m->text->addParagraph('The record will only be marked as deleted. It will remain in the database.');
$m->add(['Button', 'Yes', 'red'])->link(['confirm'=>true]);
$m->add(['Button', 'No'])->link(['action'=>false]);;
exit;
}
$v = $app->layout->add(['ui'=>'segment']);
$c = $v->add('Columns');
$gr = $c->addColumn(12)->add('Grid');
$gr->menu->addItem('Add New Supplier')->link(['action'=>'add', 'id'=>false, 'type'=>'supplier']);
$gr->menu->addItem('Add New Client')->link( ['action'=>'add', 'id'=>false, 'type'=>'client']);
$gr->menu->addItem('Add New Producer')->link(['action'=>'add', 'id'=>false, 'type'=>'producer']);
$card = $c->addColumn(4)->add(new ui\Card());
$gr->table->addClass('selectable');
$gr->table->addStyle('cursor','pointer');
$gr->table->onRowClick(new \atk4\ui\jsReload($card, ['id'=>$gr->table->jsRow()->data('id')]))
->addClass('active')
->siblings()->removeClass('active');
$gr->setModel(clone $m, ['name', 'type', 'phone']);
$card->setModel($m);
if ($m->loaded()) {
$card->add(['Button', 'Edit', 'icon'=>'edit'], 'Buttons')->link(['action'=>'edit', 'type'=>strtolower($m['type'])]);
$card->add(['Button', 'Delete', 'icon'=>'red delete'], 'Buttons')->link(['action'=>'delete']);
} else {
$card->template->del('has_buttons');
}