~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to views/daypart-page.twig

  • Committer: Dan Garner
  • Date: 2016-02-18 16:07:16 UTC
  • mfrom: (454.4.137)
  • Revision ID: git-v1:8867f12675bc9e0e67e7e622c80da7471b9f294a
Merge pull request #139 from dasgarner/feature/nested-display-groups

Feature/nested display groups

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
{#
2
 
/*
3
 
 * Xibo - Digital Signage - http://www.xibo.org.uk
4
 
 * Copyright (C) 2012-2016 Spring Signage Ltd - http://www.springsignage.com
5
 
 *
6
 
 * This file is part of Xibo.
7
 
 *
8
 
 * Xibo is free software: you can redistribute it and/or modify
9
 
 * it under the terms of the GNU Affero General Public License as published by
10
 
 * the Free Software Foundation, either version 3 of the License, or
11
 
 * any later version.
12
 
 *
13
 
 * Xibo is distributed in the hope that it will be useful,
14
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
 * GNU Affero General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU Affero General Public License
19
 
 * along with Xibo.  If not, see <http://www.gnu.org/licenses/>.
20
 
 *
21
 
 * (daypart-page.twig)
22
 
 */
23
 
#}
24
 
{% extends "authed.twig" %}
25
 
{% import "inline.twig" as inline %}
26
 
 
27
 
{% block actionMenu %}
28
 
    <ul class="nav nav-pills pull-right">
29
 
        <li class="btn btn-success btn-xs"><a class="XiboFormButton btns" href="{{ urlFor("daypart.add.form") }}"><i class="fa fa-plus-circle" aria-hidden="true"></i> {% trans "Add Daypart" %}</a></li>
30
 
    </ul>
31
 
{% endblock %}
32
 
 
33
 
{% block pageContent %}
34
 
    <div class="widget">
35
 
        <div class="widget-title">{% trans "Dayparting" %}</div>
36
 
        <div class="widget-body">
37
 
            <div class="XiboGrid" id="{{ random() }}">
38
 
                <div class="XiboFilter">
39
 
                    <div class="FilterDiv" id="Filter">
40
 
                        <form class="form-inline">
41
 
 
42
 
                        </form>
43
 
                    </div>
44
 
                </div>
45
 
                <div class="XiboData">
46
 
                    <table id="dayparts" class="table table-striped">
47
 
                        <thead>
48
 
                            <tr>
49
 
                                <th>{% trans "Name" %}</th>
50
 
                                <th>{% trans "Description" %}</th>
51
 
                                <th>{% trans "Start Time" %}</th>
52
 
                                <th>{% trans "End Time" %}</th>
53
 
                                <th></th>
54
 
                            </tr>
55
 
                        </thead>
56
 
                        <tbody>
57
 
 
58
 
                        </tbody>
59
 
                    </table>
60
 
                </div>
61
 
            </div>
62
 
        </div>
63
 
    </div>
64
 
{% endblock %}
65
 
 
66
 
{% block javaScript %}
67
 
    <script type="text/javascript">
68
 
        Handlebars.registerHelper('if_eq', function(a, b, opts) {
69
 
            if(a == b) // Or === depending on your needs
70
 
                return opts.fn(this);
71
 
            else
72
 
                return opts.inverse(this);
73
 
        });
74
 
 
75
 
        var table = $("#dayparts").DataTable({ "language": dataTablesLanguage,
76
 
            serverSide: true, stateSave: true, stateDuration: 0,
77
 
            stateLoadCallback: function (settings, callback) {
78
 
                var data;
79
 
                $.ajax({
80
 
                    type: "GET",
81
 
                    async: false,
82
 
                    url: "{{ urlFor("user.pref") }}?preference=daypartGrid",
83
 
                    dataType: 'json',
84
 
                    success: function (json) {
85
 
                        if (json.success)
86
 
                            data = JSON.parse(json.data.value);
87
 
                    }
88
 
                });
89
 
                return data;
90
 
            },
91
 
            stateSaveCallback: function (settings, data) {
92
 
                $.ajax({
93
 
                    type: "POST",
94
 
                    url: "{{ urlFor("user.pref") }}",
95
 
                    data: {
96
 
                        preference: [{
97
 
                            option: "daypartGrid",
98
 
                            value: JSON.stringify(data)
99
 
                        }]
100
 
                    }
101
 
                });
102
 
            },
103
 
            filter: false,
104
 
            searchDelay: 3000,
105
 
            "order": [[ 1, "asc"]],
106
 
            ajax: {
107
 
                "url": "{{ urlFor("daypart.search") }}",
108
 
                "data": function(d) {
109
 
                    $.extend(d, $("#dayparts").closest(".XiboGrid").find(".FilterDiv form").serializeObject());
110
 
                }
111
 
            },
112
 
            "columns": [
113
 
                { "data": "name", "render": dataTableSpacingPreformatted },
114
 
                { "data": "description" },
115
 
                { "data": "startTime" },
116
 
                { "data": "endTime" },
117
 
                {
118
 
                    "orderable": false,
119
 
                    "data": dataTableButtonsColumn
120
 
                }
121
 
            ]
122
 
        });
123
 
 
124
 
        table.on('draw', dataTableDraw);
125
 
        table.on('processing.dt', dataTableProcessing);
126
 
 
127
 
        function dayPartFormOpen(dialog) {
128
 
            // Render a set of exceptions
129
 
            $exceptions = $(dialog).find("#dayPartExceptions");
130
 
 
131
 
            // Days of the week translations
132
 
            var daysOfTheWeek = [
133
 
                { day: "Mon", title: "{% trans "Monday" %}" },
134
 
                { day: "Tue", title: "{% trans "Tuesday" %}" },
135
 
                { day: "Wed", title: "{% trans "Wednesday" %}" },
136
 
                { day: "Thu", title: "{% trans "Thursday" %}" },
137
 
                { day: "Fri", title: "{% trans "Friday" %}" },
138
 
                { day: "Sat", title: "{% trans "Saturday" %}" },
139
 
                { day: "Sun", title: "{% trans "Sunday" %}" }
140
 
            ];
141
 
 
142
 
            // Compile the handlebars template
143
 
            var exceptionsTemplate = Handlebars.compile($("#dayPartExceptionsTemplate").html());
144
 
 
145
 
            if (dialog.data().extra.exceptions.length == 0) {
146
 
                // Contexts for template
147
 
                var context = {
148
 
                    daysOfWeek: daysOfTheWeek,
149
 
                    buttonGlyph: "fa-plus",
150
 
                    exceptionDay: "",
151
 
                    exceptionStart: "",
152
 
                    exceptionEnd: "",
153
 
                    fieldId: 0
154
 
                };
155
 
 
156
 
                // Append
157
 
                $exceptions.append(exceptionsTemplate(context));
158
 
                
159
 
                XiboInitialise("#" + $exceptions.prop("id"));
160
 
            } else {
161
 
                // For each of the existing exceptions, create form components
162
 
                var i = 0;
163
 
                $.each(dialog.data().extra.exceptions, function (index, field) {
164
 
                    i++;
165
 
                    // call the template
166
 
                    var context = {
167
 
                        daysOfWeek: daysOfTheWeek,
168
 
                        buttonGlyph: ((i == 1) ? "fa-plus" : "fa-minus"),
169
 
                        exceptionDay: field.day,
170
 
                        exceptionStart: field.start,
171
 
                        exceptionEnd: field.end,
172
 
                        fieldId: i
173
 
                    };
174
 
 
175
 
                    $exceptions.append(exceptionsTemplate(context));
176
 
                    
177
 
                    XiboInitialise("#" + $exceptions.prop("id"));
178
 
                });
179
 
            }
180
 
 
181
 
            // Nabble the resulting buttons
182
 
            $exceptions.on("click", "button", function (e) {
183
 
                e.preventDefault();
184
 
 
185
 
                // find the gylph
186
 
                if ($(this).find("i").hasClass("fa-plus")) {
187
 
                    var context = {
188
 
                        daysOfWeek: daysOfTheWeek,
189
 
                        buttonGlyph: "fa-minus",
190
 
                        exceptionDay: "",
191
 
                        exceptionStart: "",
192
 
                        exceptionEnd: "",
193
 
                        fieldId: $exceptions.find('.form-group').length + 1
194
 
                    };
195
 
 
196
 
                    $exceptions.append(exceptionsTemplate(context));
197
 
 
198
 
                    XiboInitialise("#" + $exceptions.prop("id"));
199
 
                } else {
200
 
                    // Remove this row
201
 
                    $(this).closest(".form-group").remove();
202
 
                }
203
 
            });
204
 
        }
205
 
    </script>
206
 
    {% raw %}
207
 
    <script type="text/x-handlebars-template" id="dayPartExceptionsTemplate">
208
 
        <div class="form-group">
209
 
            <div class="col-sm-3">
210
 
                <select class="form-control" name="exceptionDay[]">
211
 
                    <option value=""></option>
212
 
                    {{#each daysOfWeek}}
213
 
                    <option value="{{ day }}" {{#if_eq day ../exceptionDay}}selected{{/if_eq}}>{{ title }}</option>
214
 
                    {{/each}}
215
 
                </select>
216
 
            </div>
217
 
            <div class="col-sm-3">
218
 
                <input type="hidden" name="exceptionStartTimes[]" id="exceptionStartTimes_{{ fieldId }}" value="{{ exceptionStart }}" />
219
 
                <input class="form-control timePicker dateControl" name="exceptionStartTimesLink_{{ fieldId }}" type="text" id="exceptionStartTimesLink_{{ fieldId }}" data-link-field="exceptionStartTimes_{{ fieldId }}" data-link-format="hh:ii"/>
220
 
            </div>
221
 
            <div class="col-sm-3">
222
 
                <input type="hidden" name="exceptionEndTimes[]" id="exceptionEndTimes_{{ fieldId }}" value="{{ exceptionEnd }}" />
223
 
                <input class="form-control timePicker dateControl" name="exceptionEndTimesLink_{{ fieldId }}" type="text" id="exceptionEndTimesLink_{{ fieldId }}" data-link-field="exceptionEndTimes_{{ fieldId }}" data-link-format="hh:ii"/>
224
 
            </div>
225
 
            <div class="col-sm-1">
226
 
                <button class="btn btn-default btn-sm"><i class="fa {{ buttonGlyph }}"></i></button>
227
 
            </div>
228
 
        </div>
229
 
    </script>
230
 
    {% endraw %}
231
 
{% endblock %}
 
 
b'\\ No newline at end of file'