Skip to content

Commit

Permalink
OC 8 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Fmstrat committed Feb 16, 2015
1 parent ff892cc commit 2767533
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 43 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<description></description>
<licence>AGPL</licence>
<author>Ben Curtis</author>
<version>0.0.2</version>
<version>0.0.3</version>
<requiremin>7.0.3</requiremin>
</info>
25 changes: 7 additions & 18 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@

namespace OCA\OwnNote\AppInfo;

\OCP\API::register(
'get',
'/apps/ownnote/ajax/api_getnotes.php',
function($urlParameters) {
return new \OC_OCS_Result($data);
},
'ownnote',
\OC_API::USER_AUTH
);

/**
* Create your routes in here. The name is the lowercase name of the controller
* without the controller part, the stuff after the hash is the method.
Expand All @@ -33,14 +23,13 @@ function($urlParameters) {

$application->registerRoutes($this, array('routes' => array(
array('name' => 'page#index', 'url' => '/', 'verb' => 'GET'),
array('name' => 'page#do_echo', 'url' => '/echo', 'verb' => 'POST'),
array('name' => 'ownnote_api#index', 'url' => '/api/v0.2/ownnote', 'verb' => 'GET'),
array('name' => 'ownnote_api#edit', 'url' => '/api/v0.2/ownnote/edit', 'verb' => 'GET'),
array('name' => 'ownnote_api#del', 'url' => '/api/v0.2/ownnote/del', 'verb' => 'GET'),
array('name' => 'ownnote_api#ren', 'url' => '/api/v0.2/ownnote/ren', 'verb' => 'GET'),
array('name' => 'ownnote_api#save', 'url' => '/api/v0.2/ownnote/save', 'verb' => 'GET'),
array('name' => 'ownnote_api#create', 'url' => '/api/v0.2/ownnote/create', 'verb' => 'GET'),
array('name' => 'ownnote_api#delgroup', 'url' => '/api/v0.2/ownnote/delgroup', 'verb' => 'GET'),
array('name' => 'ownnote_api#rengroup', 'url' => '/api/v0.2/ownnote/rengroup', 'verb' => 'GET'),
array('name' => 'ownnote_api#ren', 'url' => '/api/v0.2/ownnote/ren', 'verb' => 'POST'),
array('name' => 'ownnote_api#edit', 'url' => '/api/v0.2/ownnote/edit', 'verb' => 'POST'),
array('name' => 'ownnote_api#del', 'url' => '/api/v0.2/ownnote/del', 'verb' => 'POST'),
array('name' => 'ownnote_api#save', 'url' => '/api/v0.2/ownnote/save', 'verb' => 'POST'),
array('name' => 'ownnote_api#create', 'url' => '/api/v0.2/ownnote/create', 'verb' => 'POST'),
array('name' => 'ownnote_api#delgroup', 'url' => '/api/v0.2/ownnote/delgroup', 'verb' => 'POST'),
array('name' => 'ownnote_api#rengroup', 'url' => '/api/v0.2/ownnote/rengroup', 'verb' => 'POST'),
array('name' => 'ownnote_api#preflighted_cors', 'url' => '/api/v0.2/{path}', 'verb' => 'OPTIONS', 'requirements' => array('path' => '.+')),
)));
14 changes: 14 additions & 0 deletions controller/ownnoteapicontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public function edit() {
require_once 'ownnote/lib/backend.php';
if (isset($_GET["note"]))
return editNote("Notes", $_GET["note"].".htm");
if (isset($_POST["note"]))
return editNote("Notes", $_POST["note"].".htm");
}

/**
Expand All @@ -62,6 +64,8 @@ public function del() {
require_once 'ownnote/lib/backend.php';
if (isset($_GET["note"]))
return deleteNote("Notes", $_GET["note"].".htm");
if (isset($_POST["note"]))
return deleteNote("Notes", $_POST["note"].".htm");
}

/**
Expand All @@ -73,6 +77,8 @@ public function ren() {
require_once 'ownnote/lib/backend.php';
if (isset($_GET["note"]) && isset($_GET["newnote"]))
return renameNote("Notes", $_GET["note"], $_GET["newnote"]);
if (isset($_POST["note"]) && isset($_POST["newnote"]))
return renameNote("Notes", $_POST["note"], $_POST["newnote"]);
}

/**
Expand All @@ -84,6 +90,8 @@ public function save() {
require_once 'ownnote/lib/backend.php';
if (isset($_GET["note"]) && isset($_GET["content"]))
return saveNote("Notes", $_GET["note"], $_GET["content"]);
if (isset($_POST["note"]) && isset($_POST["content"]))
return saveNote("Notes", $_POST["note"], $_POST["content"]);
}

/**
Expand All @@ -95,6 +103,8 @@ public function create() {
require_once 'ownnote/lib/backend.php';
if (isset($_GET["note"]))
return createNote("Notes", $_GET["note"]);
if (isset($_POST["note"]))
return createNote("Notes", $_POST["note"]);
}

/**
Expand All @@ -106,6 +116,8 @@ public function delgroup() {
require_once 'ownnote/lib/backend.php';
if (isset($_GET["group"]))
return deleteGroup("Notes", $_GET["group"]);
if (isset($_POST["group"]))
return deleteGroup("Notes", $_POST["group"]);
}

/**
Expand All @@ -117,5 +129,7 @@ public function rengroup() {
require_once 'ownnote/lib/backend.php';
if (isset($_GET["group"]) && isset($_GET["newgroup"]))
return renameGroup("Notes", $_GET["group"], $_GET["newgroup"]);
if (isset($_POST["group"]) && isset($_POST["newgroup"]))
return renameGroup("Notes", $_POST["group"], $_POST["newgroup"]);
}
}
12 changes: 5 additions & 7 deletions controller/pagecontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ public function index() {
return new TemplateResponse('ownnote', 'main', $params); // templates/main.php
}


/**
* Simply method that posts back the payload of the request
* @NoAdminRequired
* @NoCSRFRequired
*/
public function doEcho($echo) {
return array('echo' => $echo);
public function listing() {
$params = array('user' => $this->userId);
return new TemplateResponse('ownnote', 'listing', $params); // templates/main.php
}


}
}
41 changes: 24 additions & 17 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,23 @@
});
}

function ocUrl(url) {
var newurl = OC.linkTo("ownnote",url).replace("apps/ownnote","index.php/apps/ownnote");
return newurl;
}

function ocVar(val) {
var newval = encodeURIComponent(val);
return newval;
}

function resizeFont(s) {
$('#editable_ifr').contents().find("head").append($("<style type='text/css'> body{font-size:"+s+"px;} </style>"));
}

function deleteNote(id) {
var url = OC.linkTo("ownnote","ajax/delete.php");
url += "?id=" + $(this).attr('id');
$.get(url, function(data) {
var n = ocVar($(this).attr('id'));
$.post(ocUrl("api/v0.2/ownnote/del"), { note: n }, function (data) {
loadListing();
});
}
Expand All @@ -43,9 +52,7 @@
if (f[0] == '[') {
g = f.match(/\[(.*?)\]/i)[1];
}
var url = OC.linkTo("ownnote","ajax/edit.php");
url += "?id=" + f;
$.get(url, function(data) {
$.post(ocUrl("api/v0.2/ownnote/edit"), { note: f }, function (data) {
buildEdit(t, g, data);
});
}
Expand Down Expand Up @@ -108,17 +115,17 @@
editfilename = '['+editgroup+'] '+editfilename;
if (originalgroup != '')
originalfilename = '['+originalgroup+'] '+originalfilename;
$.post(OC.linkTo("ownnote","ajax/rename.php"), { originalfilename: originalfilename, editfilename: editfilename }, function (data) {
$.post(ocUrl("api/v0.2/ownnote/ren"), { note: originalfilename, newnote: editfilename }, function (data) {
if (data == "SUCCESS") {
$.post(OC.linkTo("ownnote","ajax/save.php"), { content: content, editfilename: editfilename }, function (data) {
$.post(ocUrl("api/v0.2/ownnote/save"), { content: content, note: editfilename }, function (data) {
loadListing();
});
}
});
} else {
if (editgroup != '')
editfilename = '['+editgroup+'] '+editfilename;
$.post(OC.linkTo("ownnote","ajax/save.php"), { content: content, editfilename: editfilename }, function (data) {
$.post(ocUrl("api/v0.2/ownnote/save"), { content: content, note: editfilename }, function (data) {
loadListing();
});
}
Expand All @@ -131,7 +138,8 @@
var sortorder = "ascending";

function loadListing() {
$.get(OC.linkTo("ownnote","ajax/listing.php"), function(data) {
var url = ocUrl("api/v0.2/ownnote");
$.get(url, function(data) {
filelist = data;
listing = jQuery.parseJSON(filelist);
buildNav('All');
Expand Down Expand Up @@ -220,13 +228,13 @@
if (listing[i].timediff < 30)
fileclass = 'modified latestfile';
html += "<div class='listing'>";
html += " <div id='"+listing[i].file+"' title='"+listing[i].filename+"' class='file pointer'>"+listing[i].filename+"</div>";
html += " <div id='"+listing[i].file.replace('.htm','')+"' title='"+listing[i].filename+"' class='file pointer'>"+listing[i].filename+"</div>";
html += " <div class='info'>";
if (listing[i].timestring != '')
html += " <div class='"+fileclass+"'>"+listing[i].timestring+" ago</div>";
else
html += " <div class='"+fileclass+"'>Just now</div>";
html += " <div id='"+listing[i].file+"' class='buttons delete delete-note pointer'><br></div>";
html += " <div id='"+listing[i].filename+"' class='buttons delete delete-note pointer'><br></div>";
html += " </div>";
html += "</div>";
}
Expand Down Expand Up @@ -256,10 +264,9 @@
}

function createNote() {
var url = OC.linkTo("ownnote","ajax/create.php");
url += "?id=" + $('#newfilename').val();
var n = $('#newfilename').val();
cancelNote();
$.get(url, function(data) {
$.post(ocUrl("api/v0.2/ownnote/create"), { note: n }, function (data) {
loadListing();
});
}
Expand Down Expand Up @@ -395,7 +402,7 @@

function deleteGroup() {
var g = $(this).attr('group');
$.post(OC.linkTo("ownnote","ajax/deletegroup.php"), { group: g }, function (data) {
$.post(ocUrl("api/v0.2/ownnote/delgroup"), { group: g }, function (data) {
switchgroup = "All";
loadListing();
});
Expand All @@ -415,7 +422,7 @@
function saveGroup() {
var v = $("[id='"+this.id+"-text']").val();
if (v != cg && v.toLowerCase() != "all" && v.toLowerCase() != "not grouped") {
$.post(OC.linkTo("ownnote","ajax/renamegroup.php"), { originalgroupname: cg, editgroupname: v }, function (data) {
$.post(ocUrl("api/v0.2/ownnote/rengroup"), { group: cg, newgroup: v }, function (data) {
switchgroup = v;
cg = "";
loadListing();
Expand Down
10 changes: 10 additions & 0 deletions templates/listing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

\OCP\User::checkLoggedIn();
\OCP\App::checkAppEnabled('ownnote');

require_once 'ownnote/lib/backend.php';

echo json_encode(getListing("Notes"));

?>

0 comments on commit 2767533

Please sign in to comment.