-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.php
More file actions
415 lines (388 loc) · 19.9 KB
/
Copy pathadd.php
File metadata and controls
415 lines (388 loc) · 19.9 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
<?php
/*
* Property of Writale
* All rights reserved
* Writale © 2013
*/
require realpath(dirname(__FILE__).'/class/init.php');
require realpath(dirname(__FILE__) . "/control/session/saved.php");
require realpath(dirname(__FILE__) . "/control/general/cache.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Add Genre</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Writale is a simple, powerful way to read and build social stories." />
<link rel="shortcut icon" type="image/x-icon" href="//<?php echo $_SERVER['HTTP_HOST'] ?>/resource/image/icon/favicon.ico" />
<link rel="stylesheet" type="text/css" href="//<?php echo $_SERVER['HTTP_HOST'] . '/style/universal.css'; ?>" />
<link rel="stylesheet" type="text/css" href="//<?php echo $_SERVER['HTTP_HOST'] . '/style/ad-0107-18032014.css'; ?>" />
<script src="//<?php echo $_SERVER['HTTP_HOST'] ?>/script/common.js"></script>
</head>
<body class="add-genre">
<?php
include realpath(dirname(__FILE__) . '/control/decorator/userpanel.php');
?>
<div id="progress-bar">
</div>
<div id="ag-container">
<div id="add-genre-title">
Genres help people find stories based on their interest.
<div id="title-desc">
Provide all informations below to add a new genre to writale.
</div>
</div>
<div id="add-gnr-lower">
<div class="frm-elem" id="genre-name">
<div class="inline-middle label">
Genre Title :
</div>
<div class="inline-middle inpt">
<input type="text" id="gname" title="Name of genre which will be displayed publicly." />
</div>
<div class="inline" id="check-name">
</div>
</div>
<div class="frm-elem" id="genre-desc">
<div class="inline-top label">
Description :
</div>
<div class="inline-top inpt">
<textarea id="desc" title="Write a short description of your genre in not more than 200 chars. Mention, explicitly, what kind of stories this genre will consist of."></textarea>
</div>
</div>
<div class="frm-elem" id="genre-url">
<div class="inline label">
Genre URL :
</div>
<div class="inline url">
https://www.writale.com/ <input type="text" id="vanity"
title="Choose a unique URL for this genre. Allowed characters are [.] [a-z] [A-Z] [0-9]. Must start with an alphabet and end with alphanumeric character. No 2 consecutive periods (.) are allowed. "/>
</div>
<div class="inline" id="check-vanity">
</div>
</div>
<div class="button-std button-colorless" id="genre-dp">
Choose a picture
</div>
</div>
<div id="add-container">
<div id="add-error" class="tiny-error"></div>
<div id="add-info" class="yellow-info bold"></div>
<div id="genre-submit" class="button-std button-blue">
Add
</div>
</div>
</div>
<div class="writale-sec-dialog" id="similar-genre-dialog">
</div>
<?php require realpath(dirname(__FILE__) . '/control/decorator/pagefooter.php'); ?>
<?php
include realpath(dirname(__FILE__) . '/control/decorator/utilbottom.php');
include realpath(dirname(__FILE__) . '/control/decorator/savedutil.php');
?>
<iframe src="<?php echo $_protocol . $_SERVER['HTTP_HOST'] . '/control/general/uploadform'; ?>" id="hid-upload-frame">
</iframe>
<script>
(function () {
var add = (function () {
var
tbName = _gAny('gname'),
tbDesc = _gAny('desc'),
tbVanity = _gAny('vanity'),
nAdd = _gAny('genre-submit'),
nPic = _gAny('genre-dp'),
nError = _gAny('add-error'),
nCheck = _gAny('check-vanity'),
nInfo = _gAny('add-info'),
iFrame = _gAny('hid-upload-frame'),
pBar = _gAny('progress-bar'),
nCheckName = _gAny('check-name'),
cover = _gAny('cover'),
simGenreDialog = _gAny('similar-genre-dialog'),
nNtButt = _gAny('nt-butt'),
bVanity,
bName,
oRequest = {
name : null,
desc : null,
vanity : null,
picture : 0
};
function init () {
addEvent.call(nAdd,'click',processGenre,false);
addEvent.call(tbVanity,'blur',processVanity,false);
addEvent.call(tbName,'blur',processName,false);
tbName.value = '';
tbVanity.value = '';
tbDesc.value = '';
addEvent.call(window.self,'load',function () {
common.picture.init({
clickSource : nPic,
error : nError,
cb : uploadHandler,
progressBar : pBar,
scale : {
width : 150,
height : 150
},
dp : true
});
},false);
}
function uploadHandler (res) {
var
nTemp,
dpContain = _gAny('dp-container');
if(!dpContain) {
nTemp = $.createElement('div');
nTemp.id = 'dp-container';
nTemp.innerHTML = res;
_gAny('add-gnr-lower').appendChild (nTemp);
fade(nTemp,1,15);
}
else {
dpContain.innerHTML = res;
fade(dpContain,1,15);
}
common.picture.resetInput ();
oRequest.picture = 1;
}
function processVanity () {
bVanity = undefined;
var
val = this.value.trim();
wxhr.sendGenericRequest('?gvan='+encodeURIComponent(val),afterProcessing);
}
function processName () {
bName = undefined;
var val = this.value.trim();
if(val.length !== 0) {
wxhr.sendGenericRequest('?gname='+encodeURIComponent(val),afterProcessingName);
}
}
function afterProcessingName (res) {
if(res == -1) {
tbName.style.borderColor = '#ca6778';
nCheckName.style.color = '#a05677';
nCheckName.innerHTML ='✗';
util.genError(nError,"Sorry! This genre is already present.");
bName = 0;
}
else {
bName = 1;
nCheckName.style.color = '#56A077';
nCheckName.innerHTML ='✓';
tbName.style.borderColor = '#dadada';
}
}
function afterProcessing(response) {
var
res = JSON.parse(response);
if(res.success) {
nCheck.style.color = '#56A077';
nCheck.innerHTML ='✓';
tbVanity.style.borderColor = '#dadada';
bVanity = 1;
}
else {
tbVanity.style.borderColor = '#ca6778';
nCheck.style.color = '#a05677';
nCheck.innerHTML ='✗';
bVanity = -1;
if(res.code === 1) {
util.genError(nError,"Sorry! This URL is already taken. Please choose another.");
bVanity = 0;
}
}
}
function processGenre () {
var
sName = tbName.value.trim (),
sDesc = tbDesc.value.trim (),
sVanity = tbVanity.value.trim (),
iNLen = sName.length,
iDLen = sDesc.length,
iVLen = sVanity.length,
vanityRE = /[^\.a-zA-Z0-9]/,
vanityEndRE =/^[a-zA-Z][a-zA-Z0-9\.]*[a-zA-Z0-9]$/,
RErepeat = /[\.]{2,}/;
if(iNLen === 0 || iDLen === 0 || iVLen === 0) {
util.genError(nError,"You are missing some items. Please re-check.");
if (iNLen === 0 || !bName)
tbName.style.borderColor = '#ca6778';
else
tbName.style.borderColor = '#dadada';
if (iDLen === 0)
tbDesc.style.borderColor = '#ca6778';
else
tbDesc.style.borderColor = '#dadada';
if (iVLen === 0 || !bVanity)
tbVanity.style.borderColor = '#ca6778';
else
tbVanity.style.borderColor = '#dadada';
}
else {
if(bVanity===1)
tbVanity.style.borderColor = '#dadada';
tbDesc.style.borderColor = '#dadada';
if(bName===1) {
tbName.style.borderColor = '#dadada';
nCheckName.style.color = '#56A077';
nCheckName.innerHTML ='✓';
}
if (!util.validateInput(sName,1)) {
tbName.style.borderColor = '#ca6778';
nCheckName.style.color = '#a05677';
nCheckName.innerHTML ='✗';
util.genError(nError,"Sorry! Genre name doesn't seem genuine.");
}
else if(iNLen < 3) {
tbName.style.borderColor = '#ca6778';
nCheckName.style.color = '#a05677';
nCheckName.innerHTML ='✗';
util.genError(nError,"Genre name is too short.");
}
else if (!util.validateInput(sDesc,2)) {
tbDesc.style.borderColor = '#ca6778';
util.genError(nError,"Sorry! Description doesn't seem genuine.");
}
else if (iDLen > 200) {
tbDesc.style.borderColor = '#ca6778';
util.genError(nError,"Sorry! Description can't have more than 200 chars.");
}
else if(iVLen < 3) {
tbVanity.style.borderColor = '#ca6778';
util.genError(nError,"URL should be at least 3 chars long.");
}
else if (sVanity.match(vanityRE)) {
tbVanity.style.borderColor = '#ca6778';
util.genError(nError,"URL can contain only these chars : [.] [a-z] [A-Z] [0-9]");
}
else if(sVanity.match(RErepeat)) {
tbVanity.style.borderColor = '#ca6778';
util.genError(nError,"URL can't have more than one period (.) consecutively.");
}
else if(!sVanity.match(vanityEndRE)) {
tbVanity.style.borderColor = '#ca6778';
util.genError(nError,"URL must start with an alphabet and end with an<br /> alphanumeric character.");
}
else if (!oRequest.picture) {
util.genError(nError,"Please choose a picture that represents your genre.");
}
else if(typeof bVanity === 'undefined') {
util.genError(nInfo,"Please wait till we check URL availability.");
}
else if(typeof bName === 'undefined') {
fade(nError,0);
util.genError(nInfo,"Please wait till we check name availability.");
}
else if(bVanity === 0) {
util.genError(nError,"The requested URL is not available. Please choose another.");
}
else if(bVanity === -1) {
util.genError(nError, "There's something wrong with the URL. <br />Please see tooltip for help.");
}
else if(bName === 0) {
util.genError(nError, "Sorry! This genre is already added.");
}
else {
oRequest.name = sName;
oRequest.desc = sDesc;
oRequest.vanity = sVanity;
removeEvent.call(this,'click',processGenre,false);
wxhr.sendGenericRequest('?sgchk=1&sgchkgname='+encodeURIComponent(sName),afterCheckingSimilarGenre,'/process/creategenre');
util.dotLoader(this,1,'50px');
}
}
}
function afterCheckingSimilarGenre (res) {
nAdd.innerHTML = 'Add';
if(res != -1) {
if(res != 1) {
util.dotLoader(nAdd,0,'50px');
showSimilarGenreDialog (res);
}
else {
wxhr.createGenre(oRequest,afterCreating);
}
}
else {
util.dotLoader(nAdd,0,'50px');
addEvent.call(nAdd,'click',processGenre,false);
util.genError(nError, "Whoops! Something's wrong. Please try later.");
}
}
function showSimilarGenreDialog (res) {
cover.style.display = 'block';
fade(simGenreDialog,1,15);
simGenreDialog.innerHTML = res;
addEvent.call(_gAny('dkt-butt'),'click',cancelAdding,false);
addEvent.call($,'keyup',cancelOnKeyPress,false);
addEvent.call(_gAny('nt-butt'),'click',continueAdding,false);
}
function cancelOnKeyPress (e) {
var code = e.which || e.keyCode;
if(code === 27)
cancelAdding();
}
function continueAdding () {
removeEvent.call(_gAny('dkt-butt'),'click',cancelAdding,false);
removeEvent.call($,'keypress',cancelOnKeyPress,false);
util.dotLoader(this,1,'140px');
removeEvent.call(this,'click',continueAdding,false);
wxhr.createGenre(oRequest,function (res) {
afterCreating(res,true);
});
}
function cancelAdding () {
fade(simGenreDialog,0,15);
cover.style.display = 'none';
clearAll();
addEvent.call(nAdd,'click',processGenre,false);
}
function afterCreating (response) {
var notice = _gAny('notice-white'),
res = JSON.parse(response);
if(res.success) {
clearAll();
fade(notice,1);
util.firstChild(notice).innerHTML = "Your genre was added successfully!";
location.href = location.protocol+'//'+location.hostname+'/'+res.vanity;
}
else {
if(arguments[1]) {
util.dotLoader(nNtButt,0);
nNtButt.innerHTML = 'No thanks! My genre is different.';
fade(simGenreDialog,0,15);
cover.style.display = 'none';
}
else {
util.dotLoader(nAdd,0,'50px');
nAdd.innerHTML = 'Add';
}
addEvent.call(nAdd,'click',processGenre,false);
util.genError(nError,"Whooops! Something's wrong. Please try later.");
}
}
function clearAll () {
tbName.value = '';
tbVanity.value = '';
tbDesc.value = '';
nCheck.innerHTML = '';
nCheckName.innerHTML = '';
var
dp = _gAny('dp-container');
if(dp)
dp.parentNode.removeChild(dp);
}
return {
init : init
};
})();
add.init();
})();
</script>
</body>
</html>