diff options
author | Julius Haertl <jus@bitgrid.net> | 2016-05-18 22:55:45 +0300 |
---|---|---|
committer | Julius Haertl <jus@bitgrid.net> | 2016-05-18 22:58:44 +0300 |
commit | 197da4d640f9467f1eb5904e8ec9aef14bec6ee9 (patch) | |
tree | 3eeb5a62200d426702b92ce0fc64da71705041d6 /js | |
parent | 8759dd036f166a7ccaed755ba64654ef8bb8ec1d (diff) |
Adding basic app implementation
Diffstat (limited to 'js')
-rw-r--r-- | js/apporder.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/js/apporder.js b/js/apporder.js new file mode 100644 index 0000000..3c6dfc3 --- /dev/null +++ b/js/apporder.js @@ -0,0 +1,59 @@ +$(function() { + + var app_menu = $('#apps ul'); + if(!app_menu.length) + return; + app_menu.hide(); + + // restore existing order + $.get( "/apps/apporder/ajax/order.php", { requesttoken: oc_requesttoken}, function(data) { + var json = data.order; + try { + var order = JSON.parse( json ).reverse(); + } catch (e) { + var order = [] + } + if (order.length==0) + return; + + available_apps = {}; + app_menu.find('li').each(function() { + var id = $(this).find('a').attr('href'); + available_apps[id] = $(this); + }); + $.each(order,function(order,value) { + app_menu.prepend(available_apps[value]); + }) + app_menu.show(); + }); + + // make app menu sortable + $( "#apps ul" ).sortable({ + handle: 'img', + stop: function( event, ui ) { + var items = []; + $("#apps ul").children().each(function(i,el){ + var item = $(el).find('a').attr('href'); + items.push(item) + }) + + var json = JSON.stringify(items); + localStorage.setItem("apporder-order", json); + $.get("/apps/apporder/ajax/personal.php", { order: json, requesttoken: oc_requesttoken}, function(data) {}); + } + }); + + // Sorting inside settings + $( "#appsorter" ).sortable({ + stop: function( event, ui ) { + var items = [] + $("#appsorter").children().each(function(i,el){ + var item = $(el).find('a').attr('href'); + items.push(item) + }) + + var json = JSON.stringify(items); + $.get( "/apps/apporder/ajax/admin.php", { order: json, requesttoken: oc_requesttoken}, function(data) {}); + } + }); +}); |