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 div = $("<div style='border: 1px solid white'/>");
34 div.append(data[i]['name'])
35 img.attr("src", data[i]['thumbnail_url']);
36 img.attr("title", data[i]['name']);
37 div.attr("data-output", 'file://' + data[i]['name']);
38 div.on('click', function() {
39 $("div", body).attr('style', 'border: 1px solid white');
40 $("div", body).removeClass('active');
41 $(this).attr('style', 'border: 1px solid black');
42 $(this).addClass('active');
46 var editlink = $("<a target='_blank'>" + gettext("Manage attachments") + "</a>");
47 editlink.attr('href', config.documentGalleryUrl);
48 body.append(editlink);
56 select: function(callback, params) {
57 return new attachmentLibrary(callback, params);