oc-vcategories.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. var OCCategories={
  2. edit:function(){
  3. if(OCCategories.app == undefined) {
  4. OC.dialogs.alert('OCCategories.app is not set!');
  5. return;
  6. }
  7. $('body').append('<div id="category_dialog"></div>');
  8. $('#category_dialog').load(OC.filePath('core', 'ajax', 'vcategories/edit.php')+'?app='+OCCategories.app, function(response){
  9. try {
  10. var jsondata = jQuery.parseJSON(response);
  11. if(response.status == 'error'){
  12. OC.dialogs.alert(response.data.message, 'Error');
  13. return;
  14. }
  15. } catch(e) {
  16. $('#edit_categories_dialog').dialog({
  17. modal: true,
  18. height: 350, minHeight:200, width: 250, minWidth: 200,
  19. buttons: {
  20. 'Close': function() {
  21. $(this).dialog("close");
  22. },
  23. 'Delete':function() {
  24. OCCategories.doDelete();
  25. },
  26. 'Rescan':function() {
  27. OCCategories.rescan();
  28. }
  29. },
  30. close : function(event, ui) {
  31. $(this).dialog('destroy').remove();
  32. $('#category_dialog').remove();
  33. },
  34. open : function(event, ui) {
  35. $('#category_addinput').live('input',function(){
  36. if($(this).val().length > 0) {
  37. $('#category_addbutton').removeAttr('disabled');
  38. }
  39. });
  40. $('#categoryform').submit(function() {
  41. OCCategories.add($('#category_addinput').val());
  42. $('#category_addinput').val('');
  43. $('#category_addbutton').attr('disabled', 'disabled');
  44. return false;
  45. });
  46. $('#category_addbutton').live('click',function(e){
  47. e.preventDefault();
  48. if($('#category_addinput').val().length > 0) {
  49. OCCategories.add($('#category_addinput').val());
  50. $('#category_addinput').val('');
  51. }
  52. });
  53. }
  54. });
  55. }
  56. });
  57. },
  58. _processDeleteResult:function(jsondata, status, xhr){
  59. if(jsondata.status == 'success'){
  60. OCCategories._update(jsondata.data.categories);
  61. } else {
  62. OC.dialogs.alert(jsondata.data.message, 'Error');
  63. }
  64. },
  65. doDelete:function(){
  66. var categories = $('#categorylist').find('input:checkbox').serialize();
  67. if(categories == '' || categories == undefined) {
  68. OC.dialogs.alert(t('core', 'No categories selected for deletion.'), t('core', 'Error'));
  69. return false;
  70. }
  71. categories += '&app=' + OCCategories.app;
  72. $.post(OC.filePath(OCCategories.app, 'ajax', 'categories/delete.php'), categories, OCCategories._processDeleteResult)
  73. .error(function(xhr){
  74. if (xhr.status == 404) {
  75. $.post(OC.filePath('core', 'ajax', 'vcategories/delete.php'), categories, OCCategories._processDeleteResult);
  76. }
  77. });
  78. },
  79. add:function(category){
  80. $.getJSON(OC.filePath('core', 'ajax', 'vcategories/add.php'),{'category':category, 'app':OCCategories.app},function(jsondata){
  81. if(jsondata.status == 'success'){
  82. OCCategories._update(jsondata.data.categories);
  83. } else {
  84. OC.dialogs.alert(jsondata.data.message, 'Error');
  85. }
  86. });
  87. return false;
  88. },
  89. rescan:function(){
  90. $.getJSON(OC.filePath(OCCategories.app, 'ajax', 'categories/rescan.php'),function(jsondata, status, xhr){
  91. if(jsondata.status == 'success'){
  92. OCCategories._update(jsondata.data.categories);
  93. } else {
  94. OC.dialogs.alert(jsondata.data.message, 'Error');
  95. }
  96. }).error(function(xhr){
  97. if (xhr.status == 404) {
  98. OC.dialogs.alert('The required file ' + OC.filePath(OCCategories.app, 'ajax', 'categories/rescan.php') + ' is not installed!', 'Error');
  99. }
  100. });
  101. },
  102. _update:function(categories){
  103. var categorylist = $('#categorylist');
  104. categorylist.find('li').remove();
  105. for(var category in categories) {
  106. var item = '<li><input type="checkbox" name="categories" value="' + categories[category] + '" />' + categories[category] + '</li>';
  107. $(item).appendTo(categorylist);
  108. }
  109. if(OCCategories.changed != undefined) {
  110. OCCategories.changed(categories);
  111. }
  112. }
  113. }