src_js/iconolab-bundle/src/components/editor/AnnotationForm.vue
author Alexandre Segura <mex.zktk@gmail.com>
Fri, 28 Apr 2017 11:38:44 +0200
changeset 483 dce041bc57a9
parent 482 b71475c27159
child 485 47080491b330
permissions -rw-r--r--
Fix null pointer.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     1
<template>
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
     2
    <div>
385
d0465086d8d2 Allow editing/commenting only for authenticated users.
Alexandre Segura <mex.zktk@gmail.com>
parents: 356
diff changeset
     3
        <button v-if="annotation && isAuthenticated" @click="readonly = !readonly"
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
     4
            class="btn btn-xs pull-right"
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
     5
            v-bind:class="{ 'btn-primary': readonly, 'btn-warning': !readonly }">
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
     6
            <i class="fa fa-edit" v-if="readonly"></i>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
     7
            <span v-if="readonly">Modifier</span>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
     8
            <i class="fa fa-ban" v-if="!readonly"></i>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
     9
            <span v-if="!readonly">Annuler</span>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    10
        </button>
356
a45f7dac4789 Change wordings, align text.
Alexandre Segura <mex.zktk@gmail.com>
parents: 351
diff changeset
    11
        <div v-if="!annotation" class="alert alert-warning text-center">
433
616fc1fad25f Toggle annotation on click.
Alexandre Segura <mex.zktk@gmail.com>
parents: 427
diff changeset
    12
            Aucune annotation sélectionnée
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    13
        </div>
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    14
        <form v-bind:action="formAction" method="post">
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    15
            <slot>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    16
                <!-- CSRF token -->
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    17
            </slot>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    18
            <input type="hidden" name="fragment" v-model="fragment">
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    19
            <div v-if="annotation" class="form-group form-group-sm">
402
376158f6d760 hides title and description if there is none
duong tam kien <tk@deveha.com>
parents: 400
diff changeset
    20
                <label v-if="!readonly || title" class="small text-muted">Titre</label>
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    21
                <input type="text" class="form-control" name="title" v-model="title" v-if="!readonly">
402
376158f6d760 hides title and description if there is none
duong tam kien <tk@deveha.com>
parents: 400
diff changeset
    22
                <p v-if="readonly && title" v-bind:class="{ 'text-muted': !title }">{{ title || 'Pas de titre' }}</p>
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    23
            </div>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    24
            <div v-if="annotation" class="form-group form-group-sm">
402
376158f6d760 hides title and description if there is none
duong tam kien <tk@deveha.com>
parents: 400
diff changeset
    25
                <label v-if="!readonly || description" class="small text-muted">Description</label>
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    26
                <textarea class="form-control" name="description" v-model="description" v-if="!readonly" placeholder="Décrivez ce que vous voyez"></textarea>
403
0ed5207089ee adds formatting (markdown) to annotation description
duong tam kien <tk@deveha.com>
parents: 402
diff changeset
    27
                <p v-if="readonly && description" v-bind:class="{ 'text-muted': !description }" v-html="descriptionComputed">{{ descriptionComputed || 'Pas de description' }}</p>
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    28
            </div>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    29
            <div v-if="annotation" class="form-group form-group-sm">
400
c85505149eea orthographe mots-cléS + css
duong tam kien <tk@deveha.com>
parents: 385
diff changeset
    30
                <label class="small text-muted">Mots-clés</label>
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    31
                <tag-list ref="taglist"
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    32
                    v-bind:original-tags="annotation.tags"
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    33
                    v-bind:readonly="readonly"
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    34
                    @change="onTagsChange($event.tags)"></tag-list>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    35
                <input type="hidden" name="tags" v-model="serializedTags">
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    36
            </div>
483
dce041bc57a9 Fix null pointer.
Alexandre Segura <mex.zktk@gmail.com>
parents: 482
diff changeset
    37
            <p class="small text-center text-muted" v-if="annotation">
482
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
    38
                <a v-bind:href="revisionsUrlComputed">Dernière version</a>
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
    39
                <span>{{ dateComputed }} par</span>
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
    40
                <a v-bind:href="authorUrlComputed">{{ annotation.author }}</a>
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
    41
            </p>
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    42
            <button type="submit" v-if="annotation &amp;&amp; !readonly" v-bind:class="{ disabled: !hasChanged }"
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    43
                class="btn btn-block btn-sm btn-primary">Enregistrer une nouvelle version</button>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    44
        </form>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    45
    </div>
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    46
</template>
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    47
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    48
<script>
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    49
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    50
    import TagList from '../tagform/TagList.vue'
333
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
    51
    import _ from 'lodash'
403
0ed5207089ee adds formatting (markdown) to annotation description
duong tam kien <tk@deveha.com>
parents: 402
diff changeset
    52
    import showdown from 'showdown'
427
2a9ce7ec3a29 Display date & author of last revision.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    53
    import moment from 'moment'
403
0ed5207089ee adds formatting (markdown) to annotation description
duong tam kien <tk@deveha.com>
parents: 402
diff changeset
    54
0ed5207089ee adds formatting (markdown) to annotation description
duong tam kien <tk@deveha.com>
parents: 402
diff changeset
    55
    const converter = new showdown.Converter()
333
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
    56
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
    57
    var defaults = {
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    58
        title: '',
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    59
        description: '',
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    60
        fragment: '',
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    61
        tags: [],
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    62
        readonly: true,
333
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
    63
    }
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    64
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    65
    export default {
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    66
        props: {
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    67
            action: String,
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    68
            annotation: {
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    69
                type: Object,
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    70
                default: function () {
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    71
                    return null;
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    72
                }
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    73
            },
385
d0465086d8d2 Allow editing/commenting only for authenticated users.
Alexandre Segura <mex.zktk@gmail.com>
parents: 356
diff changeset
    74
            isAuthenticated: {
d0465086d8d2 Allow editing/commenting only for authenticated users.
Alexandre Segura <mex.zktk@gmail.com>
parents: 356
diff changeset
    75
                type: Boolean,
d0465086d8d2 Allow editing/commenting only for authenticated users.
Alexandre Segura <mex.zktk@gmail.com>
parents: 356
diff changeset
    76
                default: false
482
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
    77
            },
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
    78
            revisionsUrl: String,
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
    79
            authorUrl: String
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    80
        },
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    81
        components: {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    82
            'tag-list': TagList
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    83
        },
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    84
        data() {
333
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
    85
            return defaults;
325
8f158a4c7759 Use props to update annotation in components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 323
diff changeset
    86
        },
418
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
    87
        mounted() {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
    88
            if (this.annotation) {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
    89
                this.loadAnnotation(this.annotation);
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
    90
            }
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
    91
        },
325
8f158a4c7759 Use props to update annotation in components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 323
diff changeset
    92
        watch: {
8f158a4c7759 Use props to update annotation in components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 323
diff changeset
    93
            annotation: function(annotation) {
8f158a4c7759 Use props to update annotation in components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 323
diff changeset
    94
                if (annotation) {
418
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
    95
                    this.loadAnnotation(annotation);
325
8f158a4c7759 Use props to update annotation in components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 323
diff changeset
    96
                } else {
8f158a4c7759 Use props to update annotation in components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 323
diff changeset
    97
                    this.reset();
8f158a4c7759 Use props to update annotation in components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 323
diff changeset
    98
                }
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    99
            }
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   100
        },
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   101
        computed: {
427
2a9ce7ec3a29 Display date & author of last revision.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   102
            descriptionComputed: function() {
403
0ed5207089ee adds formatting (markdown) to annotation description
duong tam kien <tk@deveha.com>
parents: 402
diff changeset
   103
              return converter.makeHtml(this.description);
0ed5207089ee adds formatting (markdown) to annotation description
duong tam kien <tk@deveha.com>
parents: 402
diff changeset
   104
            },
427
2a9ce7ec3a29 Display date & author of last revision.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   105
            lastRevisionText: function() {
2a9ce7ec3a29 Display date & author of last revision.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   106
                if (this.annotation) {
2a9ce7ec3a29 Display date & author of last revision.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   107
                    var date = moment(this.annotation.created).locale('fr');
2a9ce7ec3a29 Display date & author of last revision.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   108
                    return 'Dernière version ' + date.fromNow() + ' par ' + this.annotation.author;
2a9ce7ec3a29 Display date & author of last revision.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   109
                }
2a9ce7ec3a29 Display date & author of last revision.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   110
            },
482
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   111
            revisionsUrlComputed: function() {
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   112
                if (this.annotation) {
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   113
                    return this.revisionsUrl.replace(':annotation_guid', this.annotation.annotation_guid);
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   114
                }
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   115
            },
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   116
            authorUrlComputed: function() {
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   117
                if (this.annotation) {
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   118
                    return this.authorUrl.replace('--username--', this.annotation.author);
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   119
                }
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   120
            },
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   121
            dateComputed: function() {
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   122
                if (this.annotation) {
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   123
                    return moment(this.annotation.created).locale('fr').fromNow();
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   124
                }
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   125
            },
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   126
            formAction: function() {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   127
                if (this.annotation) {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   128
                    return this.action.replace(':annotation_guid', this.annotation.annotation_guid);
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   129
                }
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   130
            },
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   131
            serializedTags: function() {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   132
                var tags = this.tags.map(function(tag) {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   133
                    return {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   134
                        tag_input: (typeof tag.tag_link === "string" && tag.tag_link.length) ? tag.tag_link : tag.tag_label,
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   135
                        tag_label: tag.tag_label,
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   136
                        accuracy: tag.accuracy,
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   137
                        relevancy: tag.relevancy
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   138
                    }
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   139
                });
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   140
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   141
                return JSON.stringify(tags);
333
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
   142
            },
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
   143
            hasChanged: function() {
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
   144
                if (!this.annotation) { return false; }
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
   145
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
   146
                return this.title !== this.annotation.title
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
   147
                    || this.description !== this.annotation.description
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
   148
                    || !_.isEqual(this.annotation.tags, this.tags);
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   149
            }
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   150
        },
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   151
        methods: {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   152
            onTagsChange: function(tags) {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   153
                this.tags = tags;
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   154
            },
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   155
            reset: function() {
333
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
   156
                Object.assign(this, defaults);
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   157
            },
418
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   158
            loadAnnotation(annotation) {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   159
                // Make sure we have an actual copy
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   160
                Object.assign(this, {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   161
                    title: annotation.title,
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   162
                    description: annotation.description,
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   163
                    fragment: annotation.fragment,
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   164
                    tags: annotation.tags.slice(),
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   165
                    readonly: true,
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   166
                });
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   167
            }
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   168
        }
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   169
    }
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   170
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   171
</script>
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   172
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   173
<style scoped>
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   174
form {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   175
    margin-bottom: 20px;
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
   176
    clear: both;
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   177
}
400
c85505149eea orthographe mots-cléS + css
duong tam kien <tk@deveha.com>
parents: 385
diff changeset
   178
c85505149eea orthographe mots-cléS + css
duong tam kien <tk@deveha.com>
parents: 385
diff changeset
   179
label {
c85505149eea orthographe mots-cléS + css
duong tam kien <tk@deveha.com>
parents: 385
diff changeset
   180
  font-weight: normal;
c85505149eea orthographe mots-cléS + css
duong tam kien <tk@deveha.com>
parents: 385
diff changeset
   181
}
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   182
</style>