dragAndDrop.php 2.48 KB
Newer Older
1
2
3
4
5
6
7
8
<?php
/**
 * Created by PhpStorm.
 * User: ep
 * Date: 12/23/15
 * Time: 6:17 PM
 */

Marc Egger's avatar
Marc Egger committed
9
namespace IMATHUZH\Qfq\Api;
10

Marc Egger's avatar
Marc Egger committed
11
require_once(__DIR__ . '/../../vendor/autoload.php');
12

13
use IMATHUZH\Qfq\Core\Helper\Path;
Marc Egger's avatar
Marc Egger committed
14
use IMATHUZH\Qfq\Core\QuickFormQuery;
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

/**
 * Return JSON encoded answer
 *
 * status: success|error
 * message: <message>
 * redirect: client|url|no
 * redirect-url: <url>
 * field-name: <field name>
 * field-message: <message>
 * form-data: [ fieldname1 => value1, fieldname2 => value2, ... ]
 * form-control: [ fieldname1 => status1, fieldname2 => status2, ... ]  status: show|hide, enabled|disabled,
 * readonly|readwrite
 *
 * Description:
 *
 * Save successful. Button 'close', 'new'. Form.forward: 'auto'. Client logic decide to redirect or not. Show message
 * if no redirect. status = 'success' message = <message> redirect = 'client'
 *
 * Save successful. Button 'close': Form.forward: 'page'. Client redirect to url.
 *  status = 'success'
 *  message = <message>
 *  redirect = 'url'
 *  redirect-url = <URL>
 *
 * Save failed: Button: any. Show message and set 'alert' on _optional_ specified form element. Bring 'pill' of
 * specified form element to front. status = 'error' message = <message> redirect = 'no' Optional: field-name = <field
 * name> field-message = <message appearing as tooltip (or similar) near the form element>
 */

$answer = array();

$answer[API_REDIRECT] = API_ANSWER_REDIRECT_NO;
$answer[API_STATUS] = API_ANSWER_STATUS_ERROR;
$answer[API_MESSAGE] = '';

try {
53
    try {
54
        Path::setMainPaths();
55
        $qfq = new QuickFormQuery(['bodytext' => '']);
56

57
        $data = $qfq->dragAndDrop();
58
        $answer = array_merge($data, $answer);
59

60
61
        $answer[API_STATUS] = API_ANSWER_STATUS_SUCCESS;
        $answer[API_MESSAGE] = 'reorder: success';
62
63
//    $answer[API_FORM_UPDATE] = $data[API_FORM_UPDATE];
//    $answer[API_ELEMENT_UPDATE] = $data[API_ELEMENT_UPDATE];
64
//    unset($answer[API_FORM_UPDATE][API_ELEMENT_UPDATE]);
Carsten  Rose's avatar
Carsten Rose committed
65
//        $answer[API_ELEMENT_UPDATE] = [ 'dynamic-125' => [ 'content' => 'latest news', 'attr' => [ 'title' => 'latest title'] ] ];
66

Marc Egger's avatar
Marc Egger committed
67
    } catch (\UserFormException $e) {
68
        $answer[API_MESSAGE] = $e->formatMessage();
Marc Egger's avatar
Marc Egger committed
69
    } catch (\CodeException $e) {
70
        $answer[API_MESSAGE] = $e->formatMessage();
Marc Egger's avatar
Marc Egger committed
71
    } catch (\DbException $e) {
72
73
        $answer[API_MESSAGE] = $e->formatMessage();
    }
74
75
76
77
78
79
80
} catch (\Exception $e) {
    $answer[API_MESSAGE] = "Generic Exception: " . $e->getMessage();
}

header("Content-Type: application/json");
echo json_encode($answer);