2012-10-18 22:09:07 +00:00
|
|
|
var OCCategories= {
|
2012-10-22 13:40:08 +00:00
|
|
|
category_favorites:'_$!<Favorite>!$_',
|
|
|
|
edit:function(type, cb) {
|
|
|
|
if(!type && !this.type) {
|
|
|
|
throw { name: 'MissingParameter', message: t('core', 'The object type is not specified.') };
|
2012-03-12 13:07:48 +00:00
|
|
|
}
|
2012-10-22 13:40:08 +00:00
|
|
|
type = type ? type : this.type;
|
2012-03-12 13:07:48 +00:00
|
|
|
$('body').append('<div id="category_dialog"></div>');
|
2012-10-18 22:09:07 +00:00
|
|
|
$('#category_dialog').load(
|
2012-10-22 13:40:08 +00:00
|
|
|
OC.filePath('core', 'ajax', 'vcategories/edit.php') + '?type=' + type, function(response) {
|
2012-03-12 13:07:48 +00:00
|
|
|
try {
|
|
|
|
var jsondata = jQuery.parseJSON(response);
|
2012-10-18 22:09:07 +00:00
|
|
|
if(response.status == 'error') {
|
2013-04-04 23:56:32 +00:00
|
|
|
OC.dialogs.alert(response.data.message, t('core', 'Error'));
|
2012-03-12 13:07:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch(e) {
|
2012-10-19 00:25:39 +00:00
|
|
|
var setEnabled = function(d, enable) {
|
|
|
|
if(enable) {
|
2012-11-04 11:09:04 +00:00
|
|
|
d.css('cursor', 'default').find('input,button:not(#category_addbutton)')
|
2012-10-19 00:25:39 +00:00
|
|
|
.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({
|
2012-03-12 13:07:48 +00:00
|
|
|
modal: true,
|
|
|
|
height: 350, minHeight:200, width: 250, minWidth: 200,
|
|
|
|
buttons: {
|
2012-10-22 13:40:08 +00:00
|
|
|
'Close': function() {
|
|
|
|
$(this).dialog('close');
|
2012-05-03 23:33:47 +00:00
|
|
|
},
|
2012-03-12 13:07:48 +00:00
|
|
|
'Delete':function() {
|
2012-10-19 00:25:39 +00:00
|
|
|
var categories = $('#categorylist').find('input:checkbox').serialize();
|
|
|
|
setEnabled(dlg, false);
|
|
|
|
OCCategories.doDelete(categories, function() {
|
|
|
|
setEnabled(dlg, true);
|
|
|
|
});
|
2012-03-12 13:07:48 +00:00
|
|
|
},
|
|
|
|
'Rescan':function() {
|
2012-10-19 00:25:39 +00:00
|
|
|
setEnabled(dlg, false);
|
|
|
|
OCCategories.rescan(function() {
|
|
|
|
setEnabled(dlg, true);
|
|
|
|
});
|
2012-03-12 13:07:48 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
close : function(event, ui) {
|
|
|
|
$(this).dialog('destroy').remove();
|
|
|
|
$('#category_dialog').remove();
|
|
|
|
},
|
|
|
|
open : function(event, ui) {
|
2013-01-18 21:38:44 +00:00
|
|
|
$('#category_addinput').on('input',function() {
|
2012-03-12 13:07:48 +00: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;
|
|
|
|
});
|
2013-01-18 21:38:44 +00:00
|
|
|
$('#category_addbutton').on('click',function(e) {
|
2012-03-12 13:07:48 +00:00
|
|
|
e.preventDefault();
|
|
|
|
if($('#category_addinput').val().length > 0) {
|
|
|
|
OCCategories.add($('#category_addinput').val());
|
|
|
|
$('#category_addinput').val('');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2012-10-22 13:40:08 +00:00
|
|
|
_processDeleteResult:function(jsondata) {
|
2012-10-18 22:09:07 +00:00
|
|
|
if(jsondata.status == 'success') {
|
2012-04-12 20:25:40 +00:00
|
|
|
OCCategories._update(jsondata.data.categories);
|
|
|
|
} else {
|
2013-04-04 23:56:32 +00:00
|
|
|
OC.dialogs.alert(jsondata.data.message, t('core', 'Error'));
|
2012-04-12 20:25:40 +00:00
|
|
|
}
|
|
|
|
},
|
2012-10-18 22:09:07 +00:00
|
|
|
favorites:function(type, cb) {
|
2012-10-22 13:40:08 +00:00
|
|
|
if(!type && !this.type) {
|
|
|
|
throw { name: 'MissingParameter', message: t('core', 'The object type is not specified.') };
|
|
|
|
}
|
|
|
|
type = type ? type : this.type;
|
2012-10-18 22:39:09 +00:00
|
|
|
$.getJSON(OC.filePath('core', 'ajax', 'categories/favorites.php'), {type: type},function(jsondata) {
|
2012-10-22 13:40:08 +00:00
|
|
|
if(typeof cb == 'function') {
|
|
|
|
cb(jsondata);
|
2012-10-18 22:09:07 +00:00
|
|
|
} else {
|
2012-10-22 13:40:08 +00:00
|
|
|
if(jsondata.status === 'success') {
|
|
|
|
OCCategories._update(jsondata.data.categories);
|
|
|
|
} else {
|
|
|
|
OC.dialogs.alert(jsondata.data.message, t('core', 'Error'));
|
|
|
|
}
|
2012-10-18 22:09:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2012-10-22 13:40:08 +00:00
|
|
|
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;
|
2012-10-18 22:09:07 +00:00
|
|
|
$.post(OC.filePath('core', 'ajax', 'vcategories/addToFavorites.php'), {id:id, type:type}, function(jsondata) {
|
2012-10-22 13:40:08 +00:00
|
|
|
if(typeof cb == 'function') {
|
|
|
|
cb(jsondata);
|
|
|
|
} else {
|
|
|
|
if(jsondata.status !== 'success') {
|
2013-04-04 23:56:32 +00:00
|
|
|
OC.dialogs.alert(jsondata.data.message, t('core', 'Error'));
|
2012-10-22 13:40:08 +00:00
|
|
|
}
|
2012-10-18 22:09:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2012-10-22 13:40:08 +00:00
|
|
|
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;
|
2012-10-18 22:09:07 +00:00
|
|
|
$.post(OC.filePath('core', 'ajax', 'vcategories/removeFromFavorites.php'), {id:id, type:type}, function(jsondata) {
|
2012-10-22 13:40:08 +00:00
|
|
|
if(typeof cb == 'function') {
|
|
|
|
cb(jsondata);
|
|
|
|
} else {
|
|
|
|
if(jsondata.status !== 'success') {
|
|
|
|
OC.dialogs.alert(jsondata.data.message, t('core', 'Error'));
|
|
|
|
}
|
2012-10-18 22:09:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2012-10-22 13:40:08 +00:00
|
|
|
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;
|
2012-05-03 23:33:47 +00:00
|
|
|
if(categories == '' || categories == undefined) {
|
|
|
|
OC.dialogs.alert(t('core', 'No categories selected for deletion.'), t('core', 'Error'));
|
|
|
|
return false;
|
|
|
|
}
|
2012-10-22 13:40:08 +00:00
|
|
|
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);
|
|
|
|
}
|
2012-10-19 00:25:39 +00:00
|
|
|
});
|
2012-10-18 22:39:09 +00:00
|
|
|
} else {
|
2012-10-19 00:25:39 +00:00
|
|
|
$.post(OC.filePath('core', 'ajax', 'vcategories/delete.php'), q, function(jsondata) {
|
2012-10-22 13:40:08 +00:00
|
|
|
if(typeof cb == 'function') {
|
|
|
|
cb(jsondata);
|
|
|
|
} else {
|
|
|
|
self._processDeleteResult(jsondata);
|
|
|
|
}
|
2012-10-19 00:25:39 +00:00
|
|
|
});
|
2012-10-18 22:39:09 +00:00
|
|
|
}
|
2012-03-12 13:07:48 +00:00
|
|
|
},
|
2012-10-22 13:40:08 +00:00
|
|
|
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);
|
2012-03-12 13:07:48 +00:00
|
|
|
} else {
|
2012-10-22 13:40:08 +00:00
|
|
|
if(jsondata.status === 'success') {
|
|
|
|
OCCategories._update(jsondata.data.categories);
|
|
|
|
} else {
|
2013-04-04 23:56:32 +00:00
|
|
|
OC.dialogs.alert(jsondata.data.message, t('core', 'Error'));
|
2012-10-22 13:40:08 +00:00
|
|
|
}
|
2012-03-12 13:07:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2012-10-22 13:40:08 +00:00
|
|
|
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) {
|
2012-10-19 00:25:39 +00:00
|
|
|
if(typeof cb == 'function') {
|
2012-10-22 13:40:08 +00:00
|
|
|
cb(jsondata);
|
|
|
|
} else {
|
|
|
|
if(jsondata.status === 'success') {
|
|
|
|
OCCategories._update(jsondata.data.categories);
|
|
|
|
} else {
|
2013-04-04 23:56:32 +00:00
|
|
|
OC.dialogs.alert(jsondata.data.message, t('core', 'Error'));
|
2012-10-22 13:40:08 +00:00
|
|
|
}
|
2012-10-19 00:25:39 +00:00
|
|
|
}
|
2012-04-13 14:12:55 +00:00
|
|
|
}).error(function(xhr){
|
|
|
|
if (xhr.status == 404) {
|
2012-10-22 13:40:08 +00:00
|
|
|
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 {
|
2013-04-04 23:56:32 +00:00
|
|
|
OC.dialogs.alert(errormessage, t('core', 'Error'));
|
2012-10-22 13:40:08 +00:00
|
|
|
}
|
2012-10-19 00:25:39 +00:00
|
|
|
}
|
2012-03-12 13:07:48 +00:00
|
|
|
});
|
|
|
|
},
|
2012-10-18 22:09:07 +00:00
|
|
|
_update:function(categories) {
|
2012-03-12 13:07:48 +00: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);
|
|
|
|
}
|
2012-10-19 00:25:39 +00:00
|
|
|
if(typeof OCCategories.changed === 'function') {
|
2012-03-12 13:07:48 +00:00
|
|
|
OCCategories.changed(categories);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|