aboutsummaryrefslogtreecommitdiff
path: root/Neutron-trunk/cms-special/admin-v2/pages/add/index.php
blob: 54dacdb07fc7665de29af8d3b099366c81143156 (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php require_once "../../../../resources/private/relative.php"; getRelativeDetails("cms-special"); ?>
<?php $pageConfig = [ "domName" => "Nouvelle page - Pages", "headerName" => "Nouvelle page" ]; require_once $_SERVER['DOCUMENT_ROOT'] . "/cms-special/admin/\$resources/precontent.php"; ?>
            <p>
                <form name="settings">
                    <div class="nd_Field nd_Field_input nd_Field__centered" id="namebox">
                            <input id="name" name="name" type="text" placeholder="<?= $lang["admin-pages"]["pagename"] ?>" spellcheck="false" autocomplete="off">
                            <label for="name"><?= $lang["admin-pages"]["pagename"] ?></label>
                        </div><br>
                    <input style="display:none;" type="radio" id="type-visual" value="visual" onchange="switchEditor()" name="type" checked>
                    <input style="display:none;" type="radio" id="type-html" onchange="switchEditor()" value="html" name="type">
                    <div style="text-align: center;"><div id="ptype-visual" class="mdc-card mdc-card--outlined mdc-card--selected" onclick="document.getElementsByName('type')[0].value = 'visual';switchEditor();" style="width:256px;margin:10px;display:inline-block;">
                        <div class="mdc-card__primary-action" tabindex="0" style="padding:0;">
                            <div class="mdc-card-wrapper__text-section" style="padding-left:5px;padding-right:5px;">
                                <h2 style="margin-bottom:5px;" class="mdc-typography mdc-typography--headline6"><?= $lang["admin-pages"]["editors"][0] ?></h2>
                                <h3 style="margin-top:5px;" class="mdc-typography mdc-typography--subtitle2"><?= $lang["admin-pages"]["editordescs"][0] ?></h3>
                            </div>
                        </div>
                    </div>
                    <div id="ptype-html" class="mdc-card mdc-card--outlined" onclick="document.getElementsByName('type')[0].value = 'html';switchEditor();" style="width:256px;margin:10px;display:inline-block;">
                        <div class="mdc-card__primary-action" tabindex="0" style="padding:0;">
                            <div class="mdc-card-wrapper__text-section" style="padding-left:5px;padding-right:5px;">
                                <h2 style="margin-bottom:5px;" class="mdc-typography mdc-typography--headline6"><?= $lang["admin-pages"]["editors"][1] ?></h2>
                                <h3 style="margin-top:5px;" class="mdc-typography mdc-typography--subtitle2"><?= $lang["admin-pages"]["editordescs"][1] ?></h3>
                            </div>
                        </div>
                    </div></div>
                </form>
            </p>
            <div id="editing"><div id="editor-visual">
                <?php
                require_once $_SERVER['DOCUMENT_ROOT'] . "/resources/private/VisualEditor$2.php";
                ?></div>
                <div id="editor-html" class="hide">
                    <?php require_once $_SERVER['DOCUMENT_ROOT'] . "/resources/private/CodeEditor$2.php" ?>
                </div>
            </div>
    <div class="hide" id="loader" style="text-align: center;"><img src="<?= $GLOBALS["SYSTEM_ROOT"] ?>/resources/image/loader.svg" class="loader"></div>
<?php require_once $_SERVER['DOCUMENT_ROOT'] . "/cms-special/admin/\$resources/postcontent.php"; ?>

<script>
    window.onbeforeunload = function (e) {
    e = e || window.event;

    // For IE and Firefox prior to version 4
    if (e) {
        e.returnValue = "<?= $lang["admin-pages"]["quitwarn"] ?>";
    }

        // For Safari
        return "<?= $lang["admin-pages"]["quitwarn"] ?>";
    };
</script>

<script>

function createPageVisual() {
    Array.from(document.getElementsByTagName('input')).forEach((el) => {el.disabled = true})
    document.getElementById('loader').classList.remove('hide')
    document.getElementById('editing').classList.add('hide')
    var formData = new FormData();
    formData.append("title", document.getElementById('name').value);
    formData.append("type", "0");
    formData.append("content", editor.getData());
    $.ajax({
        type: "POST",
        dataType: 'html',
        url: "<?= $GLOBALS["SYSTEM_ROOT"] ?>/api/admin/create_page.php",
        success: function (data) {
            if (data == "ok") {
                location.href = "<?= $GLOBALS["SYSTEM_ROOT"] ?>/cms-special/admin/pages";
            } else {
                alert("<?= $lang["admin-errors"]["errorprefix"] ?>" + data)
                Array.from(document.getElementsByTagName('input')).forEach((el) => {el.disabled = false})
                document.getElementById('loader').classList.add('hide')
                document.getElementById('editing').classList.remove('hide')
            }
        },
        error: function (error) {
            alert("<?= $lang["admin-errors"]["connerror"] ?>")
            document.getElementById('loader').classList.add('hide')
            document.getElementById('editing').classList.remove('hide')
        },
        data: formData,
        cache: false,
        contentType: false,
        processData: false
    });
}

function createPageVisualNoBack() {
    Array.from(document.getElementsByTagName('input')).forEach((el) => {el.disabled = true})
    document.getElementById('loader').classList.remove('hide')
    document.getElementById('editing').classList.add('hide')
    var formData = new FormData();
    formData.append("title", document.getElementById('name').value);
    formData.append("type", "0");
    formData.append("content", editor.getData());
    $.ajax({
        type: "POST",
        dataType: 'html',
        url: "<?= $GLOBALS["SYSTEM_ROOT"] ?>/api/admin/create_page.php",
        success: function (data) {
            if (data == "ok") {
                alert("<?= $lang["admin-pages"]["saved"] ?>");
                Array.from(document.getElementsByTagName('input')).forEach((el) => {el.disabled = false})
                document.getElementById('loader').classList.add('hide')
                document.getElementById('editing').classList.remove('hide')
            } else {
                alert("<?= $lang["admin-errors"]["errorprefix"] ?>" + data)
                Array.from(document.getElementsByTagName('input')).forEach((el) => {el.disabled = false})
                document.getElementById('loader').classList.add('hide')
                document.getElementById('editing').classList.remove('hide')
            }
        },
        error: function (error) {
            alert("<?= $lang["admin-errors"]["connerror"] ?>")
            document.getElementById('loader').classList.add('hide')
            document.getElementById('editing').classList.remove('hide')
        },
        data: formData,
        cache: false,
        contentType: false,
        processData: false
    });
}

function switchEditor() {
    if (document.forms['settings'].type.value == "visual") {
        document.getElementById('editor-visual').classList.remove('hide')
        document.getElementById('editor-html').classList.add('hide')
        document.getElementById('ptype-html').classList.remove('mdc-card--selected');
        document.getElementById('ptype-visual').classList.add('mdc-card--selected');
    } else {
        document.getElementById('editor-visual').classList.add('hide')
        document.getElementById('editor-html').classList.remove('hide')
        document.getElementById('ptype-visual').classList.remove('mdc-card--selected');
        document.getElementById('ptype-html').classList.add('mdc-card--selected');
        loadAce()
    }
    document.body.focus();
}

document.forms['settings'].type.value = "visual"

</script>