Skip to content

Instantly share code, notes, and snippets.

@gorosz
gorosz / ajax form submission
Created December 12, 2013 06:30
[web2py] - ajax form submission
<script>
jQuery('#forcast_month_selector').submit(function() {
jQuery('#generateresult').fadeIn();
ajax('{{=URL("ces", "populate", vars=dict(type="forecast"))}}',
['forecast_month'], 'generateresult');
return false;
});
</script>
@gorosz
gorosz / ajax call with confirm on button click
Created December 9, 2013 09:55
[web2py] - confirm dialog on button click with ajax call
"if (confirm('Are you sure to clear table?')) ajax('%s', [], ':eval')"
@gorosz
gorosz / recordversioning
Created November 5, 2013 12:03
[web2py] - recordversioning
<snippet>
<content><![CDATA[$SELECTION._enable_record_versioning(
archive_db=${1: archive_db},
archive_name='${2: archive_table}_archive',
current_record='current_record',
is_active='is_active')]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
@gorosz
gorosz / create dict
Created October 7, 2013 09:59
[web2py] - Create dict for select/insert
FieldsToUpdate = ['cost_center', 'group1', 'wbs']
Fields = [Teams.cost_center, Groups.group_name, WbsList.wbs_code]
FieldsDict = {'cost_center': Teams.cost_center, 'group1': Groups.group_name, 'wbs': WbsList.wbs_code}
DbTableLinks = itmoney_db((Groups.sdu_id == Sdus.id) & (Groups.id == Teams.group_id) & (WbsList.team_id == Teams.id) & (WbsList.customer_id == Customers.id) & ((Projects.wbs_bud == WbsList.id) | (Projects.wbs_deb == WbsList.id) | (Projects.wbs_pecs == WbsList.id)) & (Customers.partner_company_id == PartnerCompanies.id))
DbData = DbTableLinks.select(*FieldsDict.values())
UpdateDict = {}
for item in DbData:
x = item[FieldsDict['cost_center']]
for k in FieldsDict.keys():
UpdateDict[k] = item[FieldsDict[k]]
@gorosz
gorosz / dataTables
Created September 20, 2013 07:57
[javascript] - dataTables
<script>
$('#TableID or Class').dataTable({
"bPaginate": false,
"aaSorting": [[ 1, "asc" ]]
})
</script>
@gorosz
gorosz / table style
Created September 20, 2013 07:37
[web2py] - Table style
_style="width: auto; white-space: nowrap"
@gorosz
gorosz / Toggle_attribute
Created September 17, 2013 06:38
[javascript] - Toggle_attribute
<script>
(function($) {
$.fn.toggleReadonly = function() {
return this.each(function() {
var $this = $(this);
if ($this.attr('readonly')) $this.removeAttr('readonly');
else $this.attr('readonly', 'readonly');
});
};
})(jQuery);
@gorosz
gorosz / Grid on -creat, -update, -delete
Created September 16, 2013 10:01
[web2py] - Grid oncreate, update, delete
def do_something_with(form):
...
return
SQLFORM.grid(....,oncreate=lambda form: do_something_with(form))
SQLFORM.grid(....,onupdate=lambda form: do_something_with(form))
@gorosz
gorosz / radio_on_change
Created September 11, 2013 05:47
[javascript] - radio_on_change
<script>
$('input[type="radio"]').on('click change', function(e) {
ajax("{{=URL('default', 'avaya_match_report')}}", ['criteria'], "reportresult")
console.log(e.type);
});
</script>
@gorosz
gorosz / enable tab url
Created September 10, 2013 12:03
[javascript] - enable_tab_url
<script>
$(function () {
$('#myTab a:first').tab('show');
// Javascript to enable link to tab
// var url = document.location.toString();
// if (url.match('#')) {
// $('.nav-tabs a[href=#'+url.split('#')[1]+']').tab('show') ;
// window.scrollTo(0, 0);
// }