-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathim_edit_title.php
executable file
·241 lines (216 loc) · 6.93 KB
/
im_edit_title.php
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<link rel="stylesheet" type="text/css" href="im_edit.css" media="screen" />
<?php
include("include.php");
$titleId = $_GET["id"];
$eventId = $_GET["eventId"];
function printEditableRow($row, $id, $type, $prop = false) {
$val = $row[$type];
$val = htmlentities(str_replace('\n', PHP_EOL, $val));
$newlines = substr_count($val, PHP_EOL);
$name = $row["name"];
echo '<div class="row">';
if ($prop) {
echo '<div class="label">' . $prop . '</div>';
} else {
echo '<div class="label">' . $name . '</div>';
}
echo '<div class="form"><form class="edit_form" action="javascript:true" method="GET">';
echo '<input type="hidden" name="' . $id . '" value="' . $name . '" />';
if ($newlines > 0) {
echo '<textarea class="noHotkeys" rows="' . ($newlines + 1) . '" name="' . $type . '">' . "\n" . $val . '</textarea>';
} else if ($type == 'color') {
echo '<input class="noHotkeys" type="text" name="' . $type . '" value="' . $val . '" /><span class="startPicker"></span>';
} else {
echo '<input class="noHotkeys" type="text" name="' . $type . '" value="' . $val . '" />';
}
echo '<input class="submit noHotkeys" type="submit" value="Update" />';
echo '</form></div>';
echo '</div>';
}
$title = getTitle($titleId,$eventId,false);
$geos = groupGeosByType($title['geos']);
echo '<div id="editTitle">';
if ($geos['shadowText']) {
echo "<div id=\"shadowText\"><h3>Shadow Text</h3>";
foreach ($geos['shadowText'] as $geo) {
printEditableRow($geo, $titleId, 'text');
}
echo "</div>";
}
if ($geos['plainText']) {
echo "<div id=\"plainText\"><h3>Normal Text</h3>";
foreach ($geos['plainText'] as $geo) {
printEditableRow($geo, $titleId, 'text');
}
echo "</div>";
}
if ($geos['slantRectangle']) {
echo "<div id=\"colorBars\"><h3>Color Bars</h3>";
foreach ($geos['slantRectangle'] as $geo) {
printEditableRow($geo, $titleId, 'color');
}
echo "</div>";
}
if ($geos['colorRectangle']) {
echo "<div id=\"colorRectangle\"><h3>Color Rectangle</h3>";
foreach ($geos['colorRectangle'] as $geo) {
printEditableRow($geo, $titleId, 'color');
}
echo "</div>";
}
if ($geos['placeImage']) {
echo "<div id=\"images\"><h3>Images</h3>";
foreach ($geos['placeImage'] as $geo) {
printEditableRow($geo, $titleId, 'path');
}
echo "</div>";
}
if ($geos['divingStandings']) {
$ignore = array(' ','y','w','h','name','order','type','x');
echo "<h3>Diving Standings</h3>";
foreach ($geos['divingStandings'] as $geo) {
foreach ($geo as $key=>$prop) {
if (!array_search($key,$ignore)) {
printEditableRow($geo,$titleId,$key,$key);
}
}
}
}
if ($geos['flexBox']) {
$ignore = array(' ','y','w','h','name','order','type','x');
echo "<h3>Flex Box</h3>";
foreach ($geos['flexBox'] as $geo) {
foreach ($geo as $key=>$prop) {
if (!array_search($key,$ignore)) {
printEditableRow($geo,$titleId,$key,$key);
}
}
}
}
if ($geos['weather']) {
$ignore = array(' ','y','w','h','name','order','type','x', 'logoHeight', 'logoLeft', 'lineHeight', 'boxHeight', 'boxWidth', 'boxOffset', 'boxPadding', 'titleHeight', 'titleText', 'titleGravity', 'subTitleHeight', 'subTitleWidth', 'subTitleText', 'subTitleColor', 'logoRight' );
echo "<h3>Weather Graphic</h3>";
foreach ($geos['weather'] as $geo) {
foreach ($geo as $key=>$prop) {
if (!array_search($key,$ignore)) {
printEditableRow($geo,$titleId,$key,$key);
}
}
}
}
if ($geos['gameSummary']) {
$ignore = array(' ','y','w','h','name','order','type','x');
echo "<h3>Game Summary</h3>";
foreach ($geos['gameSummary'] as $geo) {
foreach ($geo as $key=>$prop) {
if (!array_search($key,$ignore)) {
printEditableRow($geo,$titleId,$key,$key);
}
}
}
}
echo '</div>'
?>
<br style="clear:both" />
<button tid="<?= $titleId ?>" id="forceRender" name="ForceRender">Force Render</button>
<button tid="<?= $titleId ?>" id="revertChanges" name="RevertChanges">Revert Changes</button>
<script>
$(".edit_form .noHotKeys").focus( function() {
if (!$(this).data('initial')) {
$(this).data("initial", $(this).val());
}
});
$(".edit_form").change( function() { // submit on changed values
$(this).data("changed", true);
$(this).submit();
});
$(".edit_form").submit(function() {
var form = $(this);
form.children("input:last").attr("value", "Submitting");
$.ajax({
type: "POST",
url: "cdb_update.php",
data: $(this).serializeArray(),
success: function(data) {
$(this).data("changed", false); // now matches the database
form.children("input:last").attr("value", data);
window.renderQueue.addToQueue(<?= $titleId ?>);
}
});
return false;
});
function updateAll(deferred) {
var updated = 0;
var requests = [];
$(".edit_form").each(function() {
if ($(this).data("changed")) {
updated = 1;
var form = $(this);
form.children("input:last").attr("value", "Submitting");
requests.push($.ajax({
type: "POST",
url: "cdb_update.php",
data: $(this).serializeArray(),
success: function(data) {
$(this).data("changed", false); // now matches the database
form.children("input:last").attr("value", data);
}
}));
}
});
$.when(requests).then(function() {
deferred.resolve();
});
}
$("#revertChanges").click(function() { // Revert Changes Button
var deferred = $.Deferred();
$('.edit_form input[type=text]').each(function() {
if ($(this).data('initial') || $(this).data('initial')==='') {
if ($(this).val() !== $(this).data('initial')) {
$(this).val($(this).data('initial'));
$(this).parent().data('changed', true);
console.log('Reset value to '+$(this).val());
} else {
console.log('No change to revert.');
}
}
});
updateAll(deferred);
deferred.done(function() {
// We don't actually need to queue it do we?
//window.renderQueue.addToQueue(<?= $titleId ?>);
});
});
$("#forceRender").click(function() { // Force Render Button
var button = $(this);
var renderTid = $(this).attr("tid");
var deferred = $.Deferred();
updateAll(deferred);
deferred.done(function() {
button.html("Rendering");
$.ajax({
type: "GET",
url: "im_render_title.php?id="+renderTid+"&bustCache=true" + (ui.eventId ? '&eventId=' + ui.eventId : ''),
success: function(data) {
button.html("Done Rendering");
window.renderQueue.removeFromQueue(renderTid);
}
});
});
});
$(document).ready(function() {
$(".row .label:contains('Color'), .row .label:contains('color')").each( function() {
var temp1 = $(this).next().children().children().last();
$('<span class="startPicker"></span>').insertBefore( temp1 );
});
$(".startPicker").each(function() {
$(this).bind( "click", function() {
var box = $(this).prev();
box.addClass('color');
jscolor.init();
box.focus();
$(this).hide();
});
});
});
</script>