diff --git a/gui/app/components/document/document-meta.js b/gui/app/components/document/document-meta.js index acb32b47..1bfddb85 100644 --- a/gui/app/components/document/document-meta.js +++ b/gui/app/components/document/document-meta.js @@ -13,13 +13,18 @@ import { computed } from '@ember/object'; import { inject as service } from '@ember/service'; import Component from '@ember/component'; import { A } from "@ember/array" +import { schedule } from '@ember/runloop'; export default Component.extend({ documentService: service('document'), categoryService: service('category'), sessionService: service('session'), - newCategory: '', + maxTags: 3, categories: A([]), + newCategory: '', + tagz: A([]), + tagzModal: A([]), + newTag: '', showCategoryModal: false, hasCategories: computed('categories', function() { return this.get('categories').length > 0; @@ -36,6 +41,36 @@ export default Component.extend({ this.load(); }, + didInsertElement() { + this._super(...arguments); + + $('#document-tags-modal').on('show.bs.modal', (event) => { // eslint-disable-line no-unused-vars + schedule('afterRender', () => { + $("#add-tag-field").focus(); + + $("#add-tag-field").off("keydown").on("keydown", function(e) { + if (e.shiftKey) { + return false; + } + + if (e.which === 13 || e.which === 45 || e.which === 189 || e.which === 8 || e.which === 127 || (e.which >= 65 && e.which <= 90) || (e.which >= 97 && e.which <= 122) || (e.which >= 48 && e.which <= 57)) { + return true; + } + + return false; + }); + + // make copy of tags for editing + this.set('tagzEdit', this.get('tagz')); + }); + }); + }, + + willDestroyElement() { + this._super(...arguments); + $("#add-tag-field").off("keydown"); + }, + load() { this.get('categoryService').getUserVisible(this.get('folder.id')).then((categories) => { let cats = A(categories); @@ -109,6 +144,48 @@ export default Component.extend({ }); return true; - } - } + }, + + onAddTag(e) { + e.preventDefault(); + + let tags = this.get("tagzEdit"); + let tag = this.get('newTag'); + tag = tag.toLowerCase().trim(); + + // empty or dupe? + if (tag.length === 0 || _.contains(tags, tag) || tags.length >= this.get('maxTags') || tag.startsWith('-')) { + $('#add-tag-field').addClass('is-invalid'); + return; + } + + tags.pushObject(tag); + this.set('tagzEdit', tags); + this.set('newTag', ''); + $('#add-tag-field').removeClass('is-invalid'); + }, + + onRemoveTag(tagToRemove) { + this.set('tagzEdit', _.without(this.get("tagzEdit"), tagToRemove)); + }, + + onSaveTags() { + let tags = this.get("tagzEdit"); + + let save = "#"; + _.each(tags, function(tag) { + save = save + tag + "#"; + }); + + let doc = this.get('document'); + doc.set('tags', save); + this.attrs.onSaveDocument(doc); + + this.load(); + this.set('newTag', ''); + + $('#document-tags-modal').modal('hide'); + $('#document-tags-modal').modal('dispose'); + }, + } }); diff --git a/gui/app/components/document/tag-editor.js b/gui/app/components/document/tag-editor.js deleted file mode 100644 index 933cbb0c..00000000 --- a/gui/app/components/document/tag-editor.js +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright 2016 Documize Inc. . All rights reserved. -// -// This software (Documize Community Edition) is licensed under -// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html -// -// You can operate outside the AGPL restrictions by purchasing -// Documize Enterprise Edition and obtaining a commercial license -// by contacting . -// -// https://documize.com - -import { computed } from '@ember/object'; - -import Component from '@ember/component'; - -export default Component.extend({ - documentTags: [], - tagz: [], - newTag: "", - maxTags: 3, - canAdd: false, - emptyState: computed('tagz', function() { - return (this.get('tagz').length === 0 && !this.get('permissions.documentEdit')); - }), - - init() { - this._super(...arguments); - let tagz = []; - - if (!_.isUndefined(this.get('documentTags')) && this.get('documentTags').length > 1) { - let tags = this.get('documentTags').split('#'); - _.each(tags, function(tag) { - if (tag.length > 0) { - tagz.pushObject(tag); - } - }); - } - - this.set('tagz', tagz); - this.set('canAdd', this.get('permissions.documentEdit') && this.get('tagz').get('length') < 3); - }, - - didUpdateAttrs() { - this._super(...arguments); - this.set('canAdd', this.get('permissions.documentEdit') && this.get('tagz').get('length') < 3); - }, - - - willDestroyElement() { - this._super(...arguments); - $("#add-tag-field").off("keydown"); - }, - - actions: { - onTagEditor() { - $("#add-tag-field").off("keydown").on("keydown", function(e) { - if (e.shiftKey) { - return false; - } - - if (e.which === 13 || e.which === 45 || e.which === 189 || e.which === 8 || e.which === 127 || (e.which >= 65 && e.which <= 90) || (e.which >= 97 && e.which <= 122) || (e.which >= 48 && e.which <= 57)) { - return true; - } - - return false; - }); - }, - - addTag() { - let tags = this.get("tagz"); - let tag = this.get('newTag'); - tag = tag.toLowerCase().trim(); - - // empty or dupe? - if (tag.length === 0 || _.contains(tags, tag) || tags.length >= this.get('maxTags') || tag.startsWith('-')) { - return false; - } - - tags.pushObject(tag); - this.set('tagz', tags); - this.set('newTag', ''); - - let save = "#"; - _.each(tags, function(tag) { - save = save + tag + "#"; - }); - - this.get('onChange')(save); - - return true; - }, - - // removeTag removes specified tag from the list of tags associated with this document. - removeTag(tagToRemove) { - let tags = this.get("tagz"); - let save = ""; - - tags = _.without(tags, tagToRemove); - - _.each(tags, function(tag) { - save = save + tag + "#"; - }); - - if (save.length) { - save = "#" + save; - } - - this.set('tagz', tags); - this.get('onChange')(save); - }, - } -}); diff --git a/gui/app/pods/document/index/template.hbs b/gui/app/pods/document/index/template.hbs index 7d140fc7..5419d8d1 100644 --- a/gui/app/pods/document/index/template.hbs +++ b/gui/app/pods/document/index/template.hbs @@ -9,8 +9,7 @@ {{/toolbar/t-toolbar}} {{document/document-heading document=model.document permissions=model.permissions onSaveDocument=(action 'onSaveDocument')}} - {{document/document-meta document=model.document folder=model.folder folders=model.folders permissions=model.permissions}} - {{document/tag-editor documentTags=model.document.tags permissions=model.permissions onChange=(action 'onTagChange')}} + {{document/document-meta document=model.document folder=model.folder folders=model.folders permissions=model.permissions onSaveDocument=(action 'onSaveDocument')}}
diff --git a/gui/app/styles/view/document/doc-meta.scss b/gui/app/styles/view/document/doc-meta.scss index cd488a91..d7d22446 100644 --- a/gui/app/styles/view/document/doc-meta.scss +++ b/gui/app/styles/view/document/doc-meta.scss @@ -54,49 +54,3 @@ } } } - -.document-category { - display: inline-block; - margin: 0 0 0 30px; - - > .regular-button { - margin-right: 10px; - } - - > .caption { - text-transform: uppercase; - color: $color-gray; - font-weight: bold; - font-size: 1.0rem; - margin: 0 0 10px 0; - } -} - -.document-category-dialog { - height: 200px; - overflow-y: auto; - margin: 0; - padding: 0; -} - -.document-tags { - margin: 20px 0 0 0; - - > .caption { - text-transform: uppercase; - color: $color-gray; - font-weight: bold; - font-size: 1.0rem; - margin: 0 0 10px 0; - } - - > .regular-button { - margin-right: 10px; - text-transform: lowercase; - } - - > .none { - color: $color-gray; - font-size: 0.9rem; - } -} diff --git a/gui/app/templates/components/document/document-meta.hbs b/gui/app/templates/components/document/document-meta.hbs index eb1e922c..b6b373c4 100644 --- a/gui/app/templates/components/document/document-meta.hbs +++ b/gui/app/templates/components/document/document-meta.hbs @@ -2,13 +2,7 @@
-
Categories - {{#if canSelectCategory}} -
- edit -
- {{/if}} -
+
Categories
{{#each selectedCategories as |cat|}} {{#link-to 'folder' folder.id folder.slug (query-params category=cat.id)}} @@ -24,6 +18,11 @@ {{/if}} {{/if}} {{/each}} + {{#if canSelectCategory}} +
+ edit +
+ {{/if}}
@@ -33,6 +32,11 @@ {{#each tagz as |t index|}} {{concat '#' t}}   {{/each}} + {{#if canSelectCategory}} +
+ edit +
+ {{/if}}
@@ -40,9 +44,37 @@
{{#if permissions.documentEdit}} - {{#ui/ui-dialog title="Set Document Cateogories" confirmCaption="Select" buttonType="btn-outline-success" show=showCategoryModal onAction=(action 'onSaveCategory')}} + {{#ui/ui-dialog title="Document Categories" confirmCaption="Select" buttonType="btn-outline-success" show=showCategoryModal onAction=(action 'onSaveCategory')}}

Select who can view documents within category

{{ui/ui-list-picker items=categories nameField='category' singleSelect=false}} {{/ui/ui-dialog}} -{{/if}} + +{{/if}} diff --git a/gui/app/templates/components/document/tag-editor.hbs b/gui/app/templates/components/document/tag-editor.hbs deleted file mode 100644 index e4bed582..00000000 --- a/gui/app/templates/components/document/tag-editor.hbs +++ /dev/null @@ -1,28 +0,0 @@ -
-
Tag
- {{#each tagz as |t index|}} -
{{concat '#' t}}
- {{/each}} - {{#if canAdd}} -
- add -
- {{#dropdown-dialog tagName="span" target="document-tag-button" position="bottom left" button="Add" color="flat-green" onAction=(action 'addTag') focusOn="add-tag-field" onOpenCallback=(action 'onTagEditor') targetOffset="20px 0"}} -
- -
Lowercase letters, numbers, dashes
- {{focus-input id="add-tag-field" value=newTag type="text"}} -
- {{/dropdown-dialog}} - {{/if}} - {{#if permissions.documentEdit}} - {{#each tagz as |t index|}} - {{#dropdown-dialog target=(concat 'delete-tag-' index) position="bottom left" button="Delete" color="flat-red" onAction=(action 'removeTag' t)}} -

Are you sure you want delete this tag?

- {{/dropdown-dialog}} - {{/each}} - {{/if}} - {{#if emptyState}} -
none
- {{/if}} -