All Downloads are FREE. Search and download functionalities are using the official Maven repository.

web.script.renderers.simple_renderers.file_content_renderer.js Maven / Gradle / Ivy

There is a newer version: 4.9.2
Show newest version
dm4c.add_simple_renderer("dm4.files.file_content_renderer", {

    render_info: function(page_model, parent_element) {
        render_content()

        // ------------------------------------------------------------------------------------------- Private Functions

        function render_content() {
            try {
                var path       = page_model.parent.object.get("dm4.files.path")
                var media_type = page_model.parent.object.get("dm4.files.media_type")
                // Note: for embedded files (e.g. in a Person) the File topic might be empty
                if (!path) {
                    return
                }
                var src = filerepo_URI()
                // Note: for unknown file types media_type is null
                /*if (!media_type) {
                    throw "the file's media type can't be detected";
                }*/
                if (media_type) {
                    // TODO: let plugins render the file content
                    if (media_type == "text/plain") {
                        render($("
").text(dm4c.restc.get_file(path)))
                        return
                    } else if (js.begins_with(media_type, "image/")) {
                        render($("").attr("src", src))
                        return
                    } else if (media_type == "application/pdf") {
                        render($("").attr({src: src, type: media_type,
                            width: "100%", height: dm4c.page_panel.height}))
                        return
                        // return $("