From 97c884c54804832a24e153273c5c619b76d3ebe9 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Fri, 19 Oct 2012 00:09:07 +0200 Subject: Updated category js for handling favorites and use post instead of get. --- core/js/oc-vcategories.js | 61 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 18 deletions(-) (limited to 'core/js') diff --git a/core/js/oc-vcategories.js b/core/js/oc-vcategories.js index c99dd51f53a..f3935911b8c 100644 --- a/core/js/oc-vcategories.js +++ b/core/js/oc-vcategories.js @@ -1,14 +1,15 @@ -var OCCategories={ - edit:function(){ +var OCCategories= { + edit:function() { if(OCCategories.app == undefined) { OC.dialogs.alert('OCCategories.app is not set!'); return; } $('body').append('
'); - $('#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') + '?app=' + OCCategories.app, function(response) { try { var jsondata = jQuery.parseJSON(response); - if(response.status == 'error'){ + if(response.status == 'error') { OC.dialogs.alert(response.data.message, 'Error'); return; } @@ -32,7 +33,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 +44,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,14 +56,37 @@ var OCCategories={ } }); }, - _processDeleteResult:function(jsondata, status, xhr){ - if(jsondata.status == 'success'){ + _processDeleteResult:function(jsondata, status, xhr) { + if(jsondata.status == 'success') { OCCategories._update(jsondata.data.categories); } else { OC.dialogs.alert(jsondata.data.message, 'Error'); } }, - doDelete:function(){ + favorites:function(type, cb) { + $.getJSON(OC.filePath(OCCategories.app, 'ajax', 'categories/favorites.php'),function(jsondata) { + if(jsondata.status === 'success') { + OCCategories._update(jsondata.data.categories); + } else { + OC.dialogs.alert(jsondata.data.message, t('core', 'Error')); + } + }); + }, + addToFavorites:function(id, type) { + $.post(OC.filePath('core', 'ajax', 'vcategories/addToFavorites.php'), {id:id, type:type}, function(jsondata) { + if(jsondata.status !== 'success') { + OC.dialogs.alert(jsondata.data.message, 'Error'); + } + }); + }, + removeFromFavorites:function(id, type) { + $.post(OC.filePath('core', 'ajax', 'vcategories/removeFromFavorites.php'), {id:id, type:type}, function(jsondata) { + if(jsondata.status !== 'success') { + OC.dialogs.alert(jsondata.data.message, t('core', 'Error')); + } + }); + }, + doDelete:function() { var categories = $('#categorylist').find('input:checkbox').serialize(); if(categories == '' || categories == undefined) { OC.dialogs.alert(t('core', 'No categories selected for deletion.'), t('core', 'Error')); @@ -76,30 +100,31 @@ var OCCategories={ } }); }, - add:function(category){ - $.getJSON(OC.filePath('core', 'ajax', 'vcategories/add.php'),{'category':category, 'app':OCCategories.app},function(jsondata){ - if(jsondata.status == 'success'){ + add:function(category) { + $.post(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(){ - $.getJSON(OC.filePath(OCCategories.app, 'ajax', 'categories/rescan.php'),function(jsondata, status, xhr){ - if(jsondata.status == 'success'){ + rescan:function() { + $.getJSON(OC.filePath(OCCategories.app, 'ajax', 'categories/rescan.php'),function(jsondata, status, xhr) { + 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'); + OC.dialogs.alert( + t('core', 'The required file {file} is not installed!', + {file: OC.filePath(OCCategories.app, 'ajax', 'categories/rescan.php')}, t('core', 'Error'))); } }); }, - _update:function(categories){ + _update:function(categories) { var categorylist = $('#categorylist'); categorylist.find('li').remove(); for(var category in categories) { -- cgit v1.2.3 From 81536a81e3df86289afcc80308a0bb7f22df3cc1 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Fri, 19 Oct 2012 00:39:09 +0200 Subject: More js updates for app/type in OCCategories --- core/js/oc-vcategories.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'core/js') diff --git a/core/js/oc-vcategories.js b/core/js/oc-vcategories.js index f3935911b8c..b0256c7ec0c 100644 --- a/core/js/oc-vcategories.js +++ b/core/js/oc-vcategories.js @@ -1,12 +1,12 @@ var OCCategories= { edit:function() { - if(OCCategories.app == undefined) { - OC.dialogs.alert('OCCategories.app is not set!'); + if(OCCategories.type == undefined) { + OC.dialogs.alert('OCCategories.type is not set!'); return; } $('body').append('
'); $('#category_dialog').load( - OC.filePath('core', 'ajax', 'vcategories/edit.php') + '?app=' + OCCategories.app, function(response) { + OC.filePath('core', 'ajax', 'vcategories/edit.php') + '?type=' + OCCategories.type, function(response) { try { var jsondata = jQuery.parseJSON(response); if(response.status == 'error') { @@ -64,7 +64,7 @@ var OCCategories= { } }, favorites:function(type, cb) { - $.getJSON(OC.filePath(OCCategories.app, 'ajax', 'categories/favorites.php'),function(jsondata) { + $.getJSON(OC.filePath('core', 'ajax', 'categories/favorites.php'), {type: type},function(jsondata) { if(jsondata.status === 'success') { OCCategories._update(jsondata.data.categories); } else { @@ -92,13 +92,13 @@ var OCCategories= { 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 q = categories + '&type=' + OCCategories.type; + if(OCCategories.app) { + q += '&app=' + OCCategories.app; + $.post(OC.filePath(OCCategories.app, 'ajax', 'categories/delete.php'), q, OCCategories._processDeleteResult); + } else { + $.post(OC.filePath('core', 'ajax', 'vcategories/delete.php'), q, OCCategories._processDeleteResult); + } }, add:function(category) { $.post(OC.filePath('core', 'ajax', 'vcategories/add.php'),{'category':category, 'app':OCCategories.app},function(jsondata) { -- cgit v1.2.3 From fdf3ec1027c0be5fe01bdd4e4780fef812f999af Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Fri, 19 Oct 2012 02:25:39 +0200 Subject: Add wait state to category dialog while processing. --- core/js/oc-vcategories.js | 50 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) (limited to 'core/js') diff --git a/core/js/oc-vcategories.js b/core/js/oc-vcategories.js index b0256c7ec0c..f08df9c0694 100644 --- a/core/js/oc-vcategories.js +++ b/core/js/oc-vcategories.js @@ -14,18 +14,34 @@ var OCCategories= { return; } } catch(e) { - $('#edit_categories_dialog').dialog({ + var setEnabled = function(d, enable) { + if(enable) { + dlg.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"); + $(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) { @@ -56,12 +72,15 @@ var OCCategories= { } }); }, - _processDeleteResult:function(jsondata, status, xhr) { + _processDeleteResult:function(jsondata, cb) { if(jsondata.status == 'success') { OCCategories._update(jsondata.data.categories); } else { OC.dialogs.alert(jsondata.data.message, 'Error'); } + if(typeof cb == 'function') { + cb(); + } }, favorites:function(type, cb) { $.getJSON(OC.filePath('core', 'ajax', 'categories/favorites.php'), {type: type},function(jsondata) { @@ -86,8 +105,7 @@ var OCCategories= { } }); }, - doDelete:function() { - var categories = $('#categorylist').find('input:checkbox').serialize(); + doDelete:function(categories, cb) { if(categories == '' || categories == undefined) { OC.dialogs.alert(t('core', 'No categories selected for deletion.'), t('core', 'Error')); return false; @@ -95,9 +113,13 @@ var OCCategories= { var q = categories + '&type=' + OCCategories.type; if(OCCategories.app) { q += '&app=' + OCCategories.app; - $.post(OC.filePath(OCCategories.app, 'ajax', 'categories/delete.php'), q, OCCategories._processDeleteResult); + $.post(OC.filePath(OCCategories.app, 'ajax', 'categories/delete.php'), q, function(jsondata) { + OCCategories._processDeleteResult(jsondata, cb) + }); } else { - $.post(OC.filePath('core', 'ajax', 'vcategories/delete.php'), q, OCCategories._processDeleteResult); + $.post(OC.filePath('core', 'ajax', 'vcategories/delete.php'), q, function(jsondata) { + OCCategories._processDeleteResult(jsondata, cb) + }); } }, add:function(category) { @@ -109,19 +131,25 @@ var OCCategories= { } }); }, - rescan:function() { + rescan:function(cb) { $.getJSON(OC.filePath(OCCategories.app, 'ajax', 'categories/rescan.php'),function(jsondata, status, xhr) { if(jsondata.status === 'success') { OCCategories._update(jsondata.data.categories); } else { OC.dialogs.alert(jsondata.data.message, 'Error'); } + if(typeof cb == 'function') { + cb(); + } }).error(function(xhr){ if (xhr.status == 404) { OC.dialogs.alert( t('core', 'The required file {file} is not installed!', {file: OC.filePath(OCCategories.app, 'ajax', 'categories/rescan.php')}, t('core', 'Error'))); } + if(typeof cb == 'function') { + cb(); + } }); }, _update:function(categories) { @@ -131,7 +159,7 @@ var OCCategories= { var item = '
  • ' + categories[category] + '
  • '; $(item).appendTo(categorylist); } - if(OCCategories.changed != undefined) { + if(typeof OCCategories.changed === 'function') { OCCategories.changed(categories); } } -- cgit v1.2.3 From 273fdb7b642b79b1d1b0d6abb31d684b6f2ed66f Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Mon, 22 Oct 2012 15:40:08 +0200 Subject: Added type and callback arguments to most methods. --- core/js/oc-vcategories.js | 141 +++++++++++++++++++++++++++++++--------------- 1 file changed, 95 insertions(+), 46 deletions(-) (limited to 'core/js') diff --git a/core/js/oc-vcategories.js b/core/js/oc-vcategories.js index f08df9c0694..53065933be0 100644 --- a/core/js/oc-vcategories.js +++ b/core/js/oc-vcategories.js @@ -1,12 +1,13 @@ var OCCategories= { - edit:function() { - if(OCCategories.type == undefined) { - OC.dialogs.alert('OCCategories.type is not set!'); - return; + category_favorites:'_$!!$_', + 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('
    '); $('#category_dialog').load( - OC.filePath('core', 'ajax', 'vcategories/edit.php') + '?type=' + OCCategories.type, function(response) { + OC.filePath('core', 'ajax', 'vcategories/edit.php') + '?type=' + type, function(response) { try { var jsondata = jQuery.parseJSON(response); if(response.status == 'error') { @@ -27,8 +28,8 @@ var OCCategories= { modal: true, height: 350, minHeight:200, width: 250, minWidth: 200, buttons: { - 'Close': function() { - $(this).dialog('close'); + 'Close': function() { + $(this).dialog('close'); }, 'Delete':function() { var categories = $('#categorylist').find('input:checkbox').serialize(); @@ -72,83 +73,131 @@ var OCCategories= { } }); }, - _processDeleteResult:function(jsondata, cb) { + _processDeleteResult:function(jsondata) { if(jsondata.status == 'success') { OCCategories._update(jsondata.data.categories); } else { OC.dialogs.alert(jsondata.data.message, 'Error'); } - if(typeof cb == 'function') { - cb(); - } }, 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(jsondata.status === 'success') { - OCCategories._update(jsondata.data.categories); + if(typeof cb == 'function') { + cb(jsondata); } else { - OC.dialogs.alert(jsondata.data.message, t('core', 'Error')); + if(jsondata.status === 'success') { + OCCategories._update(jsondata.data.categories); + } else { + OC.dialogs.alert(jsondata.data.message, t('core', 'Error')); + } } }); }, - addToFavorites:function(id, type) { + 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(jsondata.status !== 'success') { - OC.dialogs.alert(jsondata.data.message, 'Error'); + if(typeof cb == 'function') { + cb(jsondata); + } else { + if(jsondata.status !== 'success') { + OC.dialogs.alert(jsondata.data.message, 'Error'); + } } }); }, - removeFromFavorites:function(id, type) { + 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(jsondata.status !== 'success') { - OC.dialogs.alert(jsondata.data.message, t('core', 'Error')); + if(typeof cb == 'function') { + cb(jsondata); + } else { + if(jsondata.status !== 'success') { + OC.dialogs.alert(jsondata.data.message, t('core', 'Error')); + } } }); }, - doDelete:function(categories, cb) { + 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; } - var q = categories + '&type=' + OCCategories.type; - if(OCCategories.app) { - q += '&app=' + OCCategories.app; - $.post(OC.filePath(OCCategories.app, 'ajax', 'categories/delete.php'), q, function(jsondata) { - OCCategories._processDeleteResult(jsondata, cb) + 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) { - OCCategories._processDeleteResult(jsondata, cb) + if(typeof cb == 'function') { + cb(jsondata); + } else { + self._processDeleteResult(jsondata); + } }); } }, - add:function(category) { - $.post(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'); + } } }); }, - rescan:function(cb) { - $.getJSON(OC.filePath(OCCategories.app, 'ajax', 'categories/rescan.php'),function(jsondata, status, xhr) { - if(jsondata.status === 'success') { - OCCategories._update(jsondata.data.categories); - } else { - OC.dialogs.alert(jsondata.data.message, 'Error'); - } + 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(); + cb(jsondata); + } else { + 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( - t('core', 'The required file {file} is not installed!', - {file: OC.filePath(OCCategories.app, 'ajax', 'categories/rescan.php')}, t('core', 'Error'))); - } - if(typeof cb == 'function') { - cb(); + 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); + } } }); }, -- cgit v1.2.3 From 4648dcfa466ca366ea50178e6b3ab9d7e7568ba6 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Sun, 4 Nov 2012 12:09:04 +0100 Subject: VCategories: Use correct variable. --- core/js/oc-vcategories.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/js') diff --git a/core/js/oc-vcategories.js b/core/js/oc-vcategories.js index 53065933be0..609703f2cc9 100644 --- a/core/js/oc-vcategories.js +++ b/core/js/oc-vcategories.js @@ -17,7 +17,7 @@ var OCCategories= { } catch(e) { var setEnabled = function(d, enable) { if(enable) { - dlg.css('cursor', 'default').find('input,button:not(#category_addbutton)') + 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)') -- cgit v1.2.3