note.js 1.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
(function(define) {
    'use strict';
    define(['backbone', 'js/edxnotes/utils/utils', 'underscore.string'], function(Backbone, Utils, str) {
        var NoteModel = Backbone.Model.extend({
            defaults: {
                'id': null,
                'created': '',
                'updated': '',
                'user': '',
                'usage_id': '',
                'course_id': '',
                'text': '',
                'quote': '',
                'ranges': [],
                'tags': [],
                'unit': {
                    'display_name': '',
                    'url': '',
                    'location': ''
                },
                'section': {
                    'display_name': '',
                    'location': '',
                    'children': []
                },
                'chapter': {
                    'display_name': '',
                    'location': '',
                    'index': 0,
                    'children': []
                },
32
            // Flag indicating current state of the note: expanded or collapsed.
33
                'is_expanded': false,
34
            // Flag indicating whether `More` link should be shown.
35 36
                'show_link': false
            },
37

38
            textSize: 300,
39

40 41 42 43 44
            initialize: function() {
                if (this.get('quote').length > this.textSize) {
                    this.set('show_link', true);
                }
            },
45

46 47
            getQuote: function() {
                var message = this.get('quote');
48

49 50 51 52 53
                if (!this.get('is_expanded') && this.get('show_link')) {
                    message = str.prune(message, this.textSize);
                }

                return message;
54 55
            }

56
        });
57

58
        return NoteModel;
59 60
    });
}).call(this, define || RequireJS.define);