+
+/**
+ * Show a dialog loaded from an url
+ * By defaults this load the url in an iframe in colorbox
+ * Themes can overwrite `show()` function to personalize it
+ */
+var Dialog = {
+ /**
+ * Show the dialog
+ *
+ * @param string url
+ * @return object colorbox
+ */
+ show : function (url) {
+ var size = Dialog._get_size();
+ return $.colorbox({href: url, iframe:true,innerWidth: size.width+'px',innerHeight: size.height+'px'})
+ },
+
+ /**
+ * Show the Image browser dialog
+ *
+ * @param string name
+ * @param string id (optional)
+ * @return object
+ *
+ * The name will be used to build the event name
+ * fired by image browser dialog when the user select
+ * an image. The optional id will be passed as argument
+ * to the event handler
+ */
+ doImageBrowser : function (name, id) {
+ var url = Dialog._get_url("image",name,id);
+ return Dialog.show(url);
+ },
+
+ /**
+ * Show the File browser dialog
+ *
+ * @param string name
+ * @param string id (optional)
+ * @return object
+ *
+ * The name will be used to build the event name
+ * fired by file browser dialog when the user select
+ * a file. The optional id will be passed as argument
+ * to the event handler
+ */
+ doFileBrowser : function (name, id) {
+ var url = Dialog._get_url("file",name,id);
+ return Dialog.show(url);
+ },
+
+ _get_url : function(type, name, id) {
+ var hash = name;
+ if (id !== undefined) hash = hash + "-" + id;
+ return baseurl + "/fbrowser/"+type+"/?mode=minimal#"+hash;
+ },
+
+ _get_size: function() {
+ return {
+ width: window.innerWidth-50,
+ height: window.innerHeight-100
+ };
+ }
+}