Datasets:

Modalities:
Text
Formats:
json
Languages:
code
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 9,229 Bytes
eb67da4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
if (typeof Omeka === 'undefined') {
    Omeka = {};
}

Omeka.Items = {};

(function ($) {
    /**
     * Enable drag and drop sorting for files.
     */
    Omeka.Items.enableSorting = function () {
        $('.sortable').sortable({
            items: 'li.file',
            forcePlaceholderSize: true, 
            forceHelperSize: true,
            revert: 200,
            placeholder: "ui-sortable-highlight",
            containment: 'document',
            update: function (event, ui) {
                $(this).find('.file-order').each(function (index) {
                    $(this).val(index + 1);
                });
            }
        });
        $( ".sortable" ).disableSelection();
        
        $( ".sortable input[type=checkbox]" ).each(function () {
            $(this).css("display", "none");
        });
    };

    /**
     * Make links to files open in a new window.
     */
    Omeka.Items.makeFileWindow = function () {
        $('#file-list a').click(function (event) {
            event.preventDefault();
            if($(this).hasClass("delete")) {
                Omeka.Items.enableFileDeletion($(this));
            } else {
                window.open(this.getAttribute('href'));
            }
        });
    };

    /**
     * Set up toggle for marking files for deletion. 
     */
    Omeka.Items.enableFileDeletion = function (deleteLink) {
        if( !deleteLink.next().is(":checked") ) {
            deleteLink.text("Undo").next().prop('checked', true).parents('.sortable-item').addClass("deleted");
        } else {
            deleteLink.text("Delete").next().prop('checked', false).parents('.sortable-item').removeClass("deleted");
        }
    };

    /**
     * Make the item type selector AJAX in the right item type form.
     *
     * @param {string} changeItemTypeUrl URL for getting form.
     * @param {string} itemId Item ID.
     */
    Omeka.Items.changeItemType = function (changeItemTypeUrl, itemId) {
        $('#change_type').hide();
        $('#item-type').change(function () {
            var params = {
                type_id: $(this).val()
            };
            if (itemId) {
                params.item_id = itemId;
            }
            $.ajax({
                url: changeItemTypeUrl,
                type: 'POST',
                dataType: 'html',
                data: params,
                success: function (response) {
                    var form = $('#type-metadata-form');
                    form.hide();
                    form.find('textarea').each(function () {
                        tinyMCE.EditorManager.execCommand('mceRemoveEditor', true, this.id);
                    });
                    form.html(response);
                    form.trigger('omeka:elementformload');
                    form.slideDown(1000, function () {
                        // Explicit show() call fixes IE7
                        $(this).show();
                    });
                }
            });
        });
    };

    /**
     * Add remove/undo buttons for removing a tag.
     *
     * @param {string} tag Tag to add buttons for.
     */
    Omeka.Items.addTagElement = function (tag) {
        var tagLi = $('<li/>');
        tagLi.after(" ");

        var undoButton = $('<span class="undo-remove-tag"><a href="#">Undo</a></span>').appendTo(tagLi);
        var deleteButton = $('<span class="remove-tag"><a href="#">Remove</a></span>').appendTo(tagLi);
        // BUG: CWE-79 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
        // tagLi.prepend('<span class="tag">' + tag + '</span>');
        // FIXED
        $('<span></span>', {'class': 'tag', 'text': tag}).appendTo(tagLi);

        if($('#all-tags-list').length != 0) {
            $('#all-tags-list').append(tagLi);
        } else {
            $('#all-tags').append($('<h3>All Tags</h3><div class="tag-list"><ul id="all-tags-list"></ul></div>'));
            $('#all-tags-list').append(tagLi);
        }

        Omeka.Items.updateTagsField();
        return false;
    };


    /**
     * Add tag elements for new tags from the input box.
     *
     * @param {string} tags Comma-separated tags to be added.
     */
    Omeka.Items.addTags = function (tags) {
        var newTags = tags.split(Omeka.Items.tagDelimiter);

        // only add tags from the input box that are new
        var oldTags = $('.tag-list .tag').map(function () {
            return $.trim(this.text);
        });

        $.each(newTags, function () {
            var tag = $.trim(this);
            if (tag && $.inArray(tag, oldTags) === -1) {
                Omeka.Items.addTagElement(tag);
            }
        });

        $('#tags').val('');
    };

    /**
     * Callback for tag remove buttons.
     *
     * @param {Element} button Clicked button.
     */
    Omeka.Items.toggleTag = function (button) {
        $(button).parent().toggleClass('tag-removed');
        Omeka.Items.updateTagsField();
    };

    /**
     * Update the hidden tags fields to only include the tags that have not been removed.
     */
    Omeka.Items.updateTagsField = function () {
        var tagsToAdd = [];
        var tagsToDelete = [];

        $('.tag-list li').each(function () {
            var tagSpan = $(this).find('.tag');
            var tag = $.trim(tagSpan.text());
            if ($(this).hasClass('tag-removed')) {
                tagsToDelete.push(tag);
            } else {
                tagsToAdd.push(tag);
            }
        });
        
        $('#tags-to-add').val(tagsToAdd.join(Omeka.Items.tagDelimiter));
        $('#tags-to-delete').val(tagsToDelete.join(Omeka.Items.tagDelimiter));
    };

    /**
     * Set up tag remove/undo buttons and adding from tags field.
     *
     */
    Omeka.Items.enableTagRemoval = function () {
        $('#add-tags-button').click(function (event) {
            event.preventDefault();
            Omeka.Items.addTags($('#tags').val());
        });

        $(document).on('click', 'span.remove-tag', function (event) {
            event.preventDefault();
            Omeka.Items.toggleTag(this);
        });

        $(document).on('click', 'span.undo-remove-tag', function (event) {
            event.preventDefault();
            Omeka.Items.toggleTag(this);
        });

    };

    /**
     * Set up autocomplete for tags field.
     *
     * @param {string} inputSelector Selector for input to autocomplete on.
     * @param {string} tagChoicesUrl Autocomplete JSON URL.
     */
    Omeka.Items.tagChoices = function (inputSelector, tagChoicesUrl) {
        function split(val) {
            var escapedTagDelimiter = Omeka.Items.tagDelimiter.replace(/([.?*+\^$\[\]\\(){}\-])/g, "\\$1");
            var re = new RegExp(escapedTagDelimiter + '\\s*');
            return val.split(re);
        }
        function extractLast(term) {
            return split(term).pop();
        }

        // Tokenized input based on
        // http://jqueryui.com/demos/autocomplete/multiple.html
        $(inputSelector).autocomplete({
            source: function (request, response) {
                $.getJSON(tagChoicesUrl, {
                    term: extractLast(request.term)
                }, function (data) {
                    response(data);
                });
            },
            focus: function () {
                return false;
            },
            select: function (event, ui) {
                var terms = split(this.value);
                // remove the current input
                terms.pop();
                // add the selected item
                terms.push(ui.item.value);
                // add placeholder to get the comma-and-space at the end
                terms.push('');
                this.value = terms.join(Omeka.Items.tagDelimiter + ' ');
                return false;
            }
        });
    };

    /**
     * Submit tag changes on items/show with AJAX.
     */
    Omeka.Items.modifyTagsShow = function () {
        //Add the tags with this request
        $('#tags-form').submit(function (event) {
            event.preventDefault();
            var form = $(this);
            $.post(form.attr('action'), form.serialize(), function (response) {
                $('#tag-cloud').hide().html(response).fadeIn(1000);
            }, 'html');
        });
    };

    /**
     * Allow adding an arbitrary number of file input elements to the items form so that
     * more than one file can be uploaded at once.
     *
     * @param {string} label
     */
    Omeka.Items.enableAddFiles = function (label) {
        var filesDiv = $('#files-metadata .files');

        var link = $('<a href="#" id="add-file" class="add-file button">' + label + '</a>');
        link.click(function (event) {
            event.preventDefault();
            var inputs = filesDiv.find('input');
            var inputCount = inputs.length;
            var fileHtml = '<input name="file[' + inputCount + ']" type="file"></div>';
            $(fileHtml).insertAfter(inputs.last()).hide().slideDown(200, function () {
                // Extra show fixes IE bug.
                $(this).show();
            });
        });

        $('#file-inputs').append(link);
    };
})(jQuery);