summaryrefslogtreecommitdiffstats
path: root/core/js
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-03-12 14:07:48 +0100
committerThomas Tanghus <thomas@tanghus.net>2012-03-12 14:13:03 +0100
commit03eb5197b62664ee89060e2d644531c9e7fe8250 (patch)
treea2963dc7388339ba68ff4ebb7abae06d6db53271 /core/js
parenta85a10b378883bfb3f3337d963dc573c2e803e2d (diff)
downloadnextcloud-server-03eb5197b62664ee89060e2d644531c9e7fe8250.tar.gz
nextcloud-server-03eb5197b62664ee89060e2d644531c9e7fe8250.zip
Added category editor for apps using OC_VObjects.
Diffstat (limited to 'core/js')
-rw-r--r--core/js/oc-vcategories.js115
-rw-r--r--core/js/oc-vcategories.txt28
2 files changed, 143 insertions, 0 deletions
diff --git a/core/js/oc-vcategories.js b/core/js/oc-vcategories.js
new file mode 100644
index 00000000000..a6dcccf88e0
--- /dev/null
+++ b/core/js/oc-vcategories.js
@@ -0,0 +1,115 @@
+OCCategories={
+ edit:function(){
+ console.log('OCCategories.edit');
+ if(OCCategories.app == undefined) {
+ OC.dialogs.alert('OCCategories.app is not set!');
+ return;
+ }
+ $('body').append('<div id="category_dialog"></div>');
+ $('#category_dialog').load(OC.filePath('core', 'ajax', 'vcategories/edit.php')+'?app='+OCCategories.app, function(response){
+ try {
+ var jsondata = jQuery.parseJSON(response);
+ if(response.status == 'error'){
+ OC.dialogs.alert(response.data.message, 'Error');
+ return;
+ }
+ } catch(e) {
+ $('#edit_categories_dialog').dialog({
+ modal: true,
+ height: 350, minHeight:200, width: 250, minWidth: 200,
+ buttons: {
+ 'Delete':function() {
+ OCCategories.delete();
+ },
+ 'Rescan':function() {
+ OCCategories.rescan();
+ }
+ },
+ close : function(event, ui) {
+ $(this).dialog('destroy').remove();
+ $('#category_dialog').remove();
+ },
+ open : function(event, ui) {
+ $('#category_addinput').live('input',function(){
+ if($(this).val().length > 0) {
+ $('#category_addbutton').removeAttr('disabled');
+ }
+ });
+ $('#categoryform').submit(function() {
+ OCCategories.add($('#category_addinput').val());
+ $('#category_addinput').val('');
+ $('#category_addbutton').attr('disabled', 'disabled');
+ return false;
+ });
+ $('#category_addbutton').live('click',function(e){
+ e.preventDefault();
+ if($('#category_addinput').val().length > 0) {
+ OCCategories.add($('#category_addinput').val());
+ $('#category_addinput').val('');
+ }
+ });
+ }
+ });
+ }
+ });
+ },
+ delete:function(){
+ var categories = $('#categorylist').find('input[type="checkbox"]').serialize();
+ categories += '&app=' + OCCategories.app;
+ console.log('OCCategories.delete: ' + categories);
+ $.post(OC.filePath(OCCategories.app, 'ajax', 'categories/delete.php'),categories,function(jsondata, status, xhr){
+ if (status == 'error' && xhr.status == 404) {
+ $.post(OC.filePath('core', 'ajax', 'vcategories/delete.php'),categories,function(jsondata, status, xhr){
+ if(jsondata.status == 'success'){
+ OCCategories._update(jsondata.data.categories);
+ } else {
+ OC.dialogs.alert(jsondata.data.message, 'Error');
+ }
+ });
+ return;
+ }
+ if(jsondata.status == 'success'){
+ OCCategories._update(jsondata.data.categories);
+ } else {
+ OC.dialogs.alert(jsondata.data.message, 'Error');
+ }
+ });
+ },
+ add:function(category){
+ console.log('OCCategories.add ' + category);
+ $.getJSON(OC.filePath('core', 'ajax', 'vcategories/add.php'),{'category':category, 'app':OCCategories.app},function(jsondata){
+ if(jsondata.status == 'success'){
+ OCCategories._update(jsondata.data.categories);
+ } else {
+ OC.dialogs.alert(jsondata.data.message, 'Error');
+ }
+ });
+ return false;
+ },
+ rescan:function(){
+ console.log('Categories.rescan');
+ $.getJSON(OC.filePath(OCCategories.app, 'ajax', 'categories/rescan.php'),{},function(jsondata, status, xhr){
+ if (status == 'error' && xhr.status == 404) {
+ OC.dialogs.alert('The required file ' + OC.filePath(Categories.app, 'ajax', 'categories/rescan.php') + ' is not installed!', 'Error');
+ return;
+ }
+ if(jsondata.status == 'success'){
+ OCCategories._update(jsondata.data.categories);
+ } else {
+ OC.dialogs.alert(jsondata.data.message, 'Error');
+ }
+ });
+ },
+ _update:function(categories){
+ var categorylist = $('#categorylist');
+ categorylist.find('li').remove();
+ for(var category in categories) {
+ var item = '<li><input type="checkbox" name="categories" value="' + categories[category] + '" />' + categories[category] + '</li>';
+ $(item).appendTo(categorylist);
+ }
+ if(OCCategories.changed != undefined) {
+ OCCategories.changed(categories);
+ }
+ }
+}
+
diff --git a/core/js/oc-vcategories.txt b/core/js/oc-vcategories.txt
new file mode 100644
index 00000000000..76d4245f5eb
--- /dev/null
+++ b/core/js/oc-vcategories.txt
@@ -0,0 +1,28 @@
+Using OCCategories
+
+This 'class' is meant for any apps that uses OC_VObjects with the CATEGORIES field e.g.
+Contacts and Calendar. It provides an editor UI for adding/deleting and rescanning categories
+and basic ajax functions for adding and deleting.
+To use the mass updating of OC_VObjects that /lib/vcategories.php provides, the app must implement
+its own ajax functions in /apps/$(APP)/ajax/categories/rescan.php and /apps/$(APP)/ajax/categories/delete.php
+See examples in /apps/contacts/ajax/categories and the inline docs in /lib/vcategories.php.
+
+In your app make sure you load the script and stylesheet:
+
+OC_Util::addScript('','oc-vcategories');
+OC_Util::addStyle('','oc-vcategories');
+
+Set the app specific values in your javascript file. This is what I've used for the Contacts app:
+
+ OCCategories.app = 'contacts';
+ OCCategories.changed = Contacts.UI.Card.categoriesChanged;
+
+If OCCategories.changed point is set that function will be called each time the categories have been changed
+in the editor (add/delete/rescan) to allow the app to update the UI accordingly. The only argument to the function
+is an array of the updated categories e.g.:
+
+OCCategories.changed = function(categories) {
+ for(var category in categories) {
+ console.log(categories[category]);
+ }
+} \ No newline at end of file