PageRenderTime 60ms CodeModel.GetById 30ms app.highlight 1ms RepoModel.GetById 19ms app.codeStats 0ms

/kai/templates/snippets/edit.mako

https://bitbucket.org/bbangert/kai/
Mako | 53 lines | 50 code | 3 blank | 0 comment | 3 complexity | 3de0f74e438d3cbaab0a7944d107730e MD5 | raw file
 1<%!
 2from kai.model.forms import snippet_form
 3%>
 4<h1>${_('Edit Snippet')}</h1>
 5
 6${snippet_form.display(dict(title=c.snippet.title, description=c.snippet.description,
 7                    content=c.snippet.content, tags=', '.join(c.snippet.tags or [])
 8               ), action=url('snippet', id=c.id, _method='PUT')) | n}
 9
10<div style="display: none; border: 2px solid #444; padding: 4px;" id="snippet_preview">&nbsp;</div>
11
12<%def name="title()">${parent.title()} - ${_('Edit Snippet')}</%def>
13<%def name="javascript()">
14${parent.javascript()}
15<script src="http://yui.yahooapis.com/2.6.0/build/yuiloader/yuiloader-min.js" ></script>
16<script src="/javascripts/rst_helpers.js" charset="utf-8"></script>
17<script>
18$(document).ready(function() {
19    var loader = new YAHOO.util.YUILoader({
20        require: ["autocomplete"],
21        loadOptional: true,
22        onSuccess: function() {            
23            make_tagger = function(tag_field, tag_box, datafield) {
24                var data_source = new YAHOO.widget.DS_JSArray(datafield);
25                var myAutoComp = new YAHOO.widget.AutoComplete(tag_field, tag_box, data_source);
26                myAutoComp.typeAhead = true;
27                myAutoComp.queryDelay = 0;
28                myAutoComp.minQueryLength = 2;
29                myAutoComp.delimChar = [" ", ","];
30                return true;
31            };
32            var tags = [${','.join(["\"%s\"" % tag for tag in c.tags]) | n}];
33            make_tagger('snippet_form_tags', 'snippet_form_tags_autocomplete', tags);
34        }
35    });
36    loader.insert();
37    $('input#snippet_form_preview').click(function() {
38        var content = $('#snippet_form_content')[0].value;
39        var preview_url = '${url('preview_snippet')}';
40        $.ajax({
41            data: {content:content},
42            type: "POST",
43            url: preview_url,
44            success: function(data, textStatus) {
45                $('#snippet_preview').html(data).slideDown();
46            }
47        });
48        return false;
49    });
50})
51</script>
52</%def>
53<%inherit file="layout.mako" />