diff -r 20e00017dd60 -r 10974bff4dae web/res/metadataplayer/AnnotationsList.js --- a/web/res/metadataplayer/AnnotationsList.js Fri Dec 11 18:11:13 2015 +0100 +++ b/web/res/metadataplayer/AnnotationsList.js Tue Dec 29 13:25:14 2015 +0100 @@ -2,35 +2,105 @@ IriSP.Widgets.Widget.call(this, player, config); this.lastIds = []; var _this = this; - this.throttledRefresh = IriSP._.throttle(function() { - _this.refresh(false); + this.throttledRefresh = IriSP._.throttle(function(full) { + _this.refresh(full); }, 800); this.searchString = false; this.lastSearch = false; + this.localSource = undefined; }; IriSP.Widgets.AnnotationsList.prototype = new IriSP.Widgets.Widget(); IriSP.Widgets.AnnotationsList.prototype.defaults = { - /* URL when the annotations are to be reloaded from an LDT-like segment API - * e.g. http://ldt.iri.centrepompidou.fr/ldtplatform/api/ldt/segments/{{media}}/{{begin}}/{{end}}?callback=? + pre_draw_callback: function(){ + return this.importUsers(); + }, + /* + * URL when the annotations are to be reloaded from an LDT-like segment API + * e.g. + * http://ldt.iri.centrepompidou.fr/ldtplatform/api/ldt/segments/{{media}}/{{begin}}/{{end}}?callback=? */ ajax_url : false, - /* number of milliseconds before/after the current timecode when calling the segment API + /* + * number of milliseconds before/after the current timecode when calling the + * segment API */ - ajax_granularity : 600000, + ajax_granularity : 600000, default_thumbnail : "", - /* URL when the annotation is not in the current project, - * e.g. http://ldt.iri.centrepompidou.fr/ldtplatform/ldt/front/player/{{media}}/{{project}}/{{annotationType}}#id={{annotation}} + custom_external_icon : "", + /* + * URL when the annotation is not in the current project, e.g. + * http://ldt.iri.centrepompidou.fr/ldtplatform/ldt/front/player/{{media}}/{{project}}/{{annotationType}}#id={{annotation}} */ foreign_url : "", annotation_type : false, refresh_interval : 0, limit_count : 20, newest_first : false, + show_title: true, show_audio: true, - show_creator: false, + show_creator: true, show_controls: false, + show_end_time: true, + show_publish: false, + show_twitter: false, + twitter_hashtag: '', + // Callback for Edit action. Leave undefined for default action. + on_edit: undefined, + publish_type: "PublicContribution", + // Used to publish annotations + api_endpoint_template: "", + api_serializer: "ldt_annotate", + api_method: "POST", + editable: false, + // Id that will be used as localStorage key + editable_storage: "", + widget_max_height: 680, + always_visible : false, + start_visible: true, + show_audio : true, + show_filters : false, + keyword_filter: true, + date_filter: true, + user_filter: true, + segment_filter: true, + latest_contributions_filter: false, + current_day_filter: true, + show_header : false, + custom_header : false, + annotations_count_header : true, + annotations_count_header_string: "annotations", + show_creation_date : false, + show_timecode : true, + show_end_time : true, + project_id: "", + /* + * Only annotation in the current segment will be displayed. Designed to work with the Segments Widget. + */ + allow_annotations_deletion: false, + /* + * URL to call when deleting annotation. Expects a mustache template with {{annotation_id}}, ex /api/anotations/{{annotation_id}}/ + */ + api_delete_endpoint : "", + api_delete_method: "DELETE", + api_users_endpoint: "", + api_users_method: "GET", + make_name_string_function: function(params){ + return params.username ? params.username : "Anonymous"; + }, + filter_by_segments: false, + segment_filter: true, + segments_annotation_type: "chap", + /* + * Set to a username if you only want to display annotations from a given user + */ + show_only_annotation_from_user: false, + /* + * Show a text field that filter annotations by username + */ + tags : true, + polemics : [{ keyword: "++", background_color: "#c9ecc6" @@ -46,52 +116,179 @@ }] }; +IriSP.Widgets.AnnotationsList.prototype.importUsers = function(){ + if (!this.source.users_data && this.api_users_endpoint){ + this.usernames = Array(); + var _this = this, + _list = this.getWidgetAnnotations(), + usernames_list_string = ""; + + _list.forEach(function(_annotation){ + if(_this.usernames.indexOf(_annotation.creator) == -1){ + _this.usernames.push(_annotation.creator); + } + }); + this.usernames.forEach(function(_username){ + usernames_list_string+=_username+"," + }) + usernames_list_string = usernames_list_string.substring(0, usernames_list_string.length - 1); + _url = Mustache.to_html(this.api_users_endpoint, {usernames_list_string: encodeURIComponent(usernames_list_string), usernames_list_length: this.usernames.length}); + return IriSP.jQuery.ajax({ + async: false, + url: _url, + type: "GET", + success: function(_data) { + _this.source.users_data = _data.objects + }, + error: function(_xhr, _error, _thrown) { + console.log(_xhr) + console.log(_error) + console.log(_thrown) + } + }) + } +} + IriSP.Widgets.AnnotationsList.prototype.messages = { en: { voice_annotation: "Voice Annotation", - now_playing: "Now playing..." + now_playing: "Now playing...", + previous: "Previous", + next: "Next", + set_time: "Double-click to update to current player time", + edit_annotation: "Edit note", + delete_annotation: "Delete note", + publish_annotation: "Make note public", + import_annotations: "Paste or load notes in this field and press Import.", + confirm_delete_message: "You are about to delete {{ annotation.title }}. Are you sure you want to delete it?", + confirm_publish_message: "You are about to publish {{ annotation.title }}. Are you sure you want to make it public?", + tweet_annotation: "Tweet annotation", + external_annotation: "This annotation was submitted to another project", + everyone: "Everyone", + header: "Annotations for this content", + segment_filter: "All cuttings", + latest_contributions: "Latest contributions", + close_widget: "Close", + confirm: "Confirm", + cancel: "Cancel", + annotation_deletion_delete: "You will delete this annotation", + annotation_deletion_sending: "Your deletion request is being sent ... ", + annotation_deletion_success: "The annotation has been deleted.", + annotation_deletion_error: "There was an error contacting the server. The annotation has not been deleted." }, fr: { voice_annotation: "Annotation Vocale", - now_playing: "Lecture en cours..." + now_playing: "Lecture en cours...", + previous: "Précédent", + next: "Suivant", + set_time: "Double-cliquer pour fixer au temps du lecteur", + edit_annotation: "Éditer la note", + delete_annotation: "Supprimer la note", + publish_annotation: "Rendre la note publique", + import_annotations: "Copiez ou chargez des notes dans ce champ et appuyez sur Import", + confirm_delete_message: "Vous allez supprimer {{ annotation.title }}. Êtes-vous certain(e) ?", + confirm_publish_message: "Vous allez publier {{ annotation.title }}. Êtes-vous certain(e) ?", + tweet_annotation: "Tweeter l'annotation", + external_annotation: "Cette annotation a été postée sur un autre projet", + everyone: "Tous", + header: "Annotations sur ce contenu", + segment_filter: "Tous les segments", + latest_contributions: "Dernières contributions", + close_widget: "Fermer", + confirm: "Confirmer", + cancel: "Annuler", + annotation_deletion_delete: "Vous allez supprimer cette annotation", + annotation_deletion_sending: "Votre demande de suppression est en cours d'envoi ... ", + annotation_deletion_success: "L'annotation a été supprimée.", + annotation_deletion_error: "Une erreur s'est produite en contactant le serveur. L'annotation n'a pas été supprimée." } }; IriSP.Widgets.AnnotationsList.prototype.template = - '
' + + '{{#custom_header}}{{custom_header}}{{/custom_header}}' + + '{{^custom_header}}{{l10n.header}}{{/custom_header}}' + + '
{{/show_header}}' + + '{{{hdescription}}}
' + + '{{{hdescription}}}
' + + '{{#created}}' + + '