-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageSelector.js
116 lines (86 loc) · 3.2 KB
/
ImageSelector.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
dojo.provide("unc.ImageSelector");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require('dijit.form.TextBox');
dojo.require('dijit.form.Button');
dojo.require('dojox.image.Lightbox');
dojo.require('unc.ImageBrowser');
// a store singleton for use by all of these
dojo.ready(function() {
unc._ImageMediaStore = uow.getDatabase({
database: 'Media',
collection: 'Image',
mode: 'rc'
});
});
dojo.declare("unc.ImageSelector", [ dijit._Widget, dijit._Templated ], {
templatePath: dojo.moduleUrl('unc', 'ImageSelector.html'),
widgetsInTemplate: true,
name: '', // name of the control
value: '', //this is the URL
disabled: false,
title: '',
tags: '',
postCreate: function() {
this.connect(this.add, 'onClick', this.showBrowseDialog);
this.connect(this.preview, 'onClick', this.previewImage);
if(this.value) {
console.log("starting init");
dojo.when(unc._ImageMediaStore, dojo.hitch(this, function(db) {
db.fetch({
query:{'URL':this.value},
onComplete: dojo.hitch(this, function(items) {
if(items.length > 0) {
this.tags = items[0].tags;
this.title = items[0].title;
}
this.setImageValue(this.value, this.tags, this.title);
})
});
}));
}
},
showBrowseDialog: function() {
var imageBrowser = new unc.ImageBrowser();
var dialog = new dijit.Dialog({
title: "Select an Image",
content: [imageBrowser.domNode]
});
dojo.connect(imageBrowser, 'imageSelected', dojo.hitch(this, function() {
var image = imageBrowser.selected;
dialog.hide();
dialog.destroyRecursive();
this.setImageValue(image.URL, image.tags);
//set sound to value
this.value = image.URL;
this.onChange(this.value);
})
);
dialog.show();
},
setImageValue: function(url, tags, title) {
this.value = url;
this.title = title;
this.at_imageTextBox.attr('value', url + tags.join(' '));
},
previewImage: function() {
if(this.value) {
var dialog = new dojox.image.LightboxDialog({});
dialog.startup();
dialog.show({ title:this.title, href:this.value });
} else {
var dialog = new dojox.image.LightboxDialog({});
dialog.startup();
dialog.show({ title:'Default Image', href:'images/test.jpg' });
}
},
onChange: function(value) {
//this is the onChange method holder
},
_setDisabledAttr: function(value) {
dojo.query("[widgetId]", this.domNode).forEach(function(childNode) {
var child = dijit.byId(dojo.attr(childNode, 'widgetid'));
child.set('disabled', value);
});
}
});