diff options
author | Thomas Tanghus <thomas@tanghus.net> | 2012-11-13 15:40:46 -0800 |
---|---|---|
committer | Thomas Tanghus <thomas@tanghus.net> | 2012-11-13 15:40:46 -0800 |
commit | c353568ea09ef89e82c7b0f35b8d646b9c35005d (patch) | |
tree | 0d5247b00f465e5d85ead47fd1532cc20bf5a68e /core/js | |
parent | 9c36326e4776350b64b9a657feb5fca8a50cefcc (diff) | |
parent | bfb6faa85077ef8f7e56a7e706f57587460a2125 (diff) | |
download | nextcloud-server-c353568ea09ef89e82c7b0f35b8d646b9c35005d.tar.gz nextcloud-server-c353568ea09ef89e82c7b0f35b8d646b9c35005d.zip |
Merge pull request #41 from owncloud/vcategories_db
OC_VCategories - this time actually usable ;)
Diffstat (limited to 'core/js')
-rw-r--r-- | core/js/oc-vcategories.js | 180 |
1 files changed, 141 insertions, 39 deletions
diff --git a/core/js/oc-vcategories.js b/core/js/oc-vcategories.js index c99dd51f53a..609703f2cc9 100644 --- a/core/js/oc-vcategories.js +++ b/core/js/oc-vcategories.js @@ -1,30 +1,48 @@ -var OCCategories={ - edit:function(){ - if(OCCategories.app == undefined) { - OC.dialogs.alert('OCCategories.app is not set!'); - return; +var OCCategories= { + category_favorites:'_$!<Favorite>!$_', + edit:function(type, cb) { + if(!type && !this.type) { + throw { name: 'MissingParameter', message: t('core', 'The object type is not specified.') }; } + type = type ? type : this.type; $('body').append('<div id="category_dialog"></div>'); - $('#category_dialog').load(OC.filePath('core', 'ajax', 'vcategories/edit.php')+'?app='+OCCategories.app, function(response){ + $('#category_dialog').load( + OC.filePath('core', 'ajax', 'vcategories/edit.php') + '?type=' + type, function(response) { try { var jsondata = jQuery.parseJSON(response); - if(response.status == 'error'){ + if(response.status == 'error') { OC.dialogs.alert(response.data.message, 'Error'); return; } } catch(e) { - $('#edit_categories_dialog').dialog({ + var setEnabled = function(d, enable) { + if(enable) { + d.css('cursor', 'default').find('input,button:not(#category_addbutton)') + .prop('disabled', false).css('cursor', 'default'); + } else { + d.css('cursor', 'wait').find('input,button:not(#category_addbutton)') + .prop('disabled', true).css('cursor', 'wait'); + } + } + var dlg = $('#edit_categories_dialog').dialog({ modal: true, height: 350, minHeight:200, width: 250, minWidth: 200, buttons: { - 'Close': function() { - $(this).dialog("close"); + 'Close': function() { + $(this).dialog('close'); }, 'Delete':function() { - OCCategories.doDelete(); + var categories = $('#categorylist').find('input:checkbox').serialize(); + setEnabled(dlg, false); + OCCategories.doDelete(categories, function() { + setEnabled(dlg, true); + }); }, 'Rescan':function() { - OCCategories.rescan(); + setEnabled(dlg, false); + OCCategories.rescan(function() { + setEnabled(dlg, true); + }); } }, close : function(event, ui) { @@ -32,7 +50,7 @@ var OCCategories={ $('#category_dialog').remove(); }, open : function(event, ui) { - $('#category_addinput').live('input',function(){ + $('#category_addinput').live('input',function() { if($(this).val().length > 0) { $('#category_addbutton').removeAttr('disabled'); } @@ -43,7 +61,7 @@ var OCCategories={ $('#category_addbutton').attr('disabled', 'disabled'); return false; }); - $('#category_addbutton').live('click',function(e){ + $('#category_addbutton').live('click',function(e) { e.preventDefault(); if($('#category_addinput').val().length > 0) { OCCategories.add($('#category_addinput').val()); @@ -55,58 +73,142 @@ var OCCategories={ } }); }, - _processDeleteResult:function(jsondata, status, xhr){ - if(jsondata.status == 'success'){ + _processDeleteResult:function(jsondata) { + if(jsondata.status == 'success') { OCCategories._update(jsondata.data.categories); } else { OC.dialogs.alert(jsondata.data.message, 'Error'); } }, - doDelete:function(){ - var categories = $('#categorylist').find('input:checkbox').serialize(); + favorites:function(type, cb) { + if(!type && !this.type) { + throw { name: 'MissingParameter', message: t('core', 'The object type is not specified.') }; + } + type = type ? type : this.type; + $.getJSON(OC.filePath('core', 'ajax', 'categories/favorites.php'), {type: type},function(jsondata) { + if(typeof cb == 'function') { + cb(jsondata); + } else { + if(jsondata.status === 'success') { + OCCategories._update(jsondata.data.categories); + } else { + OC.dialogs.alert(jsondata.data.message, t('core', 'Error')); + } + } + }); + }, + addToFavorites:function(id, type, cb) { + if(!type && !this.type) { + throw { name: 'MissingParameter', message: t('core', 'The object type is not specified.') }; + } + type = type ? type : this.type; + $.post(OC.filePath('core', 'ajax', 'vcategories/addToFavorites.php'), {id:id, type:type}, function(jsondata) { + if(typeof cb == 'function') { + cb(jsondata); + } else { + if(jsondata.status !== 'success') { + OC.dialogs.alert(jsondata.data.message, 'Error'); + } + } + }); + }, + removeFromFavorites:function(id, type, cb) { + if(!type && !this.type) { + throw { name: 'MissingParameter', message: t('core', 'The object type is not specified.') }; + } + type = type ? type : this.type; + $.post(OC.filePath('core', 'ajax', 'vcategories/removeFromFavorites.php'), {id:id, type:type}, function(jsondata) { + if(typeof cb == 'function') { + cb(jsondata); + } else { + if(jsondata.status !== 'success') { + OC.dialogs.alert(jsondata.data.message, t('core', 'Error')); + } + } + }); + }, + doDelete:function(categories, type, cb) { + if(!type && !this.type) { + throw { name: 'MissingParameter', message: t('core', 'The object type is not specified.') }; + } + type = type ? type : this.type; if(categories == '' || categories == undefined) { OC.dialogs.alert(t('core', 'No categories selected for deletion.'), t('core', 'Error')); return false; } - categories += '&app=' + OCCategories.app; - $.post(OC.filePath(OCCategories.app, 'ajax', 'categories/delete.php'), categories, OCCategories._processDeleteResult) - .error(function(xhr){ - if (xhr.status == 404) { - $.post(OC.filePath('core', 'ajax', 'vcategories/delete.php'), categories, OCCategories._processDeleteResult); - } - }); + var self = this; + var q = categories + '&type=' + type; + if(this.app) { + q += '&app=' + this.app; + $.post(OC.filePath(this.app, 'ajax', 'categories/delete.php'), q, function(jsondata) { + if(typeof cb == 'function') { + cb(jsondata); + } else { + self._processDeleteResult(jsondata); + } + }); + } else { + $.post(OC.filePath('core', 'ajax', 'vcategories/delete.php'), q, function(jsondata) { + if(typeof cb == 'function') { + cb(jsondata); + } else { + self._processDeleteResult(jsondata); + } + }); + } }, - add:function(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); + add:function(category, type, cb) { + if(!type && !this.type) { + throw { name: 'MissingParameter', message: t('core', 'The object type is not specified.') }; + } + type = type ? type : this.type; + $.post(OC.filePath('core', 'ajax', 'vcategories/add.php'),{'category':category, 'type':type},function(jsondata) { + if(typeof cb == 'function') { + cb(jsondata); } else { - OC.dialogs.alert(jsondata.data.message, 'Error'); + if(jsondata.status === 'success') { + OCCategories._update(jsondata.data.categories); + } else { + OC.dialogs.alert(jsondata.data.message, 'Error'); + } } }); - return false; }, - rescan:function(){ - $.getJSON(OC.filePath(OCCategories.app, 'ajax', 'categories/rescan.php'),function(jsondata, status, xhr){ - if(jsondata.status == 'success'){ - OCCategories._update(jsondata.data.categories); + rescan:function(app, cb) { + if(!app && !this.app) { + throw { name: 'MissingParameter', message: t('core', 'The app name is not specified.') }; + } + app = app ? app : this.app; + $.getJSON(OC.filePath(app, 'ajax', 'categories/rescan.php'),function(jsondata, status, xhr) { + if(typeof cb == 'function') { + cb(jsondata); } else { - OC.dialogs.alert(jsondata.data.message, 'Error'); + if(jsondata.status === 'success') { + OCCategories._update(jsondata.data.categories); + } else { + OC.dialogs.alert(jsondata.data.message, 'Error'); + } } }).error(function(xhr){ if (xhr.status == 404) { - OC.dialogs.alert('The required file ' + OC.filePath(OCCategories.app, 'ajax', 'categories/rescan.php') + ' is not installed!', 'Error'); + var errormessage = t('core', 'The required file {file} is not installed!', + {file: OC.filePath(app, 'ajax', 'categories/rescan.php')}, t('core', 'Error')); + if(typeof cb == 'function') { + cb({status:'error', data:{message:errormessage}}); + } else { + OC.dialogs.alert(errormessage); + } } }); }, - _update:function(categories){ + _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) { + if(typeof OCCategories.changed === 'function') { OCCategories.changed(categories); } } |