1 define(function(require) {
5 var $ = require('libs/jquery'),
6 Dialog = require('views/dialog/dialog');
10 // Move it somewhere else.
11 var attachmentLibrary = function(callback, params) {
12 var dialog = Dialog.create({
13 title: gettext('Attachment library'),
14 executeButtonText: gettext('Select'),
15 cancelButtonText: gettext('Cancel'),
20 dialog.on('execute', function(event) {
21 callback($(".active", dialog.$el).attr('data-output'));
26 var body = $(".modal-body", dialog.$el);
27 $.ajax(config.documentGalleryUrl, {
29 success: function(data, status, jqxhr) {
31 var img = $("<img style='margin-right: 1em'>");
32 var input = $("<input type='radio' name='attachment'>");
33 var label = $("<label/>");
34 var div = $("<div style='border: 1px solid white'/>");
37 label.append(data[i]['name']);
38 img.attr("src", data[i]['thumbnail_url']);
39 img.attr("title", data[i]['name']);
40 input.attr('id', 'attachment' + i);
41 label.attr('for', 'attachment' + i);
43 div.attr("data-output", 'file://' + data[i]['name']);
44 div.on('click', function() {
45 $("div.active", body).removeClass('active');
46 $(this).addClass('active');
50 var editlink = $("<a target='_blank'>" + gettext("Manage attachments") + "</a>");
51 editlink.attr('href', config.documentGalleryUrl);
52 body.append(editlink);
60 select: function(callback, params) {
61 return new attachmentLibrary(callback, params);