src_js/iconolab-bundle/src/components/editor/AnnotationForm.vue
changeset 325 8f158a4c7759
parent 323 55c024fc7c60
child 327 44a122f0f2de
equal deleted inserted replaced
324:8f19067caeec 325:8f158a4c7759
    28 <script>
    28 <script>
    29 
    29 
    30     import TagList from '../tagform/TagList.vue'
    30     import TagList from '../tagform/TagList.vue'
    31 
    31 
    32     export default {
    32     export default {
    33         props: ['action'],
    33         props: ['action', 'annotation'],
    34         components: {
    34         components: {
    35             'tag-list': TagList
    35             'tag-list': TagList
    36         },
    36         },
    37         data() {
    37         data() {
    38             return {
    38             return {
    39                 'title': '',
    39                 'title': '',
    40                 'description': '',
    40                 'description': '',
    41                 'fragment': '',
    41                 'fragment': '',
    42                 'tags': [],
    42                 'tags': [],
    43                 'annotation': null,
    43             }
       
    44         },
       
    45         watch: {
       
    46             annotation: function(annotation) {
       
    47                 if (annotation) {
       
    48                     Object.assign(this, annotation);
       
    49                 } else {
       
    50                     this.reset();
       
    51                 }
    44             }
    52             }
    45         },
    53         },
    46         computed: {
    54         computed: {
    47             formAction: function() {
    55             formAction: function() {
    48                 if (this.annotation) {
    56                 if (this.annotation) {
    61 
    69 
    62                 return JSON.stringify(tags);
    70                 return JSON.stringify(tags);
    63             }
    71             }
    64         },
    72         },
    65         methods: {
    73         methods: {
    66             setAnnotation: function(annotation) {
       
    67                 const clone = annotation;
       
    68                 this.annotation = clone;
       
    69 
       
    70                 Object.assign(this, annotation);
       
    71             },
       
    72             onTagsChange: function(tags) {
    74             onTagsChange: function(tags) {
    73                 this.tags = tags;
    75                 this.tags = tags;
    74             },
    76             },
    75             reset: function() {
    77             reset: function() {
    76                 Object.assign(this, {
    78                 Object.assign(this, {
    77                     'title': '',
    79                     'title': '',
    78                     'description': '',
    80                     'description': '',
    79                     'tags': [],
    81                     'fragment': '',
    80                     'annotation': null
    82                     'tags': []
    81                 });
    83                 });
    82             },
    84             },
    83             hasChanged: function() {
    85             hasChanged: function() {
    84                 if (!this.annotation) { return false; }
    86                 if (!this.annotation) { return false; }
    85 
    87