-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageBrowser.js
151 lines (124 loc) · 4.63 KB
/
ImageBrowser.js
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
dojo.provide('unc.ImageBrowser');
dojo.require('dijit._Widget');
dojo.require('dijit._Templated');
dojo.require('dojox.image.ThumbnailPicker');
dojo.require('dojox.image.Lightbox');
dojo.require('unc.ImageUpload');
function formatTags(tags) {
return tags.join(' ');
}
function formatTime(t) {
return t.toFixed(2);
}
dojo.declare('unc.ImageBrowser', [ dijit._Widget, dijit._Templated ], {
templatePath: dojo.moduleUrl("unc", "ImageBrowser.html"),
widgetsInTemplate: true,
url: '',
selected: '',
uploadDialog: null,
postCreate: function() {
this.inherited(arguments);
uow.getDatabase({
database: 'Media',
collection: 'Image',
mode: 'r'
}).then(dojo.hitch(this, function(db) {
this.grid = new dojox.grid.DataGrid({
store: db,
structure: [{
name: 'Tags',
field: 'tags',
formatter: formatTags,
width: 'auto'
}, {
name: 'Width',
field: 'width',
width: '5em'
}, {
name: 'Height',
field: 'height',
width: '5em'
}
]},
this.gridGoesHere);
this.grid.startup();
this.connect(this.grid, 'onSelected', 'lightSelect');
this.connect(this.grid, 'onRowDblClick', 'hardSelect');
this.connect(this.query, 'onKeyDown', function(e) {
if (e.keyCode == dojo.keys.ENTER) {
this.grid.setQuery({ tags: { '$all': this.query.attr('value').split(' ') }});
}
});
//setup gallery
// var picker = new dojox.image.ThumbnailPicker({
// numberThumbs: 4,
// isClickable: true,
// thumbHeight: 150,
// thumbWidth:150
// });
// var request= {start:0};
//
// var itemNameMap = {imageLargeAttr: "URL",
// imageThumbAttr: "URL"};
//
// picker.setDataStore(db, request, itemNameMap);
// dojo.place(picker.domNode, this.at_picker);
// console.log("The picker", picker);
// picker.startup();
//
// dojo.subscribe(picker.getClickTopicName(), function(packet) {
//
// console.log(packet);
// var dialog = new dojox.image.LightboxDialog({});
// dialog.startup();
// dialog.show({ title:packet.title, href:packet.largeUrl });
//
// });
//
// //query connect
// this.connect(this.query, 'onKeyDown', function(e) {
// if (e.keyCode == dojo.keys.ENTER) {
// this.grid.setQuery({ tags: { '$all': this.query.attr('value').split(' ') }});
// }
// });
this.connect(this.select, 'onClick', this.imageSelected);
this.connect(this.upload, 'onClick', this.uploadImage);
}));
},
lightSelect: function(idx) {
this.selected = this.grid.getItem(idx);
console.log("selected ", this.selected);
},
hardSelect: function(evt) {
var selection = this.grid.selection.getSelected();
console.log("selected ", this.selected);
this.selected = selection[0];
this.previewImage(this.selected.URL);
},
previewImage: function(url) {
var dialog = new dojox.image.LightboxDialog({});
dialog.startup();
dialog.show({ title:this.selected.title, href:url });
},
imageSelected: function() {
return this.selected;
},
uploadImage: function() {
var theUploader = new unc.ImageUpload();
console.log("The uploader:", theUploader);
var dialog = new dijit.Dialog({
title: "Upload an image!",
content: [theUploader.domNode]
});
dojo.subscribe('close uploader', dojo.hitch(this, function() {
dialog.connect(dialog._fadeOut, 'onEnd', function() {
this.destroyRecursive();
});
dialog.hide();
//dialog.destroy(); //Recursive(); //for some reason the destroy causes the modality problem.
dojo.unsubscribe('close uploader');
console.log('closed uploader');
}));
dialog.show();
}
});