Hello

I have a SQLFORM.grid page

Values for one filed (code) in add or edit view is filed with js code from 
values of two other fields.

User can deactivate this "record" - it can not be deleted only status is 
set to e.g. 100

If user creates a new record that creates the same values for code field 
(two users can have the same values in code field, since it is not based on 
id) I would like to remind the user that record with this value already 
exist in the db and if he wants to activate the record and not create a new 
one.

I hope the question is clear enough

Also if creating value for field sh_code is possible with python I would 
rather use it but user has to see the values of sc_code field before db 
insert

Thank you

my controler code

def turnusi():
user = auth.user_id
org = db(db.auth_user.id == 
user).select(db.auth_user.organization)[0]["organization"]
 db.worker.w_user.default = user
db.worker.w_organisation.default = org
#####Naredimo še grid za šifrant turnusov
db.shift.sh_organisation.default = org
 query_shifts = ((db.shift.sh_organisation == org) & (db.shift.sh_status == 
1))
query_inactive = db((db.shift.sh_organisation == org) & (db.shift.sh_status 
== 100)).select().as_list()
#print query_inactive
 fields_shifts =(
db.shift.sh_code,
db.shift.sh_name,
db.shift.sh_color,
db.shift.sh_start1,
db.shift.sh_end1,
db.shift.sh_length1,
db.shift.sh_start2,
db.shift.sh_end2,
db.shift.sh_length2,
db.shift.sh_duration1,
# db.shift.sh_start3,
# db.shift.sh_end3,
# db.shift.sh_start4,
# db.shift.sh_end4,
# db.shift.sh_start5,
# db.shift.sh_end5,
db.shift.sh_note)
 db.shift.sh_organisation.readable = False
db.shift.sh_organisation.writable = False
db.shift.sh_organisation.editable = False
 #db.shift.sh_code.editable = db.shift.sh_code.writable = False
 
#db.shift.sh_duration.writable = False
 db.shift.sh_duration1.readable = db.shift.sh_duration1.writable = False
#db.shift.sh_length1.writable = False
 #db.shift.sh_start2.readable = db.shift.sh_start2.writable = False
#db.shift.sh_start2.writable = False
 #db.shift.sh_end2.readable = db.shift.sh_end2.writable = False
#db.shift.sh_end2.writable = False
#db.shift.sh_length2.readable = db.shift.sh_length2.writable = False
 db.shift.sh_start3.readable = db.shift.sh_start3.writable = False
#db.shift.sh_start3.writable = False
 db.shift.sh_end3.readable = db.shift.sh_end3.writable = False
#db.shift.sh_end3.writable = False
db.shift.sh_length3.readable = db.shift.sh_length3.writable = False
 db.shift.sh_start4.readable = db.shift.sh_start4.writable = False
#db.shift.sh_start4.writable = False
db.shift.sh_length4.readable = db.shift.sh_length4.writable = False
 db.shift.sh_end4.readable = db.shift.sh_end4.writable = False
#db.shift.sh_end4.writable = False
 db.shift.sh_start5.readable = db.shift.sh_start5.writable = False
#db.shift.sh_start5.writable = False
 db.shift.sh_length5.readable = db.shift.sh_length5.writable = False
db.shift.sh_end5.readable = db.shift.sh_end5.writable = False
    #db.shift.sh_end5.writable = False#
    
 db.shift.sh_code.widget = SQLFORM.widgets.string.widget
db.shift.sh_name.widget = SQLFORM.widgets.string.widget
db.shift.sh_note.widget = SQLFORM.widgets.string.widget
 grid_shifts = SQLFORM.grid(query=query_shifts, 
fields=fields_shifts,  searchable=False,create=True,
deletable=False, editable=True, paginate=25, buttons_placement = 'right',
showbuttontext = False,formname = 'shiftTable',
formargs=dict(message_onsuccess=T('New record inserted'),
                                message_onfailure=T('Form has errors')),
#oncreate=myfunction,
ui = dict(widget='',
          header='',
          content='',
          default='',
          cornerall='',
          cornertop='',
          cornerbottom='',
          button='button btn btn-default',
          buttontext='buttontext button',
          buttonadd='icon plus icon-plus glyphicon glyphicon-plus',
          buttonback='icon leftarrow icon-arrow-left glyphicon 
glyphicon-arrow-left',
          buttonexport='icon downarrow icon-download glyphicon 
glyphicon-download',
          buttondelete='icon trash icon-trash glyphicon glyphicon-trash',
          buttonedit='icon pen icon-pencil glyphicon glyphicon-pencil',
          buttontable='icon rightarrow icon-arrow-right glyphicon 
glyphicon-arrow-right',
          buttonview='icon magnifier icon-zoom-in glyphicon 
glyphicon-eye-open',
          buttonvidov = 'icon glyphicon glyphicon-euro' 
          ),
exportclasses  = dict(csv_with_hidden_cols=False, html = False, tsv = 
False, tsv_with_hidden_cols=False, json = False))
# for input in grid_shifts.elements('input', _class='string'):
# input['_class'] = 'testniKlass'
 if request.args and request.args[0] in ['edit', 'new']:
 #dolocamo sirino polj
grid_shifts.element('input[name=sh_color]')['_style']='width:30%'
grid_shifts.element('[title=Back]').parent['_href'] = 
URL('settings','turnusi')
 return dict(grid_shifts=grid_shifts,query_inactive=query_inactive)



my js code in view to get values for field sh_code

$( ".time" ).change(function() {
//length1
start  = $('#shift_sh_start1').val(),
end = $('#shift_sh_end1').val();
var dur = compareTime(start,end)/ 60; 
$('#shift_sh_length1').val(dur);
  //length2
start2  = $('#shift_sh_start2').val(),
end2 = $('#shift_sh_end2').val();
 if (start2){
 var codeBeg1 = start.split(":")[0] + start.split(":")[1];
var codeEnd1 = end.split(":")[0] + end.split(":")[1];
 var codeBeg2 = start2.split(":")[0] + start2.split(":")[1];
var codeEnd2 = end2.split(":")[0] + end2.split(":")[1];
 var tCodeL = codeBeg1 +'-' + codeEnd1 + '&' + codeBeg2 + '-' + codeEnd2; 
$('#shift_sh_code').val(tCodeL);
var dur2 = compareTime(start2,end2)/ 60; 
$('#shift_sh_length2').val(dur2);
$('#shift_sh_duration').val(dur + dur2);
 }
else  {
$('#shift_sh_length2').val(null);
//code
var beg = start.split(":")[0] + start.split(":")[1];
var ed = end.split(":")[0] + end.split(":")[1];
var tCode = beg +"-" + ed; 
$('#shift_sh_code').val(tCode);
$('#shift_sh_duration').val(dur);
 }
});


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to