videoannotation.html 7.88 KB
Newer Older
daniel cebrian committed
1
<%! from django.utils.translation import ugettext as _ %>
2
<%namespace name='static' file='/static_content.html'/>
3 4
${static.css(group='style-vendor-tinymce-content', raw=True)}
${static.css(group='style-vendor-tinymce-skin', raw=True)}
5
${static.css(group='style-xmodule-annotations', raw=True)}
daniel cebrian committed
6 7 8 9

<div class="annotatable-wrapper">
	<div class="annotatable-header">
		% if display_name is not UNDEFINED and display_name is not None:
10
			<h3 class="hd hd-2 annotatable-title">${display_name}</h3>
daniel cebrian committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
		% endif
	</div>
	% if instructions_html is not UNDEFINED and instructions_html is not None:
	<div class="annotatable-section shaded">
		<div class="annotatable-section-title">
		    ${_('Instructions')}
		    <a class="annotatable-toggle annotatable-toggle-instructions expanded" href="javascript:void(0)">${_('Collapse Instructions')}</a>
		</div>
		<div class="annotatable-section-body annotatable-instructions">
		    ${instructions_html}
		</div>
	</div>
	% endif
	<div class="annotatable-section">
		<div class="annotatable-content">
		    <div id="videoHolder">
				<video id="vid1" class="video-js vjs-default-skin" controls preload="none" width="640" height="264" poster="${poster}">
					<source src="${sourceUrl}" type='${typeSource}' />
				</video>
30
			</div>
daniel cebrian committed
31 32 33 34 35 36
			<div id="catchDIV">
				<div class="annotationListContainer">${_('You do not have any notes.')}</div>
			</div>
		</div>
	</div>
</div>
37

