-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathevent_category.phtml
205 lines (194 loc) · 7.51 KB
/
event_category.phtml
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
<html>
<head>
<meta charset='utf-8' />
<?php
require_once("inc/stdLib.php");
$menu = $_SESSION['menu'];
echo $menu['stylesheets'];
echo $menu['javascripts'];
echo $head['BOXCSS'];
echo $head['COLORPICKERCSS'];
echo $head['THEME'];
echo $head['JQBOX'];
echo $head['COLORPICKERJS'];
echo $head['T8'];
?>
<script>
$( document ).ready( function(){
var colorInput = '';
$.ajax({
url: 'ajax/event_category.php',
data: { action: 'getCategories' },
type: "POST",
success: function( json ) {
var max = 0;
var html = '';
$.each( json, function( i, val ){
html +="<li class='ui-state-default'><span class='ui-icon ui-icon-arrowthick-2-n-s'></span>"
+ " <input type='text' class='ui-widget-content ui-corner-all left' autocomplete='off' value='" + val.label + "' name='cat'></input>"
+ " <input type='text' class='ui-widget-content ui-corner-all middle' autocomplete='off' value='" + val.color + "' name='color' maxlength='7'></input>"
+ " <input type='hidden' value='" + val.id + "' name='id' ></input>"
+ " <button class='right delete' title='" + kivi.t8( 'Attention! Delete category!' ) + "' tabIndex='-1'>" + kivi.t8( 'D' ) + "</button>"
+ "</li>";
});
$( "#sortable" ).prepend( html );
$( ".right" ).tooltip({ position: { my: "center bottom-10", at: "center top" } } );
$( '#colorPick' ).colorPicker({
columns: 13, //number of columns
color: ['#FF7400', '#CDEB8B','#6BBA70','#006E2E','#C3D9FF','#0101DF','#4096EE','#356AA0','#FF0096','#DF0101','#B02B2C','#112211','#000000'], //list of colors
click: function( color ){
colorInput.value = color;
}
});
$( ".middle" ).click( function(){
colorInput = this;
var pos = $( this ).position();
$( "#colorPick" ).css({
position: 'absolute',
//left: pos.left - 230,
//top: pos.top
left: pos.left - 70,
top: pos.top - 15
}).toggle();
});
$( '.delete' ).click( function(){
const delId = $(this).prev('input')[0].value;
const delLine = $(this).parent();
$.ajax({
url: 'ajax/event_category.php',
data: { action: 'deleteCategory', data:delId },
type: "POST",
success: function(){
delLine.remove();
},
error: function(){
alert( 'Error: deleteCategory()!' );
}
});
return false;
})
},
error: function () {
alert('Error getCategories()!!');
}
});
$( "#save" ).button({
label: kivi.t8( 'save' )
}).click( function(){
var dataArr = $( "#myform" ).serializeArray();
$( '#colorPick' ).css( "display" , "none" );
//;
//remove name from array
var onlyValueArr = [];
var order = 0;
$.each( dataArr, function( index, value ){
onlyValueArr[index] = value.value;
});
// we have 3 comlumns. category, color, id (hidden)
var twoDimValueArr = [];
while( onlyValueArr.length ) twoDimValueArr.push( onlyValueArr.splice( 0, 3 ) );
//add order
$.each( twoDimValueArr, function( index, value ){
twoDimValueArr[index].push( (index + 1) );
})
const last = twoDimValueArr.length - 1;
if( twoDimValueArr[last][0] ){ // last line category is not empty,
$.ajax({
url: 'ajax/event_category.php',
data: { action: 'newCategory', data:[twoDimValueArr[last][0], twoDimValueArr[last][1], twoDimValueArr[last][3] ] },
type: "POST",
success: function( lastId ){
// add id to last hidden input named id
$( '#sortable li:last input[name=id]' ).attr( 'value', lastId );
$( '#sortable li:last' ).append( "<span class='ui-icon ui-icon-arrowthick-2-n-s'></span><button class='right delete' tabIndex='-1'>" + kivi.t8( 'D' ) + "</button>" );
var newLine = "<li class='ui-state-default'>"
+ " <input type='text' class='ui-widget-content ui-corner-all left' autocomplete='off' name='cat'></input>"
+ " <input type='text' class='ui-widget-content ui-corner-all middle' autocomplete='off' name='color' maxlength='7'></input>"
+ " <input type='hidden' name='id' ></input>"
+ "</li>";
$( "#sortable" ).append( newLine );
//$( '#sortable' ).sortable( "refresh" );
$( '.delete' ).click( function(){
const delId = lastId;
const delLine = $(this).parent();
$.ajax({
url: 'ajax/event_category.php',
data: { action: 'deleteCategory', data:delId },
type: "POST",
success: function(){
delLine.remove();
},
error: function(){
alert( 'Error: deleteCategory()!' );
}
});
return false;
})
},
});
}
twoDimValueArr.pop();// remove last array, (it's not in db)
//console.log( twoDimValueArr );
$.ajax({
url: 'ajax/event_category.php',
data: { action: 'updateCategories', data: twoDimValueArr },
type: "POST",
});
});// end save CLICK
$( "#calendar" ).button({
label: kivi.t8( 'Calendar' )
}).click( function(){
window.location.href = "calendar.phtml";
});
$( '#sortable' ).sortable({
items: 'li:not(:last-child)',
update: function(){
$( "#save" ).click();
}
});
$( '#headline' ).text( kivi.t8( 'Evemt category' ) );
$( '#head_category' ).text( kivi.t8( 'Category' ) );
$( '#head_color' ).text( kivi.t8( 'Color' ) );
});
</script>
<style>
#sortable, #head { list-style-type: none; margin: 0; padding: 0;padding-left: 2.5em; width: 400px; }
#sortable li, #head li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: 18px; }
#sortable li span { position: absolute; margin-left: -1.3em; }
.left { position:absolute; width: 180px;}
.middle { position:absolute; left:280px; width: 90px;}
.right { position:absolute; left:380px;}
#buttons { padding-left: 2.5em; padding-top: 1em; }
</style>
</head>
<body>
<?php
echo $menu['pre_content'];
echo $menu['start_content'];
?>
<div class="ui-widget-content" >
<div id="tmp"></div>
<div>
<p id="headline" class="tools ui-state-highlight ui-corner-all " style="margin-top: 20px; padding: 0.6em;"></p>
</div>
<ul id="head">
<li class="ui-state-active"><span id="head_category" class="left"></span><span id="head_color" class="middle"></span></li>
</ul>
<form id="myform">
<ul id="sortable">
<li class="ui-state-default">
<input type="text" class="ui-widget-content ui-corner-all left" autocomplete="off" name="cat"></input>
<input type="text" class="ui-widget-content ui-corner-all middle" autocomplete="off" name="color" maxlength="7"></input>
<input type='hidden' name="id"></input>
</li>
</ul>
</form>
<div id="colorPick" style="display: none"></div>
<div id="buttons">
<button id="save"></button>
<button id="calendar"></button>
</div>
</div>
<?php echo $menu['end_content']; ?>
</body>
</html>