summaryrefslogtreecommitdiffstats
path: root/core/js
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2016-01-21 15:35:15 +0100
committerJoas Schilling <nickvergessen@owncloud.com>2016-01-21 15:56:25 +0100
commitf108dbfa6a4e93e266f16bf22fc54cb52f7cd8fa (patch)
treea0abd074ff5256c3741b384869ed2b456ca8aae5 /core/js
parent2b4532c6b91dc38c5af8d703826a1fbf11134a6a (diff)
downloadnextcloud-server-f108dbfa6a4e93e266f16bf22fc54cb52f7cd8fa.tar.gz
nextcloud-server-f108dbfa6a4e93e266f16bf22fc54cb52f7cd8fa.zip
Move getDescriptiveTag to core
Diffstat (limited to 'core/js')
-rw-r--r--core/js/core.json1
-rw-r--r--core/js/systemtags/systemtagmodel.js3
-rw-r--r--core/js/systemtags/systemtags.js47
-rw-r--r--core/js/tests/specs/systemtags/systemtagsSpec.js51
4 files changed, 99 insertions, 3 deletions
diff --git a/core/js/core.json b/core/js/core.json
index 93c64afea98..d894d59ca54 100644
--- a/core/js/core.json
+++ b/core/js/core.json
@@ -45,6 +45,7 @@
"mimetypelist.js",
"files/fileinfo.js",
"files/client.js",
+ "systemtags/systemtags.js",
"systemtags/systemtagmodel.js",
"systemtags/systemtagscollection.js",
"systemtags/systemtagsmappingcollection.js",
diff --git a/core/js/systemtags/systemtagmodel.js b/core/js/systemtags/systemtagmodel.js
index ad6ea7b7d44..e6014977d2b 100644
--- a/core/js/systemtags/systemtagmodel.js
+++ b/core/js/systemtags/systemtagmodel.js
@@ -43,9 +43,6 @@
}
});
- /**
- * @namespace
- */
OC.SystemTags = OC.SystemTags || {};
OC.SystemTags.SystemTagModel = SystemTagModel;
})(OC);
diff --git a/core/js/systemtags/systemtags.js b/core/js/systemtags/systemtags.js
new file mode 100644
index 00000000000..05d3ba2c7b8
--- /dev/null
+++ b/core/js/systemtags/systemtags.js
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2016
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+(function(OC) {
+ /**
+ * @namespace
+ */
+ OC.SystemTags = {
+ /**
+ *
+ * @param {OC.SystemTags.SystemTagModel|Object|String} tag
+ * @return {jQuery}
+ */
+ getDescriptiveTag: function(tag) {
+ if (_.isUndefined(tag.name) && !_.isUndefined(tag.toJSON)) {
+ tag = tag.toJSON();
+ }
+
+ if (_.isUndefined(tag.name)) {
+ return $('<span>').addClass('non-existing-tag').text(
+ t('core', 'Non-existing tag #{tag}', {
+ tag: tag
+ })
+ );
+ }
+
+ var $span = $('<span>'),
+ $tag = $('<em>').text(
+ t('core', '({uservisible}, {userassignable})', {
+ uservisible: tag.userVisible ? t('core', 'visible') : t('core', 'invisible'),
+ userassignable: tag.userAssignable ? t('core', 'assignable') : t('core', 'not assignable')
+ })
+ );
+ $span.append(escapeHTML(tag.name) + ' ');
+ $span.append($tag);
+ return $span;
+ }
+ };
+})(OC);
+
diff --git a/core/js/tests/specs/systemtags/systemtagsSpec.js b/core/js/tests/specs/systemtags/systemtagsSpec.js
new file mode 100644
index 00000000000..2e8390ad9f0
--- /dev/null
+++ b/core/js/tests/specs/systemtags/systemtagsSpec.js
@@ -0,0 +1,51 @@
+/**
+* ownCloud
+*
+* @author Joas Schilling
+* @copyright 2016 Joas Schilling <nickvergessen@owncloud.com>
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+describe('OC.SystemTags tests', function() {
+ it('describes non existing tag', function() {
+ var $return = OC.SystemTags.getDescriptiveTag('23');
+ expect($return.text()).toEqual('Non-existing tag #23');
+ expect($return.hasClass('non-existing-tag')).toEqual(true);
+ });
+
+ it('describes SystemTagModel', function() {
+ var tag = new OC.SystemTags.SystemTagModel({
+ id: 23,
+ name: 'Twenty Three',
+ userAssignable: true,
+ userVisible: true
+ });
+ var $return = OC.SystemTags.getDescriptiveTag(tag);
+ expect($return.text()).toEqual('Twenty Three (visible, assignable)');
+ expect($return.hasClass('non-existing-tag')).toEqual(false);
+ });
+
+ it('describes JSON tag object', function() {
+ var $return = OC.SystemTags.getDescriptiveTag({
+ id: 42,
+ name: 'Fourty Two',
+ userAssignable: false,
+ userVisible: false
+ });
+ expect($return.text()).toEqual('Fourty Two (invisible, not assignable)');
+ expect($return.hasClass('non-existing-tag')).toEqual(false);
+ });
+});