Closed GoogleCodeExporter closed 9 years ago
You could add your own plugin that exposes your own action, something like this:
function CustomActionPlugin() {
var that = this;
this.getPluginInfo = function() { return { id: "custom-action-plugin" }; }
this.initialize = function(env) {
that.env = env;
env.addItemContextProvider(function(item, details) {
if (item.extension != 'pdf') return null;
return {
components: [],
actions: {
primary: [{
title: "My view action",
callback: that.onView
}],
secondary: []
}
}
});
}
this.onView = function(item) {
var url = that.env.service().getUrl("view/"+item.id+"/content/");
window.open(url, 'viewer', "height=600, width=400");
}
}
and then register this in your mollify init.
However, I couldn't make chrome display the pdf, it just downloaded the file.
Original comment by samuli.j...@gmail.com
on 14 Dec 2011 at 6:34
Original comment by samuli.j...@gmail.com
on 5 Jan 2012 at 9:00
I don't see how? In fact in the latest update when I click on txt file, it
says Unknown Error Occurred.
Original comment by Jesse.Sc...@gmail.com
on 6 Jan 2012 at 4:33
How what? You don't know where to put this or what? This is javascript and goes
into the index.html under mollify.init inside script tag.
Unknown error, or txt files in general, does not have anything to do with this
example. I don't have any problems with txt files, so you'd have to get error
log for this error.
Original comment by samuli.j...@gmail.com
on 6 Jan 2012 at 5:13
This doesn't work because it is relying on the viewer plugin, which doesn't
return a proper mime type (so it always downloads the file).
I added a new view type to the FilesystemServices class, like so:
--- FilesystemServices.class.php (revision 1430)
+++ FilesystemServices.class.php (working copy)
@@ -37,6 +37,24 @@
return;
}
+ if ($this->path[0] === 'view') {
+ $item = $this->item($this->path[1]);
+ if ($item->isFile())
+ {
+ if (count($this->path) == 2) {
+ $this->env->filesystem()->view($item);
+ return;
+ }
+ else
+ ; # invalid
+ }
+ else
+ ; # invalid
+
+ return;
+ }
+
+
$item = $this->item($this->path[0]);
if ($item->isFile())
$this->processGetFile($item);
to get around this. Then I came up against a bug in the mime type checking
which causes it to always return the default. I fixed that by doing this:
--- OutputHandler.class.php (revision 1430)
+++ OutputHandler.class.php (working copy)
@@ -157,8 +157,9 @@
}
private function getMime($type) {
- if (in_array($type, $this->mimeTypes)) return $this->mimeTypes[$type];
- if (in_array($type, $this->defaultMimeTypes)) return
$this->defaultMimeTypes[$type];
+ if (array_key_exists($type, $this->mimeTypes)) return
$this->mimeTypes[$type];
+ if (array_key_exists($type, $this->defaultMimeTypes)) return
$this->defaultMimeTypes[$type];
+
return 'application/octet-stream';
}
Then change the onview function in the above example to:
this.onView = function(item) {
var url = that.env.service().getUrl("filesystem/view/"+item.id);
window.open(url);
}
At which point you new view button should start working. Finally, you will want
to add more mime types, the default set in Mollify doesn't even have jpg. That
is done in configuration.php, and looks like this:
$SETTINGS = array(
"mime_types" => array(
'jpg' => 'image/jpeg',
'ogg' => 'audio/ogg',
)
);
Original comment by kevin.se...@gmail.com
on 8 Mar 2012 at 3:26
Original issue reported on code.google.com by
Jesse.Sc...@gmail.com
on 12 Dec 2011 at 9:15