Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/app/templates/editor.html
blob: 6ac5d83314981c474068f06b64bf0f8a543117c3 (plain)
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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:py="http://genshi.edgewall.org/">
<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <title>Editor</title>
  <link rel="stylesheet" href="/static/css/main.css" type="text/css" />
    <link rel="stylesheet" href="/static/css/sugar-theme/jquery-ui-1.8.16.sugar.css" />
    <script src="/static/js/jquery-1.6.2.js" type="text/javascript"></script>
    <script src="/static/js/jquery-ui-1.8.16.sugar.min.js" type="text/javascript"></script>
    <script src="/static/js/jquery.corner.js" type="text/javascript"></script>
    <script src="/static/js/websdk-1.js" type="text/javascript"></script>
</head>
<body>
<script src="/static/js/ace/ace-uncompressed.js" type="text/javascript" charset="utf-8"></script>
<script src="/static/js/ace/theme-twilight.js" type="text/javascript" charset="utf-8"></script>
<script py:if="mode" src="/static/js/ace/mode-${mode}.js" type="text/javascript" charset="utf-8"></script>
<pre id="editor">$content</pre>
<div id="editor-sidebar" class="bling">
<form id="saveform" action="/save" method="post">
<div class="file">
    <img src="/static/icons/${icon}" /><br/>
    ${absdir}/<br/>
    <strong py:if="basename!='///'">${basename}</strong>
    <input py:if="basename=='///'" style="width:90%" type="text" name="basename" id="basename"/>
    <br/>
</div>
<span id="result" style="color:red"></span>
<br/>
<hr /><br/>
<input type="hidden" name="filename" id="filename" value="$filename" />
<input type="hidden" name="directory" id="directory" value="$directory" />
<input type="hidden" name="content" id="content" value="ñññ" />
<!--input type="button" class="btn"  value="Browse" onclick='location.href="/files/$directory"' /-->
<input type="submit"  value="Save file" /><br/>
<input py:if="basename!='///'" type="button" value="Delete file" onclick='location.href="/delete/${filename}"' />
<!-- save a magic cookie for security here TODO -->
<input type="button" value="Return" onclick='location.href="/help"' />
<!--input type="button" class="btn"  value="edit wysiwyg" onclick='top.location.href=top.location.href+"&amp;editor=wysiwyg"' /-->

</form>
</div>
<script>
  /* attach a submit handler to the form */
  $("#saveform").submit(function(event) {

    /* stop form from submitting normally */
    event.preventDefault(); 

    var newfile=false;
    /* get some values from elements on the page: */
    var form = $( this ),
        cont = form.find( 'input[name="content"]' ).val(),
        dir = form.find( 'input[name="directory"]' ).val(),
        url = form.attr( 'action' );
    if ("${basename}"=="///") { // New file
        if (form.find('input[name="basename"]').val()=="") {
            $( "#result" ).empty().append( "name your file" );
            $( "#result" ).show().fadeOut(15000);
            return false;
        }else{
            var file = dir + "/" + form.find('input[name="basename"]').val();
            $('filename').val(file);
            newfile = true;
        }
    } else {
        var file = form.find( 'input[name="filename"]' ).val();
    }

    /* Send the data using post and put the results to #result */
    $.post( url, { content: cont, filename: file, directory: dir },
      function( data ) {
          $( "#result" ).empty().append( data );
          $( "#result" ).show().fadeOut(15000);
      }
    );
    if (newfile) {
        parent.frame2.location.reload();
    }
  });

document.ready = function() {
    $('#basename').corner();
    
    var aceEditor = ace.edit("editor");
    aceEditor.setTheme("ace/theme/twilight");
    document.getElementById('editor').style.fontSize='16px';
    aceEditor.getSession().setUseSoftTabs(true);
    // we can assume we're on unix
    aceEditor.getSession().setNewLineMode("unix");

    if ("${mode}"!="") {
        var thisMode = require("ace/mode/${mode}").Mode;
        aceEditor.getSession().setMode(new thisMode());
    }

    function dispatch() {
        var c = $('#content');
        c.val(aceEditor.getSession().getValue()); 
    }
    dispatch()

    aceEditor.getSession().on('change', dispatch);  
    $('.bling').slideDown("slow");
};
</script>
</body>
</html>