Skip to content

Commit 2767533

Browse files
committed
OC 8 Update
1 parent ff892cc commit 2767533

File tree

6 files changed

+61
-43
lines changed

6 files changed

+61
-43
lines changed

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
<description></description>
66
<licence>AGPL</licence>
77
<author>Ben Curtis</author>
8-
<version>0.0.2</version>
8+
<version>0.0.3</version>
99
<requiremin>7.0.3</requiremin>
1010
</info>

appinfo/routes.php

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@
1111

1212
namespace OCA\OwnNote\AppInfo;
1313

14-
\OCP\API::register(
15-
'get',
16-
'/apps/ownnote/ajax/api_getnotes.php',
17-
function($urlParameters) {
18-
return new \OC_OCS_Result($data);
19-
},
20-
'ownnote',
21-
\OC_API::USER_AUTH
22-
);
23-
2414
/**
2515
* Create your routes in here. The name is the lowercase name of the controller
2616
* without the controller part, the stuff after the hash is the method.
@@ -33,14 +23,13 @@ function($urlParameters) {
3323

3424
$application->registerRoutes($this, array('routes' => array(
3525
array('name' => 'page#index', 'url' => '/', 'verb' => 'GET'),
36-
array('name' => 'page#do_echo', 'url' => '/echo', 'verb' => 'POST'),
3726
array('name' => 'ownnote_api#index', 'url' => '/api/v0.2/ownnote', 'verb' => 'GET'),
38-
array('name' => 'ownnote_api#edit', 'url' => '/api/v0.2/ownnote/edit', 'verb' => 'GET'),
39-
array('name' => 'ownnote_api#del', 'url' => '/api/v0.2/ownnote/del', 'verb' => 'GET'),
40-
array('name' => 'ownnote_api#ren', 'url' => '/api/v0.2/ownnote/ren', 'verb' => 'GET'),
41-
array('name' => 'ownnote_api#save', 'url' => '/api/v0.2/ownnote/save', 'verb' => 'GET'),
42-
array('name' => 'ownnote_api#create', 'url' => '/api/v0.2/ownnote/create', 'verb' => 'GET'),
43-
array('name' => 'ownnote_api#delgroup', 'url' => '/api/v0.2/ownnote/delgroup', 'verb' => 'GET'),
44-
array('name' => 'ownnote_api#rengroup', 'url' => '/api/v0.2/ownnote/rengroup', 'verb' => 'GET'),
27+
array('name' => 'ownnote_api#ren', 'url' => '/api/v0.2/ownnote/ren', 'verb' => 'POST'),
28+
array('name' => 'ownnote_api#edit', 'url' => '/api/v0.2/ownnote/edit', 'verb' => 'POST'),
29+
array('name' => 'ownnote_api#del', 'url' => '/api/v0.2/ownnote/del', 'verb' => 'POST'),
30+
array('name' => 'ownnote_api#save', 'url' => '/api/v0.2/ownnote/save', 'verb' => 'POST'),
31+
array('name' => 'ownnote_api#create', 'url' => '/api/v0.2/ownnote/create', 'verb' => 'POST'),
32+
array('name' => 'ownnote_api#delgroup', 'url' => '/api/v0.2/ownnote/delgroup', 'verb' => 'POST'),
33+
array('name' => 'ownnote_api#rengroup', 'url' => '/api/v0.2/ownnote/rengroup', 'verb' => 'POST'),
4534
array('name' => 'ownnote_api#preflighted_cors', 'url' => '/api/v0.2/{path}', 'verb' => 'OPTIONS', 'requirements' => array('path' => '.+')),
4635
)));

controller/ownnoteapicontroller.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public function edit() {
5151
require_once 'ownnote/lib/backend.php';
5252
if (isset($_GET["note"]))
5353
return editNote("Notes", $_GET["note"].".htm");
54+
if (isset($_POST["note"]))
55+
return editNote("Notes", $_POST["note"].".htm");
5456
}
5557

5658
/**
@@ -62,6 +64,8 @@ public function del() {
6264
require_once 'ownnote/lib/backend.php';
6365
if (isset($_GET["note"]))
6466
return deleteNote("Notes", $_GET["note"].".htm");
67+
if (isset($_POST["note"]))
68+
return deleteNote("Notes", $_POST["note"].".htm");
6569
}
6670

6771
/**
@@ -73,6 +77,8 @@ public function ren() {
7377
require_once 'ownnote/lib/backend.php';
7478
if (isset($_GET["note"]) && isset($_GET["newnote"]))
7579
return renameNote("Notes", $_GET["note"], $_GET["newnote"]);
80+
if (isset($_POST["note"]) && isset($_POST["newnote"]))
81+
return renameNote("Notes", $_POST["note"], $_POST["newnote"]);
7682
}
7783

7884
/**
@@ -84,6 +90,8 @@ public function save() {
8490
require_once 'ownnote/lib/backend.php';
8591
if (isset($_GET["note"]) && isset($_GET["content"]))
8692
return saveNote("Notes", $_GET["note"], $_GET["content"]);
93+
if (isset($_POST["note"]) && isset($_POST["content"]))
94+
return saveNote("Notes", $_POST["note"], $_POST["content"]);
8795
}
8896

8997
/**
@@ -95,6 +103,8 @@ public function create() {
95103
require_once 'ownnote/lib/backend.php';
96104
if (isset($_GET["note"]))
97105
return createNote("Notes", $_GET["note"]);
106+
if (isset($_POST["note"]))
107+
return createNote("Notes", $_POST["note"]);
98108
}
99109

100110
/**
@@ -106,6 +116,8 @@ public function delgroup() {
106116
require_once 'ownnote/lib/backend.php';
107117
if (isset($_GET["group"]))
108118
return deleteGroup("Notes", $_GET["group"]);
119+
if (isset($_POST["group"]))
120+
return deleteGroup("Notes", $_POST["group"]);
109121
}
110122

111123
/**
@@ -117,5 +129,7 @@ public function rengroup() {
117129
require_once 'ownnote/lib/backend.php';
118130
if (isset($_GET["group"]) && isset($_GET["newgroup"]))
119131
return renameGroup("Notes", $_GET["group"], $_GET["newgroup"]);
132+
if (isset($_POST["group"]) && isset($_POST["newgroup"]))
133+
return renameGroup("Notes", $_POST["group"], $_POST["newgroup"]);
120134
}
121135
}

controller/pagecontroller.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,12 @@ public function index() {
4141
return new TemplateResponse('ownnote', 'main', $params); // templates/main.php
4242
}
4343

44-
4544
/**
46-
* Simply method that posts back the payload of the request
4745
* @NoAdminRequired
46+
* @NoCSRFRequired
4847
*/
49-
public function doEcho($echo) {
50-
return array('echo' => $echo);
48+
public function listing() {
49+
$params = array('user' => $this->userId);
50+
return new TemplateResponse('ownnote', 'listing', $params); // templates/main.php
5151
}
52-
53-
54-
}
52+
}

