ownpad_lite.php
2.58 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
<?php
/**
* Copyright (c) 2013 Thomas Müller
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
// Set the content type to Javascript
header("Content-type: text/javascript");
// Disallow caching
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
?>
var ownPad = {
username : '<?php echo OCA\ownpad_lite\App::getUsername() ?>',
host : '<?php echo OCA\ownpad_lite\App::getServiceUrl() ?>',
showPad : function() {
$('#ownpad-content').pad({
'showControls' : true,
'showChat' : true,
'showLineNumbers' : true,
'border' : '1px',
'padId' : ownPad.getTitle(),
'userName' : ownPad.getUsername(),
'host' : ownPad.getHost(),
'baseUrl' : ''
});
},
getTitle : function() {
return $('#ownpad-title').val();
},
getUsername : function() {
return ownPad.username;
},
setUsername : function(username) {
ownPad.username = username;
},
getHost : function() {
return ownPad.host;
},
setHost : function(host) {
ownPad.host = host;
},
onSearch : function(request, response){
if (request && request.term){
$.post(
OC.filePath('ownpad_lite', 'ajax', 'search.php'),
{<?php echo OCA\ownpad_lite\UrlParam::SHARE_SEARCH ?>:request.term},
function(data){
if (data.status == 'success' && data.data){
response( data.data );
}
}
);
}
},
onShare : function(){
var source = ownPad.getHost() + ownPad.getTitle();
var shareWith = $('#ownpad-share').val();
if (shareWith.length<3) {
return;
}
$.post(
OC.filePath('ownpad_lite', 'ajax', 'share.php'),
{
<?php echo OCA\ownpad_lite\UrlParam::SHARE_WHAT ?> : source,
<?php echo OCA\ownpad_lite\UrlParam::SHARE_WITH ?> : shareWith
},
ownPad.onShareComplete
);
},
onShareComplete : function(data){
var successMessage = t('<?php echo OCA\ownpad_lite\App::APP_ID ?>', 'Shared successfully');
var errorMessage = t('<?php echo OCA\ownpad_lite\App::APP_ID ?>', 'Failed to send notification');
var message = data && data.status && data.status=='success' ? successMessage : errorMessage ;
OC.Notification.show(message);
setTimeout(OC.Notification.hide, 6000);
}
};
$('#ownpad-open').click(ownPad.showPad);
$('#ownpad-share').autocomplete({ minLength: 3, source: ownPad.onSearch});
$('#ownpad-share-button').click(ownPad.onShare);
$('#settingsbtn').on('click keydown', function() {
try {
OC.appSettings({appid:'ownpad_lite', loadJS:true, cache:false});
} catch(e) {
console.log(e);
}
});