Disable image upload form on stylesheet editor.

This commit is contained in:
Matt Lee
2015-07-24 11:58:24 -07:00
committed by Florence Yeun
parent 468b0551d0
commit b53ebded00
2 changed files with 113 additions and 106 deletions

View File

@@ -2704,12 +2704,18 @@ class SubredditStylesheet(Templated):
"""form for editing or creating subreddit stylesheets"""
def __init__(self, site = None,
stylesheet_contents = ''):
allow_image_upload = site and not site.quarantine
raw_images = ImagesByWikiPage.get_images(c.site, "config/stylesheet")
images = {name: make_url_protocol_relative(url)
for name, url in raw_images.iteritems()}
Templated.__init__(self, site = site, images=images,
stylesheet_contents = stylesheet_contents)
Templated.__init__(
self,
site=site,
images=images,
stylesheet_contents=stylesheet_contents,
allow_image_upload=allow_image_upload,
)
@staticmethod
def find_preview_comments(sr):

View File

@@ -112,115 +112,116 @@
</table>
</div>
<div id="images">
<h2><a name="images">${_("images")}</a></h2>
%if thing.allow_image_upload:
<div id="images">
<h2><a name="images">${_("images")}</a></h2>
<%call expr="image_upload('/api/upload_sr_img', '',
onchange='return file_changed(this)',
label = _('image file'), ask_type=True)">
<br/>
<label for="img-name">${_("new image name:")}</label>
<input id="img-name" name="name" value="" type="text"/>
${error_field("BAD_CSS_NAME", "name")}
<br/>
<span class="little gray">
${_("(image names should consist of alphanumeric characters and '-' only)")}
</span>
</%call>
<p class="error">
${_("Note: any changes to images here will be reflected immediately on reload and cannot be undone.")}
</p>
<script type="text/javascript">
/* <![CDATA[ */
function create_new_image(name) {
var list = $(".image-list:first");
var new_li = list.children("li:first")
.clone(true).attr("id", "")
.find(".img-name").html(name).end()
.find(".img-url").html("url(%%" + name + "%%)").end()
.find("form input[name=img_name]").val(name).end()
.find("img").attr("id", "img-preview-" + name).end();
list.append(new_li);
img = new_li.find("img");
$("#old-names").append("<option>" + name + "</option>");
return img;
}
<%call expr="image_upload('/api/upload_sr_img', '',
onchange='return file_changed(this)',
label = _('image file'), ask_type=True)">
<br/>
<label for="img-name">${_("new image name:")}</label>
<input id="img-name" name="name" value="" type="text"/>
${error_field("BAD_CSS_NAME", "name")}
<br/>
<span class="little gray">
${_("(image names should consist of alphanumeric characters and '-' only)")}
</span>
</%call>
<p class="error">
${_("Note: any changes to images here will be reflected immediately on reload and cannot be undone.")}
</p>
<script type="text/javascript">
/* <![CDATA[ */
function create_new_image(name) {
var list = $(".image-list:first");
var new_li = list.children("li:first")
.clone(true).attr("id", "")
.find(".img-name").html(name).end()
.find(".img-url").html("url(%%" + name + "%%)").end()
.find("form input[name=img_name]").val(name).end()
.find("img").attr("id", "img-preview-" + name).end();
list.append(new_li);
img = new_li.find("img");
$("#old-names").append("<option>" + name + "</option>");
return img;
}
function on_image_success(img) {
$(img).parents("li:first").fadeIn();
$(img).parent("a").attr("href", $(img).attr("src"));
}
function on_image_success(img) {
$(img).parents("li:first").fadeIn();
$(img).parent("a").attr("href", $(img).attr("src"));
}
function paste_url(source) {
var txt = $(source).siblings("pre:first").html();
$("#stylesheet_contents").insertAtCursor(txt);
return false;
}
function delete_img(button) {
$(button).parents("li:first").fadeOut(function() {
$(this).remove();
})
}
function file_changed(file_input) {
$("#submit-header-img").show();
$(".img-status").html("");
if(file_input.value) {
if(! $('#img-name').val()) {
var f = file_input.value
.replace(/.*[\/\\]/, "").split('.')[0]
.replace(/[ _]/g, "-");
$('#img-name').val(f);
}
function paste_url(source) {
var txt = $(source).siblings("pre:first").html();
$("#stylesheet_contents").insertAtCursor(txt);
return false;
}
function delete_img(button) {
$(button).parents("li:first").fadeOut(function() {
$(this).remove();
})
}
function file_changed(file_input) {
$("#submit-header-img").show();
$(".img-status").html("");
if(file_input.value) {
if(! $('#img-name').val()) {
var f = file_input.value
.replace(/.*[\/\\]/, "").split('.')[0]
.replace(/[ _]/g, "-");
$('#img-name').val(f);
}
var ext = file_input.value
.split('.').pop().toLowerCase()
.replace("jpeg", "jpg");
if (ext == 'png' || ext == 'jpg') {
$('input:radio[name=img_type]').attr('checked', false);
$('input:radio[name=img_type][value="' + ext + '"]').attr('checked', true);
}
}
}
/* ]]> */
</script>
<ul id="image-preview-list" class="image-list">
<%def name="make_li(name='', img=None, prototype=False)">
<li ${"style='display:none'" if img is None else ""}>
<a href="${img}" class="preview">
<img id="img-preview-${name}" src="${img}"
alt="Image ${name}" title="click to preview"/>
</a>
<div class="description">
<b class="img-name">
${name}
</b>
<br/>
<span>link:</span>
<pre class="img-url">url(%%${name}%%)</pre>
<br/>
<a href="javascript:void(0)" onclick="return paste_url(this)">
${_("paste into stylesheet")}
var ext = file_input.value
.split('.').pop().toLowerCase()
.replace("jpeg", "jpg");
if (ext == 'png' || ext == 'jpg') {
$('input:radio[name=img_type]').attr('checked', false);
$('input:radio[name=img_type][value="' + ext + '"]').attr('checked', true);
}
}
}
/* ]]> */
</script>
<ul id="image-preview-list" class="image-list">
<%def name="make_li(name='', img=None, prototype=False)">
<li ${"style='display:none'" if img is None else ""}>
<a href="${img}" class="preview">
<img id="img-preview-${name}" src="${img}"
alt="Image ${name}" title="click to preview"/>
</a>
<br/>
${ynbutton(_("delete this image"), _("deleted"),
"delete_sr_img", callback = "delete_img",
hidden_data = dict(img_name = name))}
</div>
</li>
</%def>
${make_li(prototype=True)}
%for name, url in thing.images.iteritems():
${make_li(name=name, img=url)}
%endfor
</ul>
<iframe src="about:blank" width="600" height="200" style="display: none;"
name="upload-iframe" id="upload-iframe"></iframe>
</div>
<div class="description">
<b class="img-name">
${name}
</b>
<br/>
<span>link:</span>
<pre class="img-url">url(%%${name}%%)</pre>
<br/>
<a href="javascript:void(0)" onclick="return paste_url(this)">
${_("paste into stylesheet")}
</a>
<br/>
${ynbutton(_("delete this image"), _("deleted"),
"delete_sr_img", callback = "delete_img",
hidden_data = dict(img_name = name))}
</div>
</li>
</%def>
${make_li(prototype=True)}
%for name, url in thing.images.iteritems():
${make_li(name=name, img=url)}
%endfor
</ul>
<iframe src="about:blank" width="600" height="200" style="display: none;"
name="upload-iframe" id="upload-iframe"></iframe>
</div>
%endif
</div>