daniel cebrian committed
38
<script>
39 40 41 42
// TODO: Fix indentation in the following block
(function (require) {
    var init = function() {
    function onClickHideInstructions(){
daniel cebrian committed
43 44 45 46 47 48 49 50 51 52 53 54
		//Reset function if there is more than one event handler
		$(this).off();
		$(this).on('click',onClickHideInstructions);
		var hide = $(this).html()=='Collapse Instructions'?true:false,
			cls, txt,slideMethod;
		txt = (hide ? 'Expand' : 'Collapse') + ' Instructions';
		cls = (hide ? ['expanded', 'collapsed'] : ['collapsed', 'expanded']);
		slideMethod = (hide ? 'slideUp' : 'slideDown');
		$(this).text(txt).removeClass(cls[0]).addClass(cls[1]);
		$(this).parents('.annotatable-section:first').find('.annotatable-instructions')[slideMethod]();
	}
	$('.annotatable-toggle-instructions').on('click', onClickHideInstructions);
55

daniel cebrian committed
56
	//Grab uri of the course
57
    var parts = window.location.href.split("/"),
58
    	uri = '';
daniel cebrian committed
59 60 61 62 63 64 65
	for (var index = 0; index <= 9; index += 1) uri += parts[index]+"/"; //Get the unit url
	//Change uri in cms
	var lms_location = $('.sidebar .preview-button').attr('href');
	if (typeof lms_location!='undefined'){
		uri = window.location.protocol;
		for (var index = 0; index <= 9; index += 1) uri += lms_location.split("/")[index]+"/"; //Get the unit url
	}
66 67
	var unit_id = $('#sequence-list').find('.active').attr("data-element");
    uri += unit_id;
daniel cebrian committed
68
	var pagination = 100,
69
	 is_staff = '${is_course_staff}' === 'True',
daniel cebrian committed
70 71 72 73
        options = {
        optionsAnnotator: {
            permissions:{
                user: {
74
                    id:"${user.email}",
daniel cebrian committed
75 76 77
                    name:"${user.username}"
                },
                userString: function (user) {
78
                    if (user && user.name)
daniel cebrian committed
79 80 81 82
                        return user.name;
                    return user;
                },
                userId: function (user) {
83
                    if (user && user.id)
daniel cebrian committed
84 85 86 87 88 89 90 91 92
                        return user.id;
                    return user;
                },
                permissions: {
                        'read':   [],
                        'update': ["${user.email}"],
                        'delete': ["${user.email}"],
                        'admin':  ["${user.email}"]
                },
93
                showViewPermissionsCheckbox: false,
daniel cebrian committed
94 95 96 97 98 99 100 101 102 103 104 105 106
                showEditPermissionsCheckbox: false,
                userAuthorize: function(action, annotation, user) {
                    var token, tokens, _i, _len;
                    if (annotation.permissions) {
                      tokens = annotation.permissions[action] || [];
                      if (is_staff){
                      	return true;
                      }
                      if (tokens.length === 0) {
                        return true;
                      }
                      for (_i = 0, _len = tokens.length; _i < _len; _i++) {
                        token = tokens[_i];
107

daniel cebrian committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
                        if (this.userId(user) === token) {

                          return true;
                        }
                      }

                      return false;
                    } else if (annotation.user) {
                      if (user) {
                        return this.userId(user) === this.userId(annotation.user);
                      } else {
                        return false;
                      }
                    }
                    return true;
                  },
            },
            auth: {
126
                token: "${token}"
daniel cebrian committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
            },
            store: {
                // The endpoint of the store on your server.
                prefix: "${annotation_storage}",

                annotationData: {
                    uri: uri,

                },

                urls: {
                    // These are the default URLs.
                    create:  '/create',
                    read:    '/read/:id',
                    update:  '/update/:id',
                    destroy: '/delete/:id',
                    search:  '/search'
                },

                loadFromSearch:{
                    limit:pagination,
                    offset:0,
                    uri:uri,
                    media:'video',
		    userid:'${user.email}',
                }
            },
        },
        optionsVideoJS: {techOrder: ["html5","flash","youtube"]},
        optionsRS: {},
        optionsOVA: {posBigNew:'none'},
        optionsRichText: {
            tinymce:{
                selector: "li.annotator-item textarea",
161
                plugins: "media image codemirror",
daniel cebrian committed
162 163 164
                menubar: false,
                toolbar_items_size: 'small',
                extended_valid_elements : "iframe[src|frameborder|style|scrolling|class|width|height|name|align|id]",
165
                toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | image rubric | code ",
daniel cebrian committed
166 167 168
            }
        },
    };
169

daniel cebrian committed
170
	var imgURLRoot = "${settings.STATIC_URL}" + "js/vendor/ova/catch/img/";
171
    var ova, Catch, annotator, catchOptions;
172 173 174 175 176 177 178
    var startova = function() {
    	//remove old instances
        if (Annotator._instances.length !== 0) {
          $('#videoHolder').annotator("destroy");
        }
        delete ova;
        //Load the plugin Video/Text Annotation
179
        ova = new OpenVideoAnnotation.Annotator($('#videoHolder'),options);
180

181 182 183 184 185
        // TODO: Fix to avoid using global scope!
        window.options = options;
        window.ova = ova;
        // END TODO

186
        ova.annotator.addPlugin('Tags');
187
        var userId = ('${default_tab}'.toLowerCase() === 'instructor') ?
188 189
                '${instructor_email}':
                '${user.email}';
190

191
        //Catch
192 193
        annotator = ova.annotator;
        catchOptions = {
194 195 196 197 198 199 200 201 202 203 204 205
                media:'video',
                externalLink:false,
                imageUrlRoot:imgURLRoot,
                showMediaSelector: false,
                showPublicPrivate: true,
    	        userId:userId,
                pagination:pagination,//Number of Annotations per load in the pagination,
                flags:is_staff,
                default_tab: "${default_tab}",
                instructor_email: "${instructor_email}",
                annotation_mode: "${annotation_mode}",
            };
206
        Catch = new CatchAnnotation($('#catchDIV'),catchOptions);
207 208 209
        // TODO: Fix to avoid using global scope!
        window.Catch = Catch;
        // END TODO
210
    }
211 212 213 214 215 216 217

    startova();
    };
    try {
        require(["ova"], init);
    } catch(error) {
        console.log("Error: " + error.message + " - Annotator not loaded in LMS.");
218
    }
219
}).call(this, require || RequireJS.require);
daniel cebrian committed
220
</script>