summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-11-13 15:40:46 -0800
committerThomas Tanghus <thomas@tanghus.net>2012-11-13 15:40:46 -0800
commitc353568ea09ef89e82c7b0f35b8d646b9c35005d (patch)
tree0d5247b00f465e5d85ead47fd1532cc20bf5a68e /core
parent9c36326e4776350b64b9a657feb5fca8a50cefcc (diff)
parentbfb6faa85077ef8f7e56a7e706f57587460a2125 (diff)
downloadnextcloud-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')
-rw-r--r--core/ajax/vcategories/add.php20
-rw-r--r--core/ajax/vcategories/addToFavorites.php38
-rw-r--r--core/ajax/vcategories/delete.php25
-rw-r--r--core/ajax/vcategories/edit.php14
-rw-r--r--core/ajax/vcategories/favorites.php30
-rw-r--r--core/ajax/vcategories/removeFromFavorites.php38
-rw-r--r--core/js/oc-vcategories.js180
-rw-r--r--core/routes.php6
-rw-r--r--core/templates/edit_categories_dialog.php9
9 files changed, 293 insertions, 67 deletions
diff --git a/core/ajax/vcategories/add.php b/core/ajax/vcategories/add.php
index 8d31275dbfb..23d00af70ab 100644
--- a/core/ajax/vcategories/add.php
+++ b/core/ajax/vcategories/add.php
@@ -14,23 +14,25 @@ function debug($msg) {
OC_Log::write('core', 'ajax/vcategories/add.php: '.$msg, OC_Log::DEBUG);
}
-OC_JSON::checkLoggedIn();
-$category = isset($_GET['category'])?strip_tags($_GET['category']):null;
-$app = isset($_GET['app'])?$_GET['app']:null;
+OCP\JSON::checkLoggedIn();
+OCP\JSON::callCheck();
-if(is_null($app)) {
- bailOut(OC_Contacts_App::$l10n->t('Application name not provided.'));
-}
+$l = OC_L10N::get('core');
+
+$category = isset($_POST['category']) ? strip_tags($_POST['category']) : null;
+$type = isset($_POST['type']) ? $_POST['type'] : null;
-OC_JSON::checkAppEnabled($app);
+if(is_null($type)) {
+ bailOut($l->t('Category type not provided.'));
+}
if(is_null($category)) {
- bailOut(OC_Contacts_App::$l10n->t('No category to add?'));
+ bailOut($l->t('No category to add?'));
}
debug(print_r($category, true));
-$categories = new OC_VCategories($app);
+$categories = new OC_VCategories($type);
if($categories->hasCategory($category)) {
bailOut(OC_Contacts_App::$l10n->t('This category already exists: '.$category));
} else {
diff --git a/core/ajax/vcategories/addToFavorites.php b/core/ajax/vcategories/addToFavorites.php
new file mode 100644
index 00000000000..52f62d5fc6b
--- /dev/null
+++ b/core/ajax/vcategories/addToFavorites.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+function bailOut($msg) {
+ OC_JSON::error(array('data' => array('message' => $msg)));
+ OC_Log::write('core', 'ajax/vcategories/addToFavorites.php: '.$msg, OC_Log::DEBUG);
+ exit();
+}
+function debug($msg) {
+ OC_Log::write('core', 'ajax/vcategories/addToFavorites.php: '.$msg, OC_Log::DEBUG);
+}
+
+OCP\JSON::checkLoggedIn();
+OCP\JSON::callCheck();
+
+$l = OC_L10N::get('core');
+
+$id = isset($_POST['id']) ? strip_tags($_POST['id']) : null;
+$type = isset($_POST['type']) ? $_POST['type'] : null;
+
+if(is_null($type)) {
+ bailOut($l->t('Object type not provided.'));
+}
+
+if(is_null($id)) {
+ bailOut($l->t('%s ID not provided.', $type));
+}
+
+$categories = new OC_VCategories($type);
+if(!$categories->addToFavorites($id, $type)) {
+ bailOut($l->t('Error adding %s to favorites.', $id));
+}
+
+OC_JSON::success();
diff --git a/core/ajax/vcategories/delete.php b/core/ajax/vcategories/delete.php
index 74b0220870c..dfec3785743 100644
--- a/core/ajax/vcategories/delete.php
+++ b/core/ajax/vcategories/delete.php
@@ -15,21 +15,26 @@ function debug($msg) {
OC_Log::write('core', 'ajax/vcategories/delete.php: '.$msg, OC_Log::DEBUG);
}
-OC_JSON::checkLoggedIn();
-$app = isset($_POST['app'])?$_POST['app']:null;
-$categories = isset($_POST['categories'])?$_POST['categories']:null;
-if(is_null($app)) {
- bailOut(OC_Contacts_App::$l10n->t('Application name not provided.'));
-}
+OCP\JSON::checkLoggedIn();
+OCP\JSON::callCheck();
+
+$l = OC_L10N::get('core');
-OC_JSON::checkAppEnabled($app);
+$type = isset($_POST['type']) ? $_POST['type'] : null;
+$categories = isset($_POST['categories']) ? $_POST['categories'] : null;
+
+if(is_null($type)) {
+ bailOut($l->t('Object type not provided.'));
+}
-debug('The application "'.$app.'" uses the default file. OC_VObjects will not be updated.');
+debug('The application using category type "'
+ . $type
+ . '" uses the default file for deletion. OC_VObjects will not be updated.');
if(is_null($categories)) {
- bailOut('No categories selected for deletion.');
+ bailOut($l->t('No categories selected for deletion.'));
}
-$vcategories = new OC_VCategories($app);
+$vcategories = new OC_VCategories($type);
$vcategories->delete($categories);
OC_JSON::success(array('data' => array('categories'=>$vcategories->categories())));
diff --git a/core/ajax/vcategories/edit.php b/core/ajax/vcategories/edit.php
index caeebcaa940..0387b17576c 100644
--- a/core/ajax/vcategories/edit.php
+++ b/core/ajax/vcategories/edit.php
@@ -16,16 +16,18 @@ function debug($msg) {
}
OC_JSON::checkLoggedIn();
-$app = isset($_GET['app'])?$_GET['app']:null;
-if(is_null($app)) {
- bailOut('Application name not provided.');
+$l = OC_L10N::get('core');
+
+$type = isset($_GET['type']) ? $_GET['type'] : null;
+
+if(is_null($type)) {
+ bailOut($l->t('Category type not provided.'));
}
-OC_JSON::checkAppEnabled($app);
-$tmpl = new OC_TEMPLATE("core", "edit_categories_dialog");
+$tmpl = new OCP\Template("core", "edit_categories_dialog");
-$vcategories = new OC_VCategories($app);
+$vcategories = new OC_VCategories($type);
$categories = $vcategories->categories();
debug(print_r($categories, true));
$tmpl->assign('categories', $categories);
diff --git a/core/ajax/vcategories/favorites.php b/core/ajax/vcategories/favorites.php
new file mode 100644
index 00000000000..20accea61cd
--- /dev/null
+++ b/core/ajax/vcategories/favorites.php
@@ -0,0 +1,30 @@
+<?php
+/**
+ * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+function bailOut($msg) {
+ OC_JSON::error(array('data' => array('message' => $msg)));
+ OC_Log::write('core', 'ajax/vcategories/addToFavorites.php: '.$msg, OC_Log::DEBUG);
+ exit();
+}
+function debug($msg) {
+ OC_Log::write('core', 'ajax/vcategories/addToFavorites.php: '.$msg, OC_Log::DEBUG);
+}
+
+OCP\JSON::checkLoggedIn();
+OCP\JSON::callCheck();
+
+$type = isset($_GET['type']) ? $_GET['type'] : null;
+
+if(is_null($type)) {
+ $l = OC_L10N::get('core');
+ bailOut($l->t('Object type not provided.'));
+}
+
+$categories = new OC_VCategories($type);
+$ids = $categories->getFavorites($type)) {
+
+OC_JSON::success(array('ids' => $ids));
diff --git a/core/ajax/vcategories/removeFromFavorites.php b/core/ajax/vcategories/removeFromFavorites.php
new file mode 100644
index 00000000000..ba6e95c2497
--- /dev/null
+++ b/core/ajax/vcategories/removeFromFavorites.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+function bailOut($msg) {
+ OC_JSON::error(array('data' => array('message' => $msg)));
+ OC_Log::write('core', 'ajax/vcategories/removeFromFavorites.php: '.$msg, OC_Log::DEBUG);
+ exit();
+}
+function debug($msg) {
+ OC_Log::write('core', 'ajax/vcategories/removeFromFavorites.php: '.$msg, OC_Log::DEBUG);
+}
+
+OCP\JSON::checkLoggedIn();
+OCP\JSON::callCheck();
+
+$l = OC_L10N::get('core');
+
+$id = isset($_POST['id']) ? strip_tags($_POST['id']) : null;
+$type = isset($_POST['type']) ? $_POST['type'] : null;
+
+if(is_null($type)) {
+ bailOut($l->t('Object type not provided.'));
+}
+
+if(is_null($id)) {
+ bailOut($l->t('%s ID not provided.', $type));
+}
+
+$categories = new OC_VCategories($type);
+if(!$categories->removeFromFavorites($id, $type)) {
+ bailOut($l->t('Error removing %s from favorites.', $id));
+}
+
+OC_JSON::success();
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);
}
}
diff --git a/core/routes.php b/core/routes.php
index 6f999356689..fc511d403d8 100644
--- a/core/routes.php
+++ b/core/routes.php
@@ -24,6 +24,12 @@ $this->create('core_ajax_vcategories_add', '/core/ajax/vcategories/add.php')
->actionInclude('core/ajax/vcategories/add.php');
$this->create('core_ajax_vcategories_delete', '/core/ajax/vcategories/delete.php')
->actionInclude('core/ajax/vcategories/delete.php');
+$this->create('core_ajax_vcategories_addtofavorites', '/core/ajax/vcategories/addToFavorites.php')
+ ->actionInclude('core/ajax/vcategories/addToFavorites.php');
+$this->create('core_ajax_vcategories_removefromfavorites', '/core/ajax/vcategories/removeFromFavorites.php')
+ ->actionInclude('core/ajax/vcategories/removeFromFavorites.php');
+$this->create('core_ajax_vcategories_favorites', '/core/ajax/vcategories/favorites.php')
+ ->actionInclude('core/ajax/vcategories/favorites.php');
$this->create('core_ajax_vcategories_edit', '/core/ajax/vcategories/edit.php')
->actionInclude('core/ajax/vcategories/edit.php');
// Routing
diff --git a/core/templates/edit_categories_dialog.php b/core/templates/edit_categories_dialog.php
index 8997fa586bd..d0b7b5ee62a 100644
--- a/core/templates/edit_categories_dialog.php
+++ b/core/templates/edit_categories_dialog.php
@@ -6,11 +6,14 @@ $categories = isset($_['categories'])?$_['categories']:array();
<form method="post" id="categoryform">
<div class="scrollarea">
<ul id="categorylist">
- <?php foreach($categories as $category) { ?>
+ <?php foreach($categories as $category): ?>
<li><input type="checkbox" name="categories[]" value="<?php echo $category; ?>" /><?php echo $category; ?></li>
- <?php } ?>
+ <?php endforeach; ?>
</ul>
</div>
- <div class="bottombuttons"><input type="text" id="category_addinput" name="category" /><button id="category_addbutton" disabled="disabled"><?php echo $l->t('Add'); ?></button></div>
+ <div class="bottombuttons">
+ <input type="text" id="category_addinput" name="category" />
+ <button id="category_addbutton" disabled="disabled"><?php echo $l->t('Add'); ?></button>
+ </div>
</form>
</div>