-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
253 lines (215 loc) · 7.85 KB
/
Copy pathindex.php
File metadata and controls
253 lines (215 loc) · 7.85 KB
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
242
243
244
245
246
247
248
249
250
251
252
<html>
<head>
<script src="jquery-2.0.3.min.js"></script>
<meta charset=utf-8 />
<title></title>
</head>
<body>
<div class="lists-holder"></div>
<div class="list-holder"></div>
</body>
</html>
<script>
var launcherId = 'simon';
var liveListId = -1;
$(document).ready(function(){
refreshRevisionList(function() {
refreshAppList(liveListId);
});
});
var refreshRevisionList = function(callback) {
$.ajax({
url: 'api/com/?req={"ListRevisionReq":{"launcherId":"' + launcherId +'"}}',
context: document.body
}).done(function(result) {
var data = $.parseJSON(result);
var lists = data.ListRevisionResp.result.lists;
liveListId = data.ListRevisionResp.result.liveList;
var editRevisionExists = false;
$(".lists-holder").html('');
var editRevisionExists = false;
$(lists).each(function(index, list) {
if('1' != list.has_been_live) {
editRevisionExists = true;
}
var listItem = listItemHtml(list);
$(".lists-holder").append(listItem);
});
$(".list-item").click(listsItemAction);
if(!editRevisionExists) {
var buttonCreateRevision =
'<input type="button" class="button-create-revision" value="Edit" data="' + liveListId + '">';
$(".lists-holder").append(buttonCreateRevision);
$(".button-create-revision").click(createRevisionAction);
}
if(callback) {
callback.apply(data);
}
});
};
var listItemHtml = function(list) {
var buttonText = list.changed + ' revision ' + list.id;
if(liveListId == list.id) {
buttonText += ' [LIVE]';
} else if('1' == list.has_been_live) {
buttonText += ' [WAS LIVE]';
} else {
buttonText += ' [EDIT]';
}
var listItem =
'<input type="button" class="list-item" value="' + buttonText + '" data="' + list.id + '">';
return listItem;
};
var listsItemAction = function() {
var revision = $(this).attr('data');
refreshAppList(revision);
};
var createRevisionAction = function() {
var revision = $(this).attr('data');
var url = 'api/com/?req={"NewListRevisionReq":{"launcherId":"' + launcherId + '","baseList":"' + revision + '"}}';
$.ajax({
url: url,
context: document.body
}).done(function(result) {
var obj = $.parseJSON(result);
refreshRevisionList();
var newListId = obj.NewListRevisionResp.result.list_id;
if(newListId) {
refreshAppList(newListId);
}
});
};
var refreshAppList = function(revision) {
var url = 'api/com/?req={"ListReq":{"launcherId":"' + launcherId + '","revision":"' + revision + '"}}';
$.ajax({
url: url,
context: document.body
}).done(function(result) {
var obj = $.parseJSON(result);
$(".list-holder").html(listHtml(obj.ListResp));
if(obj.ListResp.hasBeenLive) {
$(".list-holder").find(":input").prop("disabled", true);
}
$(".button-add-app").click(addAppAction);
$(".button-delete-app").click(deleteAppAction);
$(".button-delete-list").click(deleteListAction);
$(".button-publish-list").click(publishListAction);
});
};
var deleteListAction = function() {
$(this).prop('disabled', true);
var revision = $(this).closest(".app-list").attr('data');
var req = {};
var data = {};
data.launcherId = launcherId;
data.revision = revision;
req.DeleteListRevisionReq = data;
var reqStr = JSON.stringify(req);
var url = 'api/com/?req=' + reqStr;
$.ajax({
url: url,
context: document.body
}).done(function(result) {
refreshRevisionList();
refreshAppList(liveListId);
});
}
var publishListAction = function() {
$(this).prop('disabled', true);
var revision = $(this).closest(".app-list").attr('data');
var req = {};
var data = {};
data.launcherId = launcherId;
data.appListId = revision;
req.PublishListReq = data;
var reqStr = JSON.stringify(req);
var url = 'api/com/?req=' + reqStr;
$.ajax({
url: url,
context: document.body
}).done(function(result) {
refreshRevisionList();
refreshAppList(revision);
});
}
var addAppAction = function() {
$(this).prop('disabled', true);
var appId = $(this).parent().find(".input-app-id").val();
var revision = $(this).closest(".app-list").attr('data');
var position = $(this).parent().parent().find(".input-position").val();
var latitude = $(this).parent().parent().find(".input-latitude").val();
var longitude = $(this).parent().parent().find(".input-longitude").val();
var req = {};
var AddToListReq = {};
AddToListReq.appId = appId;
AddToListReq.appListId = revision;
AddToListReq.position = position;
if('' != latitude) {
AddToListReq.latitude = latitude;
}
if('' != longitude) {
AddToListReq.longitude = longitude;
}
req.AddToListReq = AddToListReq;
var reqStr = JSON.stringify(req);
var url = 'api/com/?req=' + reqStr;
$.ajax({
url: url,
context: document.body
}).done(function(result) {
refreshAppList(revision);
});
};
var deleteAppAction = function() {
$(this).prop('disabled', true);
var appId = $(this).parent().find(".input-app-id").val();
var appListId = $(this).closest(".app-list").attr('data');
var url = 'api/com/?req={"RemoveFromListReq":{"appId":"' + appId + '","appListId":' +appListId + '}}';
$.ajax({
url: url,
context: document.body
}).done(function(result) {
refreshAppList(appListId);
});
}
var listHtml = function(appListResp){
var appList = appListResp.tile;
var revision = appListResp.revision;
var result = '<ul class="app-list" data="' + revision + '">';
result += '<input type="button" class="button-delete-list" value="Discard">';
result += '<input type="button" class="button-publish-list" value="Publish">';
$(appList).each(function(index, item) {
var app = item.appTile;
if(typeof(app.latitude) == 'undefined') {
app.latitude = '';
}
if(typeof(app.longitude) == 'undefined') {
app.longitude = '';
}
result += '<li>';
result += '<div class="title-holder">' + app.title + '</div>';
result += '<div class="developer-holder">' + app.developer + '</div>';
result += '<div class="icon-holder"><img src="' + app.iconUri +'=w64"></div>';
result += '<div class="position-holder">';
result += '<input type="text" class="input-position" value="' + app.position + '">';
result += '</div>';
result += '<div class="geolocation-holder">';
result += '<input type="text" class="input-latitude" value="' + app.latitude + '" placeholder="latitude">';
result += '<input type="text" class="input-longitude" value="' + app.longitude + '" placeholder="longitude">';
result += '</div>';
result += '<div class="update-app-holder">';
result += '<input type="text" class="input-app-id" placeholder="package name" disabled value="' + app.packageName + '">';
result += '<input type="button" class="button-add-app" value="Update">';
result += '<input type="button" class="button-delete-app" value="X">';
result += '</div>';
result += '</li>';
});
result += '<li>';
result += '<div class="add-app-holder">';
result += '<input type="text" class="input-app-id" placeholder="package name">';
result += '<input type="button" class="button-add-app" value="Add app">';
result += '</div>';
result += '</ul>';
return result;
};
</script>