2012-10-19 02:09:07 +04:00
|
|
|
var OCCategories= {
|
|
|
|
edit:function() {
|
2012-10-19 02:39:09 +04:00
|
|
|
if(OCCategories.type == undefined) {
|
|
|
|
OC.dialogs.alert('OCCategories.type is not set!');
|
2012-03-12 17:07:48 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$('body').append('<div id="category_dialog"></div>');
|
2012-10-19 02:09:07 +04:00
|
|
|
$('#category_dialog').load(
|
2012-10-19 02:39:09 +04:00
|
|
|
OC.filePath('core', 'ajax', 'vcategories/edit.php') + '?type=' + OCCategories.type, function(response) {
|
2012-03-12 17:07:48 +04:00
|
|
|
try {
|
|
|
|
var jsondata = jQuery.parseJSON(response);
|
2012-10-19 02:09:07 +04:00
|
|
|
if(response.status == 'error') {
|
2012-03-12 17:07:48 +04:00
|
|
|
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: {
|
2012-05-04 03:33:47 +04:00
|
|
|
'Close': function() {
|
|
|
|
$(this).dialog("close");
|
|
|
|
},
|
2012-03-12 17:07:48 +04:00
|
|
|
'Delete':function() {
|
2012-04-10 23:53:51 +04:00
|
|
|
OCCategories.doDelete();
|
2012-03-12 17:07:48 +04:00
|
|
|
},
|
|
|
|
'Rescan':function() {
|
|
|
|
OCCategories.rescan();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
close : function(event, ui) {
|
|
|
|
$(this).dialog('destroy').remove();
|
|
|
|
$('#category_dialog').remove();
|
|
|
|
},
|
|
|
|
open : function(event, ui) {
|
2012-10-19 02:09:07 +04:00
|
|
|
$('#category_addinput').live('input',function() {
|
2012-03-12 17:07:48 +04:00
|
|
|
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;
|
|
|
|
});
|
2012-10-19 02:09:07 +04:00
|
|
|
$('#category_addbutton').live('click',function(e) {
|
2012-03-12 17:07:48 +04:00
|
|
|
e.preventDefault();
|
|
|
|
if($('#category_addinput').val().length > 0) {
|
|
|
|
OCCategories.add($('#category_addinput').val());
|
|
|
|
$('#category_addinput').val('');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2012-10-19 02:09:07 +04:00
|
|
|
_processDeleteResult:function(jsondata, status, xhr) {
|
|
|
|
if(jsondata.status == 'success') {
|
2012-04-13 00:25:40 +04:00
|
|
|
OCCategories._update(jsondata.data.categories);
|
|
|
|
} else {
|
|
|
|
OC.dialogs.alert(jsondata.data.message, 'Error');
|
|
|
|
}
|
|
|
|
},
|
2012-10-19 02:09:07 +04:00
|
|
|
favorites:function(type, cb) {
|
2012-10-19 02:39:09 +04:00
|
|
|
$.getJSON(OC.filePath('core', 'ajax', 'categories/favorites.php'), {type: type},function(jsondata) {
|
2012-10-19 02:09:07 +04:00
|
|
|
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() {
|
2012-05-04 03:33:47 +04:00
|
|
|
var categories = $('#categorylist').find('input:checkbox').serialize();
|
|
|
|
if(categories == '' || categories == undefined) {
|
|
|
|
OC.dialogs.alert(t('core', 'No categories selected for deletion.'), t('core', 'Error'));
|
|
|
|
return false;
|
|
|
|
}
|
2012-10-19 02:39:09 +04:00
|
|
|
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);
|
|
|
|
}
|
2012-03-12 17:07:48 +04:00
|
|
|
},
|
2012-10-19 02:09:07 +04:00
|
|
|
add:function(category) {
|
|
|
|
$.post(OC.filePath('core', 'ajax', 'vcategories/add.php'),{'category':category, 'app':OCCategories.app},function(jsondata) {
|
|
|
|
if(jsondata.status === 'success') {
|
2012-03-12 17:07:48 +04:00
|
|
|
OCCategories._update(jsondata.data.categories);
|
|
|
|
} else {
|
|
|
|
OC.dialogs.alert(jsondata.data.message, 'Error');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2012-10-19 02:09:07 +04:00
|
|
|
rescan:function() {
|
|
|
|
$.getJSON(OC.filePath(OCCategories.app, 'ajax', 'categories/rescan.php'),function(jsondata, status, xhr) {
|
|
|
|
if(jsondata.status === 'success') {
|
2012-03-12 17:07:48 +04:00
|
|
|
OCCategories._update(jsondata.data.categories);
|
|
|
|
} else {
|
|
|
|
OC.dialogs.alert(jsondata.data.message, 'Error');
|
|
|
|
}
|
2012-04-13 18:12:55 +04:00
|
|
|
}).error(function(xhr){
|
|
|
|
if (xhr.status == 404) {
|
2012-10-19 02:09:07 +04:00
|
|
|
OC.dialogs.alert(
|
|
|
|
t('core', 'The required file {file} is not installed!',
|
|
|
|
{file: OC.filePath(OCCategories.app, 'ajax', 'categories/rescan.php')}, t('core', 'Error')));
|
2012-04-13 18:12:55 +04:00
|
|
|
}
|
2012-03-12 17:07:48 +04:00
|
|
|
});
|
|
|
|
},
|
2012-10-19 02:09:07 +04:00
|
|
|
_update:function(categories) {
|
2012-03-12 17:07:48 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|