-
-
Save tubbo/1293516 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def edit(): | |
icon_name = request.vars.item_0 if request.vars else None | |
icon_name = urllib.unquote(icon_name) | |
model = Icon() | |
if icon_name: | |
icon_object = bw.objectQuery("icon", icon_name) | |
model.populate(icon_object) | |
icon_form = SQLFORM.factory(*model.fields()) | |
if icon_form.accepts(request.vars, session): | |
# first update data | |
model.populate(request.vars) | |
icon_update = model.serialize() | |
if hasattr(request.vars, 'icon_file'): | |
if request.vars.icon_file: | |
icon_update['icon'] = xmlrpclib.Binary(request.vars.icon_file.value) | |
result = bw.objectUpdate('icon', icon_update) | |
# then try to rename | |
if (icon_object['name'] != request.vars.name): | |
bw.objectRename("icon", icon_object['name'], request.vars.name) | |
return response.json({'success': True}) | |
if icon_form.errors: | |
return response.json(icon_form.errors) | |
return dict(form=icon_form) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
$('button[type="button"]').click(function() { | |
form_cancel(); | |
return false; | |
}); | |
$("#icon_form form").submit(function() { | |
$(this).ajaxSubmit({ | |
type: 'POST', | |
url: '{{=URL("icon", "edit", vars={"item_0":request.vars.item_0})}}', | |
dataType: 'json', | |
success: function(response, statusText, xhr, form) { | |
console.log("here!"); | |
page_load_callback(); | |
if (response.success) { | |
$('#right_sidebar').empty(); | |
$('#icon_table').dataTable().fnDraw(); | |
display_success("{{=T('icon updated')}}"); | |
} else { | |
display_error("{{=T('There is an error with your form')}}"); | |
$.each(response, function(k, v) { | |
$("#no_table_" + k).after('<dd class="error">' + v + '</dd>'); | |
}); | |
} | |
} | |
}); | |
return false; | |
}); | |
</script> | |
<div id="icon_form"> | |
{{=form.custom.begin}} | |
<button type="submit">{{=T('Update')}}</button> | |
<button type="button">{{=T('Cancel')}}</button> | |
<div class="content-box column-right"> | |
<div class="content-box-header"> | |
<h3>{{=T("Name and Details")}}</h3> | |
</div> | |
<div class="content-box-content"> | |
<div class="tab-content default-tab"> | |
<dl> | |
<dt>{{=form.custom.label.name}}</dt> | |
<dd>{{=form.custom.widget.name}}</dd> | |
</dl> | |
</div> | |
</div> | |
</div> | |
<div class="content-box column-right closed-box"> | |
<div class="content-box-header"> | |
<h3>{{=T("Icon Upload")}}</h3> | |
</div> | |
<div class="content-box-content"> | |
<div class="tab-content default-tab"> | |
<dl> | |
<dt>{{=T("Icon")}}</dt> | |
<dd>{{=INPUT(_type='file', _name='icon_file', _id='icon_file', requires=IS_NOT_EMPTY())}}</dd> | |
</dl> | |
</div> | |
</div> | |
</div> | |
{{=form.custom.end}} | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment