aboutsummaryrefslogtreecommitdiffstats
path: root/core/js
diff options
context:
space:
mode:
authorJan-Christoph Borchardt <hey@jancborchardt.net>2012-10-28 14:10:10 +0100
committerJan-Christoph Borchardt <hey@jancborchardt.net>2012-10-28 14:10:10 +0100
commitcf2a504d42d35a200cb611b11c8cfa394895fca9 (patch)
tree192816e2cc4c93f2655d8033b4481d9ad0207d3f /core/js
parentfc280b28876bd1b57a8f4a5710da26adb8ebb3b9 (diff)
parent20e0432de8e635b742415cae58e1466daf7da9b5 (diff)
downloadnextcloud-server-cf2a504d42d35a200cb611b11c8cfa394895fca9.tar.gz
nextcloud-server-cf2a504d42d35a200cb611b11c8cfa394895fca9.zip
Merge branch 'master' into navigation
Diffstat (limited to 'core/js')
-rw-r--r--core/js/js.js13
-rw-r--r--core/js/router.js73
2 files changed, 82 insertions, 4 deletions
diff --git a/core/js/js.js b/core/js/js.js
index c5e32f3c278..6ed50b42bd5 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -62,7 +62,7 @@ function escapeHTML(s) {
* @return string
*/
function fileDownloadPath(dir, file) {
- return OC.filePath('files', 'ajax', 'download.php')+'&files='+encodeURIComponent(file)+'&dir='+encodeURIComponent(dir);
+ return OC.filePath('files', 'ajax', 'download.php')+'?files='+encodeURIComponent(file)+'&dir='+encodeURIComponent(dir);
}
var OC={
@@ -95,9 +95,9 @@ var OC={
var isCore=OC.coreApps.indexOf(app)!==-1,
link=OC.webroot;
if((file.substring(file.length-3) === 'php' || file.substring(file.length-3) === 'css') && !isCore){
- link+='/?app=' + app;
+ link+='/index.php/apps/' + app;
if (file != 'index.php') {
- link+='&getfile=';
+ link+='/';
if(type){
link+=encodeURI(type + '/');
}
@@ -113,7 +113,12 @@ var OC={
}
link+=file;
}else{
- link+='/';
+ if ((app == 'settings' || app == 'core') && type == 'ajax') {
+ link+='/index.php/';
+ }
+ else {
+ link+='/';
+ }
if(!isCore){
link+='apps/';
}
diff --git a/core/js/router.js b/core/js/router.js
new file mode 100644
index 00000000000..8b66f5a05c5
--- /dev/null
+++ b/core/js/router.js
@@ -0,0 +1,73 @@
+OC.router_base_url = OC.webroot + '/index.php/',
+OC.Router = {
+ routes_request: $.ajax(OC.router_base_url + 'core/routes.json', {
+ dataType: 'json',
+ success: function(jsondata) {
+ if (jsondata.status == 'success') {
+ OC.Router.routes = jsondata.data;
+ }
+ }
+ }),
+ generate:function(name, opt_params) {
+ if (!('routes' in this)) {
+ if(this.routes_request.state() != 'resolved') {
+ alert('wait');// wait
+ }
+ }
+ if (!(name in this.routes)) {
+ throw new Error('The route "' + name + '" does not exist.');
+ }
+ var route = this.routes[name];
+ var params = opt_params || {};
+ var unusedParams = $.extend(true, {}, params);
+ var url = '';
+ var optional = true;
+ $(route.tokens).each(function(i, token) {
+ if ('text' === token[0]) {
+ url = token[1] + url;
+ optional = false;
+
+ return;
+ }
+
+ if ('variable' === token[0]) {
+ if (false === optional || !(token[3] in route.defaults)
+ || ((token[3] in params) && params[token[3]] != route.defaults[token[3]])) {
+ var value;
+ if (token[3] in params) {
+ value = params[token[3]];
+ delete unusedParams[token[3]];
+ } else if (token[3] in route.defaults) {
+ value = route.defaults[token[3]];
+ } else if (optional) {
+ return;
+ } else {
+ throw new Error('The route "' + name + '" requires the parameter "' + token[3] + '".');
+ }
+
+ var empty = true === value || false === value || '' === value;
+
+ if (!empty || !optional) {
+ url = token[1] + encodeURIComponent(value).replace(/%2F/g, '/') + url;
+ }
+
+ optional = false;
+ }
+
+ return;
+ }
+
+ throw new Error('The token type "' + token[0] + '" is not supported.');
+ });
+ if (url === '') {
+ url = '/';
+ }
+
+ unusedParams = $.param(unusedParams);
+ if (unusedParams.length > 0) {
+ url += '?'+unusedParams;
+ }
+
+ return OC.router_base_url + url;
+ }
+};