plugin
upstream
Templates in the website are disabled now. Editing them will not have any effect on the live website.
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 |
$def with (author, page, name, unique=True, right=False) $ label = _.get('/type/edition', name) $ value = page[name] $add_stylesheet("/static/css/freebase-controls.css") $add_javascript("/static/js/jquery/freebase.suggest.js") $ class_label = (right and "formheader-data-left") or "formheader" $ class_input = (right and "formheader-data-left") or "formfield" <tbody id="tbody_$name"> $if unique: <tr> <td valign="middle" class="$class_label">$label</td> <td valign="top" class="$class_input">$:thinginput(get_property_type(page.type, name), name, value)</td> <td valign="top" class="formbuttons"></td> </tr> $else if value(page[author]): <tr> <td valign="middle" class="$class_label">$label</td> <td valign="top" class="$class_input"> <input id="key_$name" type="hidden" name="$name" value="$author.key"/> <input id="saved_name_$name" type="hidden" name="_saved_name_$name" value="$author.name" onselect="\$(this).parent().hide(); return false;" style="width: 100%"/> <input id="name_$name" type="text" name="_name_$name" value="$author.name" style="width: 100%"/> </td> <td valign="top" class="formbuttons"></td> </tr> </tr><tr><td colspan="2"> <div id="fberror_$name" style="display: none;"> <div class="fb_error">$_t.author_dropdown</div><br> <span id="hideerror"></div> </div> <div id="msg"> </div> </td><td></td></tr> $else: $ value = value or [""] $for i, v in enumerate(value): <tr> <td valign="middle" class="$class_label">$label</td> <td valign="top" class="$class_input">$:thinginput(get_property_type(page.type, name), name + '#' + str(i), v)</td> <td valign="top" class="formbuttons-identifier"> $if i == len(value) - 1: <button class="control" onClick="add_row('$name')" type="button"><img src="/static/images/+.gif" alt="+" width="18" height="18" /></button> </td> </tr> $ label = "" </tbody> <script type="text/javascript"> function new_author(name) { \$.post( '/addauthor', {name: name}, function(data, status) { if (status == "success") { \$(document.getElementById("key_$name")).attr("value", data); \$(document.getElementById("saved_name_$name")).attr("value", name); alert("Author added."); } else { alert("Error in creating author: " + status); } }, "text" ); } jQuery(function(\$) { \$(document.getElementById("name_$name")) .freebaseSuggest({ soft: false, suggest_new: "$_t.author_create", service_url: "http://" + window.location.host, ac_path: '/suggest/search', blurb_path: '/suggest/blurb' }) .bind("fb-select", function(e, data) { \$(document.getElementById("key_$name")).attr("value", data.id); \$(document.getElementById("saved_name_$name")).attr("value", data.name); }) .bind("fb-select-new", function(e, data) { new_author(data.name); }); \$(document.getElementById('key_$name')).parents('form') .bind("submit", function(e, data) { var v1 = \$(document.getElementById("saved_name_$name")).val(); var v2 = \$(document.getElementById("name_$name")).val(); if (v1 != v2) { \$(document.getElementById("fberror_$name")).show() \$(document.getElementById("name_$name")).focus(); return false; } return True; }); }); </script> |