add a basic plaintextview (related to #289632)

render file content in pre tag

authorSamuel Trégouët <samuel.tregouet@logilab.fr>
changeseta6c47feea690
branchdefault
phasepublic
hiddenno
parent revision#66cf5d7a04a2 pdfview: state of a pdf-viewer should be on instance and not on prototype
child revision#5037f221d1eb xmosaicframe: fill form partially with initial dataset (if exist)
files modified by this revision
components/plainview/plaintextview.js
components/plainview/plainview.html
portfolios/_template.html
# HG changeset patch
# User Samuel Trégouët <samuel.tregouet@logilab.fr>
# Date 1427990223 -7200
# Thu Apr 02 17:57:03 2015 +0200
# Node ID a6c47feea6903d22ae42cf47bcf8de147ccfaf7c
# Parent 66cf5d7a04a25bdd05ed33171962f2961022591d
add a basic plaintextview (related to #289632)

render file content in pre tag

diff --git a/components/plainview/plaintextview.js b/components/plainview/plaintextview.js
@@ -0,0 +1,22 @@
1 +(function() {
2 +    /* global $ */
3 +    'use strict';
4 +    var registry = require('registry');
5 +
6 +
7 +    function plainView(ctx) {
8 +        var contentType = ctx.xhr.getResponseHeader('content-type');
9 +        var viewer = document.createElement('pre');
10 +        $.ajax({
11 +            url: ctx.reqUrl,
12 +            type: "GET"
13 +        }).done(function(data, status, xhr) {
14 +            viewer.textContent = data;
15 +        }).fail(function() {
16 +            viewer.textContent = 'something goes wrong when requesting file';
17 +        });
18 +        return viewer;
19 +    }
20 +
21 +    registry.registerView('http', 'plain', plainView);
22 +})();
diff --git a/components/plainview/plainview.html b/components/plainview/plainview.html
@@ -0,0 +1,1 @@
23 +<script src="plaintextview.js"></script>
diff --git a/portfolios/_template.html b/portfolios/_template.html
@@ -17,10 +17,11 @@
24      <link rel="import" href="/components/neolistview/neolistview.html" />
25      <link rel="import" href="/components/sparqltableview/sparqltableview.html" />
26      <link rel="import" href="/components/cwtableview/cwtableview.html" />
27      <link rel="import" href="/components/markdown-editable/markdown-editable.html" />
28      <link rel="import" href="/components/pdfview/pdfview.html" />
29 +    <link rel="import" href="/components/plainview/plainview.html" />
30    </head>
31    <body>
32      <div class="container">
33        <button id="save-portfolio" class="btn">save portfolio</button>
34        <x-markdown-editable>###Edit me</x-markdown-editable>