Advertisement
Guest User

Abrir Modal

a guest
May 30th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.78 KB | None | 0 0
  1. tenho no meu DB.py, minhas duas tabelas
  2.  
  3. db.define_table("a_cadtiporgao",
  4.     Field("nome", label="Nome"),
  5.     auth.signature,
  6.     format="%(nome)s"
  7.     )
  8.  
  9. db.define_table("a_cadorgao",
  10.     Field("codtcm", label="Código do TCM"),
  11.     Field("nome", label="Descrição do Órgão"),
  12.     Field("tipoorg", "reference a_cadtiporgao", label="Tipo do Órgão"),
  13.     Field("cnpj", label="CNPJ"),
  14.     Field("mascara", label="Máscara da Lotação"),
  15.     Field("centralizado", "boolean", label="Marque esta opção quando o Órgão for Centralizador"),
  16.     Field("endereco", label="Endereço"),
  17.     Field("bairro", label="Bairro"),
  18.     Field("cidade", label="Cidade"),
  19.     Field("uf", label="UF"),
  20.     Field("cep", label="CEP"),
  21.     Field("telefone",  label="Telefone"),
  22.     Field("obs", label="Observação"),
  23.     auth.signature,
  24.     format="%(nome)s"
  25.     )
  26. db.a_cadorgao.tipoorg.requires=IS_IN_DB(db,'a_cadtiporgao.id','%(nome)s')
  27. db.a_cadorgao.cidade.requires=IS_IN_DB(db,'a_cadcidade.id','%(nome)s')
  28. db.a_cadorgao.uf.requires=IS_IN_SET(ufs)
  29. db.a_cadorgao.cnpj.requires=IS_CPF_OR_CNPJ()
  30.  
  31.  
  32. no meu controler criei:
  33.  
  34. def orgao_new():
  35.     response.view = 'geral/orgao_new.html'
  36.  
  37. #Initialize O widget
  38.     add_option = SELECT_OR_ADD_OPTION(form_title="Add new Product Category", controller="geral", function="add_tip_orgao_extra", button_text = "Novo")
  39.     db.a_cadorgao.tipoorg.widget = add_option.widget
  40.  
  41.     form = SQLFORM(db.a_cadorgao,  formstyle="divs", submit_button='Salvar',
  42.                fields=['codtcm', 'nome', 'tipoorg', 'cnpj', 'mascara', 'centralizado', 'endereco'
  43.                , 'bairro', 'cidade', 'uf', 'cep', 'telefone', 'obs'])
  44.  
  45.     if form.accepts(request.vars, session):        
  46.         response.flash = 'Cadastrado realizado com sucesso!'
  47.         redirect(URL(f='orgao_list', args=request.args(0)))
  48.     return dict(form=form)
  49.  
  50. def add_tip_orgao_extra():
  51.     #this is the controller function that will appear in our dialog
  52.     form = SQLFORM(db.a_cadtiporgao)
  53.    
  54.     if form.accepts(request.vars):
  55.         #Successfully added new item
  56.         #do whatever else you may want
  57.        
  58.         #Then let the user know it worked        
  59.         response.flash = T("Added")
  60.         target= request.args[0]
  61.         #close the widget's dialog box
  62.         response.js = '$( "#%s_dialog-form" ).dialog( "close" ); ' %(target)
  63.         #update the options they can select their new category in the main form                
  64.         response.js += """$("#%s").append("<option value='%s'>%s</option>");""" \
  65.                 % (target, form.vars.id, form.vars.name)
  66.         #and select the one they just added
  67.         response.js += """$("#%s").val("%s");""" % (target, form.vars.id)
  68.         #finally, return a blank form incase for some reason they wanted to add another option
  69.         return form
  70.     elif form.errors:
  71.         #silly user, just send back the form and it'll still be in our dialog box complete with error messages
  72.         return form
  73.     else:
  74.         #hasn't been submitted yet, just give them the fresh blank form        
  75.         return form
  76.  
  77. na minha view, tem:
  78.  
  79. ...
  80.     {{response.files.append("http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js")}}
  81.     {{response.files.append("http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/smoothness/jquery-ui.css")}}
  82. ...
  83.           {{=form.custom.begin}}
  84.           <div class='form-group'>
  85.             <label class='control-label col-md-2 col-md-offset-2' autofocus id="control-label" for="tipoorg">Tipo do Órgão: </label>
  86.             {{=form.custom.widget.tipoorg}}
  87.           </div>
  88.  
  89.          {{=form.custom.end}}
  90. ...
  91.  
  92.  
  93. quando eu abro a VIEW, so aparece: LOADING ( Novo )
  94. a palavra NOVO aparece ao receber o focu fica sublinhada, mas nao funciona como um link... nao executa nada
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement