src_js/iconolab-bundle/src/components/editor/AnnotationForm.vue
author Alexandre Segura <mex.zktk@gmail.com>
Tue, 16 May 2017 11:29:33 +0200
changeset 504 11a862e01b04
parent 485 47080491b330
child 539 08e2513dbc2f
permissions -rw-r--r--
Implement annotation on the whole picture.
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>
485
47080491b330 Add intro.js for on boarding.
Alexandre Segura <mex.zktk@gmail.com>
parents: 483
diff changeset
     3
        <button
47080491b330 Add intro.js for on boarding.
Alexandre Segura <mex.zktk@gmail.com>
parents: 483
diff changeset
     4
            data-intro="Proposez une nouvelle version" data-position="left"
504
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
     5
            v-if="annotation && isAuthenticated"
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
     6
            @click="onCancelClick"
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
     7
            class="btn btn-xs pull-right"
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
     8
            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
     9
            <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
    10
            <span v-if="readonly">Modifier</span>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    11
            <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
    12
            <span v-if="!readonly">Annuler</span>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    13
        </button>
356
a45f7dac4789 Change wordings, align text.
Alexandre Segura <mex.zktk@gmail.com>
parents: 351
diff changeset
    14
        <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
    15
            Aucune annotation sélectionnée
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    16
        </div>
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    17
        <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
    18
            <slot>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    19
                <!-- CSRF token -->
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    20
            </slot>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    21
            <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
    22
            <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
    23
                <label v-if="!readonly || title" class="small text-muted">Titre</label>
504
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
    24
                <input type="text" class="form-control" name="title" v-model="title" v-if="!readonly" ref="title">
402
376158f6d760 hides title and description if there is none
duong tam kien <tk@deveha.com>
parents: 400
diff changeset
    25
                <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
    26
            </div>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    27
            <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
    28
                <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
    29
                <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
    30
                <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
    31
            </div>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    32
            <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
    33
                <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
    34
                <tag-list ref="taglist"
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    35
                    v-bind:original-tags="annotation.tags"
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    36
                    v-bind:readonly="readonly"
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    37
                    @change="onTagsChange($event.tags)"></tag-list>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    38
                <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
    39
            </div>
504
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
    40
            <p class="small text-center text-muted" v-if="annotation && annotation.annotation_guid">
482
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
    41
                <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
    42
                <span>{{ dateComputed }} par</span>
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
    43
                <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
    44
            </p>
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    45
            <button type="submit" v-if="annotation &amp;&amp; !readonly" v-bind:class="{ disabled: !hasChanged }"
504
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
    46
                class="btn btn-block btn-sm btn-primary">{{ submitButtonText }}</button>
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    47
        </form>
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    48
    </div>
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    49
</template>
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    50
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    51
<script>
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    52
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    53
    import TagList from '../tagform/TagList.vue'
333
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
    54
    import _ from 'lodash'
403
0ed5207089ee adds formatting (markdown) to annotation description
duong tam kien <tk@deveha.com>
parents: 402
diff changeset
    55
    import showdown from 'showdown'
427
2a9ce7ec3a29 Display date & author of last revision.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
    56
    import moment from 'moment'
403
0ed5207089ee adds formatting (markdown) to annotation description
duong tam kien <tk@deveha.com>
parents: 402
diff changeset
    57
0ed5207089ee adds formatting (markdown) to annotation description
duong tam kien <tk@deveha.com>
parents: 402
diff changeset
    58
    const converter = new showdown.Converter()
333
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
    59
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
    60
    var defaults = {
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    61
        title: '',
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    62
        description: '',
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    63
        fragment: '',
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    64
        tags: [],
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    65
        readonly: true,
333
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
    66
    }
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    67
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    68
    export default {
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    69
        props: {
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    70
            annotation: {
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    71
                type: Object,
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    72
                default: function () {
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    73
                    return null;
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    74
                }
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    75
            },
385
d0465086d8d2 Allow editing/commenting only for authenticated users.
Alexandre Segura <mex.zktk@gmail.com>
parents: 356
diff changeset
    76
            isAuthenticated: {
d0465086d8d2 Allow editing/commenting only for authenticated users.
Alexandre Segura <mex.zktk@gmail.com>
parents: 356
diff changeset
    77
                type: Boolean,
d0465086d8d2 Allow editing/commenting only for authenticated users.
Alexandre Segura <mex.zktk@gmail.com>
parents: 356
diff changeset
    78
                default: false
482
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
    79
            },
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
    80
            revisionsUrl: String,
504
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
    81
            authorUrl: String,
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
    82
            newAnnotationUrl: String,
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
    83
            editAnnotationUrl: String
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
    84
        },
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    85
        components: {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    86
            'tag-list': TagList
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    87
        },
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    88
        data() {
333
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
    89
            return defaults;
325
8f158a4c7759 Use props to update annotation in components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 323
diff changeset
    90
        },
418
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
    91
        mounted() {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
    92
            if (this.annotation) {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
    93
                this.loadAnnotation(this.annotation);
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
    94
            }
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
    95
        },
325
8f158a4c7759 Use props to update annotation in components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 323
diff changeset
    96
        watch: {
8f158a4c7759 Use props to update annotation in components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 323
diff changeset
    97
            annotation: function(annotation) {
8f158a4c7759 Use props to update annotation in components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 323
diff changeset
    98
                if (annotation) {
418
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
    99
                    this.loadAnnotation(annotation);
325
8f158a4c7759 Use props to update annotation in components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 323
diff changeset
   100
                } else {
8f158a4c7759 Use props to update annotation in components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 323
diff changeset
   101
                    this.reset();
8f158a4c7759 Use props to update annotation in components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 323
diff changeset
   102
                }
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   103
            }
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   104
        },
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   105
        computed: {
427
2a9ce7ec3a29 Display date & author of last revision.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   106
            descriptionComputed: function() {
403
0ed5207089ee adds formatting (markdown) to annotation description
duong tam kien <tk@deveha.com>
parents: 402
diff changeset
   107
              return converter.makeHtml(this.description);
0ed5207089ee adds formatting (markdown) to annotation description
duong tam kien <tk@deveha.com>
parents: 402
diff changeset
   108
            },
427
2a9ce7ec3a29 Display date & author of last revision.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   109
            lastRevisionText: function() {
2a9ce7ec3a29 Display date & author of last revision.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   110
                if (this.annotation) {
2a9ce7ec3a29 Display date & author of last revision.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   111
                    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
   112
                    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
   113
                }
2a9ce7ec3a29 Display date & author of last revision.
Alexandre Segura <mex.zktk@gmail.com>
parents: 418
diff changeset
   114
            },
482
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   115
            revisionsUrlComputed: function() {
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   116
                if (this.annotation) {
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   117
                    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
   118
                }
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
            authorUrlComputed: function() {
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   121
                if (this.annotation) {
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   122
                    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
   123
                }
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
            dateComputed: function() {
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   126
                if (this.annotation) {
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   127
                    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
   128
                }
b71475c27159 Add page with list of revisions.
Alexandre Segura <mex.zktk@gmail.com>
parents: 433
diff changeset
   129
            },
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   130
            formAction: function() {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   131
                if (this.annotation) {
504
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   132
                    if (this.annotation.annotation_guid) {
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   133
                        return this.editAnnotationUrl.replace(':annotation_guid', this.annotation.annotation_guid);
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   134
                    }
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   135
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   136
                    return this.newAnnotationUrl
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   137
                }
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   138
            },
504
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   139
            submitButtonText: function() {
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   140
                return this.isNewAnnotation ? 'Enregistrer' : 'Enregister une nouvelle version'
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   141
            },
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   142
            isNewAnnotation: function() {
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   143
                return this.annotation && !this.annotation.annotation_guid
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   144
            },
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   145
            serializedTags: function() {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   146
                var tags = this.tags.map(function(tag) {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   147
                    return {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   148
                        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
   149
                        tag_label: tag.tag_label,
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   150
                        accuracy: tag.accuracy,
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   151
                        relevancy: tag.relevancy
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   152
                    }
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   153
                });
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
                return JSON.stringify(tags);
333
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
   156
            },
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
   157
            hasChanged: function() {
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
   158
                if (!this.annotation) { return false; }
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
   159
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
   160
                return this.title !== this.annotation.title
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
   161
                    || this.description !== this.annotation.description
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
   162
                    || !_.isEqual(this.annotation.tags, this.tags);
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   163
            }
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   164
        },
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   165
        methods: {
504
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   166
            onCancelClick: function() {
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   167
                if (this.isNewAnnotation) {
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   168
                    this.$emit('close')
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   169
                } else {
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   170
                    this.readonly = !this.readonly
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   171
                }
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   172
            },
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   173
            onTagsChange: function(tags) {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   174
                this.tags = tags;
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   175
            },
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   176
            reset: function() {
333
625ac8b8bb87 Improve change detection in TagList.
Alexandre Segura <mex.zktk@gmail.com>
parents: 327
diff changeset
   177
                Object.assign(this, defaults);
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   178
            },
418
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   179
            loadAnnotation(annotation) {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   180
                // 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
   181
                Object.assign(this, {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   182
                    title: annotation.title,
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   183
                    description: annotation.description,
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   184
                    fragment: annotation.fragment,
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   185
                    tags: annotation.tags.slice(),
504
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   186
                    readonly: !this.isNewAnnotation,
418
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   187
                });
504
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   188
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   189
                if (!annotation.annotation_guid) {
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   190
                    setTimeout(() => {
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   191
                        $(this.$refs.title).focus()
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   192
                    }, 500);
11a862e01b04 Implement annotation on the whole picture.
Alexandre Segura <mex.zktk@gmail.com>
parents: 485
diff changeset
   193
                }
418
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents: 403
diff changeset
   194
            }
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   195
        }
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   196
    }
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   197
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   198
</script>
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   199
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   200
<style scoped>
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   201
form {
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   202
    margin-bottom: 20px;
339
ba89f767b091 Introduce readonly prop in AnnotationForm & child components.
Alexandre Segura <mex.zktk@gmail.com>
parents: 333
diff changeset
   203
    clear: both;
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   204
}
400
c85505149eea orthographe mots-cléS + css
duong tam kien <tk@deveha.com>
parents: 385
diff changeset
   205
c85505149eea orthographe mots-cléS + css
duong tam kien <tk@deveha.com>
parents: 385
diff changeset
   206
label {
c85505149eea orthographe mots-cléS + css
duong tam kien <tk@deveha.com>
parents: 385
diff changeset
   207
  font-weight: normal;
c85505149eea orthographe mots-cléS + css
duong tam kien <tk@deveha.com>
parents: 385
diff changeset
   208
}
323
55c024fc7c60 Roughly implement annotation navigator.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   209
</style>