js/script.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,23 @@
2424
});
2525
}
2626

27+
function ocUrl(url) {
28+
var newurl = OC.linkTo("ownnote",url).replace("apps/ownnote","index.php/apps/ownnote");
29+
return newurl;
30+
}
31+
32+
function ocVar(val) {
33+
var newval = encodeURIComponent(val);
34+
return newval;
35+
}
36+
2737
function resizeFont(s) {
2838
$('#editable_ifr').contents().find("head").append($("<style type='text/css'> body{font-size:"+s+"px;} </style>"));
2939
}
3040

3141
function deleteNote(id) {
32-
var url = OC.linkTo("ownnote","ajax/delete.php");
33-
url += "?id=" + $(this).attr('id');
34-
$.get(url, function(data) {
42+
var n = ocVar($(this).attr('id'));
43+
$.post(ocUrl("api/v0.2/ownnote/del"), { note: n }, function (data) {
3544
loadListing();
3645
});
3746
}
@@ -43,9 +52,7 @@
4352
if (f[0] == '[') {
4453
g = f.match(/\[(.*?)\]/i)[1];
4554
}
46-
var url = OC.linkTo("ownnote","ajax/edit.php");
47-
url += "?id=" + f;
48-
$.get(url, function(data) {
55+
$.post(ocUrl("api/v0.2/ownnote/edit"), { note: f }, function (data) {
4956
buildEdit(t, g, data);
5057
});
5158
}
@@ -108,17 +115,17 @@
108115
editfilename = '['+editgroup+'] '+editfilename;
109116
if (originalgroup != '')
110117
originalfilename = '['+originalgroup+'] '+originalfilename;
111-
$.post(OC.linkTo("ownnote","ajax/rename.php"), { originalfilename: originalfilename, editfilename: editfilename }, function (data) {
118+
$.post(ocUrl("api/v0.2/ownnote/ren"), { note: originalfilename, newnote: editfilename }, function (data) {
112119
if (data == "SUCCESS") {
113-
$.post(OC.linkTo("ownnote","ajax/save.php"), { content: content, editfilename: editfilename }, function (data) {
120+
$.post(ocUrl("api/v0.2/ownnote/save"), { content: content, note: editfilename }, function (data) {
114121
loadListing();
115122
});
116123
}
117124
});
118125
} else {
119126
if (editgroup != '')
120127
editfilename = '['+editgroup+'] '+editfilename;
121-
$.post(OC.linkTo("ownnote","ajax/save.php"), { content: content, editfilename: editfilename }, function (data) {
128+
$.post(ocUrl("api/v0.2/ownnote/save"), { content: content, note: editfilename }, function (data) {
122129
loadListing();
123130
});
124131
}
@@ -131,7 +138,8 @@
131138
var sortorder = "ascending";
132139

133140
function loadListing() {
134-
$.get(OC.linkTo("ownnote","ajax/listing.php"), function(data) {
141+
var url = ocUrl("api/v0.2/ownnote");
142+
$.get(url, function(data) {
135143
filelist = data;
136144
listing = jQuery.parseJSON(filelist);
137145
buildNav('All');
@@ -220,13 +228,13 @@
220228
if (listing[i].timediff < 30)
221229
fileclass = 'modified latestfile';
222230
html += "<div class='listing'>";
223-
html += " <div id='"+listing[i].file+"' title='"+listing[i].filename+"' class='file pointer'>"+listing[i].filename+"</div>";
231+
html += " <div id='"+listing[i].file.replace('.htm','')+"' title='"+listing[i].filename+"' class='file pointer'>"+listing[i].filename+"</div>";
224232
html += " <div class='info'>";
225233
if (listing[i].timestring != '')
226234
html += " <div class='"+fileclass+"'>"+listing[i].timestring+" ago</div>";
227235
else
228236
html += " <div class='"+fileclass+"'>Just now</div>";
229-
html += " <div id='"+listing[i].file+"' class='buttons delete delete-note pointer'><br></div>";
237+
html += " <div id='"+listing[i].filename+"' class='buttons delete delete-note pointer'><br></div>";
230238
html += " </div>";
231239
html += "</div>";
232240
}
@@ -256,10 +264,9 @@
256264
}
257265

258266
function createNote() {
259-
var url = OC.linkTo("ownnote","ajax/create.php");
260-
url += "?id=" + $('#newfilename').val();
267+
var n = $('#newfilename').val();
261268
cancelNote();
262-
$.get(url, function(data) {
269+
$.post(ocUrl("api/v0.2/ownnote/create"), { note: n }, function (data) {
263270
loadListing();
264271
});
265272
}
@@ -395,7 +402,7 @@
395402

396403
function deleteGroup() {
397404
var g = $(this).attr('group');
398-
$.post(OC.linkTo("ownnote","ajax/deletegroup.php"), { group: g }, function (data) {
405+
$.post(ocUrl("api/v0.2/ownnote/delgroup"), { group: g }, function (data) {
399406
switchgroup = "All";
400407
loadListing();
401408
});
@@ -415,7 +422,7 @@
415422
function saveGroup() {
416423
var v = $("[id='"+this.id+"-text']").val();
417424
if (v != cg && v.toLowerCase() != "all" && v.toLowerCase() != "not grouped") {
418-
$.post(OC.linkTo("ownnote","ajax/renamegroup.php"), { originalgroupname: cg, editgroupname: v }, function (data) {
425+
$.post(ocUrl("api/v0.2/ownnote/rengroup"), { group: cg, newgroup: v }, function (data) {
419426
switchgroup = v;
420427
cg = "";
421428
loadListing();

templates/listing.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
\OCP\User::checkLoggedIn();
4+
\OCP\App::checkAppEnabled('ownnote');
5+
6+
require_once 'ownnote/lib/backend.php';
7+
8+
echo json_encode(getListing("Notes"));
9+
10+
?>

0 commit comments

Comments
 (0)