class Myform::MyForm
Attributes
additional_on_insert[RW]
additional_on_update[RW]
ag[RW]
batch[RW]
id[RW]
is_embedded[RW]
moditem[RW]
new_parentselected[RW]
parentselected[RW]
querySQL[RW]
runmode[RW]
table[R]
title[RW]
tmp[R]
Public Class Methods
new(caller,form_id,runmode)
click to toggle source
Calls superclass method
# File lib/FormHolder/Form.rb, line 13 def initialize(caller,form_id,runmode) @caller=caller @table=nil @parentselected=nil @new_parentselected=nil @querySQL="" @runmode=runmode @additional_on_update="" @additional_on_insert="" @batch=nil @batch_support=false set_id(form_id) @items=Array.new @tips=Gtk::Tooltips.new.enable @tmp=Hash.new @built=false @multiselector=nil super() @tabs.sort{|a,b| a[1]['minX'].to_f <=> b[1]['minX'].to_f}.each{|t| tab=t[0] @tabs[tab]["widget"]=Gtk::Table.new(0,0,false) @tabs[tab]["widget"].set_border_width(0) @tabs[tab]["widget"].set_resize_mode(Gtk::ResizeMode::PARENT) @tabs[tab]["widget"].resize(1+ @tabs[tab]['maxY'].to_i-@tabs[tab]['minY'].to_i,1+ @tabs[tab]['maxX'].to_i-@tabs[tab]['minX'].to_i) append_page(@tabs[tab]["widget"],Gtk::Label.new(@tabs[tab]["title"])) } set_show_tabs(@tabs.size>1) set_show_border(@tabs.size>1) set_tab_pos(case gtk_attribute("tab-position") when "BOTTOM" then Gtk::PositionType::BOTTOM when "RIGHT" then Gtk::PositionType::RIGHT when "LEFT" then Gtk::PositionType::LEFT else Gtk::PositionType::TOP end ) set_enable_popup(false) set_scrollable(true) signal_connect('destroy'){|me| set_conf(get_id,0,"page",page)} @is_embedded=nil end
Public Instance Methods
admin()
click to toggle source
# File lib/FormHolder/Form.rb, line 86 def admin if wysiwygf? ManqodDB.instance.manqod_db else ManqodDB.instance.manqod_db.admin end end
admin_qrow(sql,with_table=false)
click to toggle source
# File lib/FormHolder/Form.rb, line 176 def admin_qrow(sql,with_table=false) if wysiwygf? begin ManqodDB.instance.manqod_db.qrow(sql,with_table) rescue =>err retry if tell_exception("error in server connection",backtrace_to_debug(err),"server","error",false,true,"#{err}") end else begin ManqodDB.instance.manqod_db.admin.qrow(sql,with_table) rescue =>err retry if tell_exception("error in server connection",backtrace_to_debug(err),"server","error",false,true,"#{err}") end end end
apply_changes(caller)
click to toggle source
# File lib/FormHolder/Form.rb, line 372 def apply_changes(caller) s=""; #check if required items are filled @items.each { |item| if item.editable && item.required && (item.text==nil || (item.text!=nil && (item.text.length==0 || (item.text=="-1" && ['gtk_const_combo','gtk_combo','gtk_combo_wn','gtk_list'].include?(item.type))))) then s=s+item.description+"?\n";end} if s.length >0 #there were some unfilled but required form items warner=Gtk::MessageDialog.new(get_ancestor(Gtk::Window),Gtk::Dialog::DESTROY_WITH_PARENT,Gtk::MessageDialog::QUESTION,Gtk::MessageDialog::BUTTONS_OK,s) warner.set_image(Gtk::Image.new(Gtk::Stock::FIND_AND_REPLACE,Gtk::IconSize::DIALOG)) warner.show_all.run warner.destroy return -1 else run_events(get_id,'form-OnApply-beforeSQL') #/event OnApply if @runmode items_to_update=0 isql="" #build the query if @multiselector && @multiselector.toggled_ids.size > 0 sql="insert into #{@table} (#{@multiselector.item['data']}," @items.each { |item| sql="#{sql}#{item.data}," if item.text && (item.include_in_query_building || (item.include_in_query_building.nil? && item.editable?)) && !item.multiselector? } sql=sql[0 .. sql.rindex(',')-1] unless sql.rindex(',').nil? #strip last , autoadd_child_key=(parentM.class.name == "MyEditableList" && parentM.list_model.key_child && !(sql.index(" #{parentM.list_model.key_child} "))) #adding child_key/parent_key if autoadd_child_key begin sql="#{sql}, #{parentM.list_model.key_child}" rescue =>err eerror("can't auto-add child_key: #{parentM.list_model.key_child} => #{err}","form") end end sql="#{sql}) values " @multiselector.toggled_ids.each{|tid| isql="(#{tid}," @items.each { |item| isql="#{isql} '#{escape_string(item.text)}'," if item.text && (item.include_in_query_building || (item.include_in_query_building.nil? && item.editable?)) && !item.multiselector? } isql=isql[0 .. isql.rindex(',')-1] unless isql.rindex(',').nil? #strip last , if autoadd_child_key begin isql="#{isql}, '#{parentM.list_model.parentM.iter_at_cursor[parentM.list_model.column_of_parent_key]}'" if parentM.list_model.key_child.index(".")==nil || parentM.list_model.key_child.index("#{@table}.") rescue => err eerror("can't auto-add child_key: #{parentM.list_model.key_child} => #{err}","form") end end isql="#{isql})" sql="#{sql} #{isql}," } sql=sql[0 .. sql.rindex(',')-1] unless sql.rindex(',').nil? #strip last , else @items.each { |item| if item.text && (item.include_in_query_building || (item.include_in_query_building.nil? && item.editable?)) isql="#{isql} #{item.data} = '#{escape_string(item.text)}' ," items_to_update+=1 end } end if (items_to_update != 0) or (@runmode=='remove') isql=isql[0 .. isql.rindex(',')-1] if !isql.rindex(',').nil? case @runmode when 'add','copy' sql="insert into #{@table} set #{isql}"; sql=sql+", "+eeval("\"#{@additional_on_insert}\"") if @additional_on_insert.length>0 #auto-adding child_key if parentM.class.name == "MyEditableList" #adding child_key/parent_key if parentM.list_model.key_child # and ck=parentM.list_model.key_child[parentM.list_model.key_child.rindex(".")+1 .. parentM.list_model.key_child.length] unless sql.index(" #{parentM.list_model.key_child} ") begin sql="#{sql}, #{parentM.list_model.key_child} ='#{parentM.list_model.parentM.iter_at_cursor[parentM.list_model.column_of_parent_key]}'" if parentM.list_model.key_child.index(".")==nil || parentM.list_model.key_child.index("#{@table}.") rescue =>err eerror("can't auto-add child_key: #{parentM.list_model.key_child} => #{err}","form") end end end #adding child_key2/parent_key2 if parentM.list_model.key_child2 # and ck=parentM.list_model.key_child2[parentM.list_model.key_child2.rindex(".")+1 .. parentM.list_model.key_child2.length] unless sql.index(" #{parentM.list_model.key_child2} ") begin sql="#{sql}, #{parentM.list_model.key_child2} ='#{parentM.list_model.parentM.iter_at_cursor[parentM.list_model.column_of_parent_key2]}'" if parentM.list_model.key_child2.index(".")==nil || parentM.list_model.key_child2.index("#{@table}.") rescue =>err eerror("can't auto-add child_key2: #{err}","form") end end end end when 'modify' sql="update `#{@table}` set #{isql}"; sql="#{sql}, "+eeval("\"#{@additional_on_update}\"") if @additional_on_update.length>0; sql="#{sql} where #{@list_key} #{batch? ? "in (#{batch.join(",")})": "= '#{@parentselected}'"}" when 'remove' sql="delete from `#{@table}` where #{@list_key}='#{@parentselected}'" end end einfo(sql,"form") ret=if sql && query(sql) then -1 #error unless nil? else if @runmode == 'modify' then @new_parentselected=@parentselected else @new_parentselected=qrow("select #{@list_key} from #{table} order by #{@list_key} desc limit 1")[@list_key] end end run_events(get_id,'form-OnApply-afterSQL') @parentselected=new_parentselected ret=@parentselected if ret.nil? if @multiselector && @multiselector.toggled_ids.size>0 new_ids=Array.new rows("select #{@list_key} from #{table} order by #{@list_key} desc limit #{@multiselector.toggled_ids.size}").each{|newid| new_ids.push(newid[@list_key].to_i)} changed_ids_of_base(table,new_ids) else if batch? batch.each{|b| changed_ids_of_base(table,b.to_i)} else changed_ids_of_base(table,@parentselected.to_i) end end changed notify_observers(self) return ret.to_i end end end
attach(wg)
click to toggle source
# File lib/FormHolder/Form.rb, line 510 def attach(wg) yshrink=wg.gtk_attribute('vertical-shrink') == 'true' yfill=yexpand=['gtk_timestamp','gtk_calendar','gtk_const_radio','gtk_field_list','gtk_multiline','gtk_source','gtk_list','gtk_editable_list','filesave','fileload','qbuilder'].include?(wg.item['gtktype']) yfill=wg.gtk_attribute('vertical-fill') == 'true' if wg.gtk_attribute('vertical-fill') yexpand=wg.gtk_attribute('vertical-expand') == 'true' if wg.gtk_attribute('vertical-expand') yopts=(yfill ? Gtk::FILL : 0)|(yexpand ? Gtk::EXPAND : 0)|(yshrink ? Gtk::SHRINK : 0) xexpand=(wg.gtk_attribute('horizontal-expand')||'true') == 'true' xfill=(wg.gtk_attribute('horizontal-fill')||'true') == 'true' xshrink=(wg.gtk_attribute('horizontal-shrink')||'false') == 'true' xopts=(xfill ? Gtk::AttachOptions::FILL : 0)|(xexpand ? Gtk::AttachOptions::EXPAND : 0)|(xshrink ? Gtk::AttachOptions::SHRINK : 0) wg.item['x']='0' if wg.item['x'].to_i<0 wg.item['y']='0' if wg.item['y'].to_i<0 wg.item['xspan']='1' if wg.item['xspan'].to_i<1 wg.item['yspan']='1' if wg.item['yspan'].to_i<1 @tabs[wg.item["tab"]]["widget"].attach(wg.widget,wg.item['x'].to_i,wg.item['x'].to_i+wg.item['xspan'].to_i,wg.item['y'].to_i,wg.item['y'].to_i+wg.item['yspan'].to_i,xopts,yopts) end
batch?()
click to toggle source
# File lib/FormHolder/Form.rb, line 212 def batch? batch_support? && batch.class == Array end
batch_support?()
click to toggle source
# File lib/FormHolder/Form.rb, line 208 def batch_support? @batch_support end
cache()
click to toggle source
# File lib/FormHolder/Form.rb, line 102 def cache if wysiwygf? ManqodDB.instance.ccache else ManqodDB.instance.cache end end
client()
click to toggle source
# File lib/FormHolder/Form.rb, line 94 def client if wysiwygf? ManqodDB.instance.manqod_db.client else ManqodDB.instance.manqod_db end end
embedd?()
click to toggle source
# File lib/FormHolder/Form.rb, line 71 def embedd? if @moditem && @moditem['on_embed'].length >0 eeval(@moditem['on_embed'],self) else true end end
findItem(data)
click to toggle source
# File lib/FormHolder/Form.rb, line 244 def findItem(data) ret=nil @items.each{ |item| ret=item if item.data == data or item.data == "#{@table}.#{data}"} warn("form item: #{data} not found","tried [#{data}], [#{@table}.#{data}]","form",ERROR) if ret.nil? ret end
form_holder()
click to toggle source
# File lib/FormHolder/Form.rb, line 82 def form_holder @caller end
get_id()
click to toggle source
# File lib/FormHolder/Form.rb, line 216 def get_id @form_id end
itemValue(data)
click to toggle source
# File lib/FormHolder/Form.rb, line 255 def itemValue(data) item=findItem(data) ret="" ret=item.text if item and item.text edebug("itemValue: #{data.inspect} : #{item.inspect} text:#{item.text unless item.nil?} return: #{ret}","form") ret end
Also aliased as: item_value
items()
click to toggle source
# File lib/FormHolder/Form.rb, line 241 def items @items end
method_missing(sym,*args)
click to toggle source
# File lib/FormHolder/Form.rb, line 251 def method_missing(sym,*args) findItem(sym.to_s) end
parentM()
click to toggle source
# File lib/FormHolder/Form.rb, line 238 def parentM @caller.parentM end
qrow(sql,with_table=false)
click to toggle source
# File lib/FormHolder/Form.rb, line 160 def qrow(sql,with_table=false) if wysiwygf? begin ManqodDB.instance.manqod_db.client.qrow(sql,with_table) rescue =>err retry if tell_exception("error in server connection",backtrace_to_debug(err),"server","error",false,true,"#{err}") end else begin ManqodDB.instance.manqod_db.qrow(sql,with_table) rescue =>err retry if tell_exception("error in server connection",backtrace_to_debug(err),"server","error",false,true,"#{err}") end end end
query(sql)
click to toggle source
# File lib/FormHolder/Form.rb, line 140 def query(sql) if wysiwygf? begin ret=ManqodDB.instance.manqod_db.client.query(sql) tell_exception("Database Error","Duplicate entry","sql","error") if ret == -1 ret rescue =>err retry if tell_exception("error in server connection",backtrace_to_debug(err),"server","error",false,true,"#{err}") end else begin ret=ManqodDB.instance.manqod_db.query(sql) tell_exception("Database Error","Duplicate entry","sql","error") if ret == -1 ret rescue =>err retry if tell_exception("error in server connection",backtrace_to_debug(err),"server","error",false,true,"#{err}") end end end
reattach(wg)
click to toggle source
# File lib/FormHolder/Form.rb, line 506 def reattach(wg) @tabs[wg.item["tab"]]["widget"].remove(wg.widget) attach(wg) end
rows(sql) { |row| ... }
click to toggle source
# File lib/FormHolder/Form.rb, line 192 def rows(sql) if wysiwygf? begin ManqodDB.instance.manqod_db.client.rows(sql){|row| yield row} rescue =>err retry if tell_exception("error in server connection",backtrace_to_debug(err),"server","error",false,true,"#{err}") end else begin ManqodDB.instance.manqod_db.rows(sql){|row| yield row} rescue =>err retry if tell_exception("error in server connection",backtrace_to_debug(err),"server","error",false,true,"#{err}") end end end
set_ag(ag)
click to toggle source
# File lib/FormHolder/Form.rb, line 110 def set_ag(ag) @ag=ag ag.connect(Gdk::Keyval::GDK_KEY_space, Gdk::Window::CONTROL_MASK, Gtk::ACCEL_VISIBLE){ focused=@caller.holder.focus.parent if focused && ["MySourceView"].include?(focused.class.name) ret=focused.test_content if ret tell_exception("query is ok","fields: #{ret.num_fields}\n rows: #{ret.num_rows}","sql","normal",false) end end } ag.connect(Gdk::Keyval::GDK_KEY_f, Gdk::Window::CONTROL_MASK, Gtk::ACCEL_VISIBLE){ unless @caller.holder.focus.nil? if (focused=@caller.holder.focus.parent) && ["MyRendererMultiline","MySourceView"].include?(focused.class.name) then focused.run_search(self) end if (focused=@caller.holder.focus.parent) && ["MyRendererComboWithNew","MyRendererCombo","MyRendererConstCombo","FieldCombo"].include?(focused.class.name) then focused.model.filterer.run(self) end if (focused=@caller.holder.focus.parent.parent) && ["MyRendererList","FieldList"].include?(focused.class.name) then focused.model.filterer.run(self) end end } end
set_id(form_id)
click to toggle source
# File lib/FormHolder/Form.rb, line 219 def set_id(form_id) @form_id=form_id begin @moditem=cache.get("#{get_id}moditem") moditem_attributes=cache.get("#{get_id}attributes") @querySQL=moditem_attributes[:querySQL] @table=moditem_attributes[:table] @tabs=moditem_attributes[:tabs] @title=@moditem['display'] @batch_support=moditem_attributes[:batch] rescue => err retry if warn("can't load form: id=[#{@form_id}]",err,nil,"error",nil,true,backtrace_to_debug(err)) end self end
set_multiselector(widget)
click to toggle source
# File lib/FormHolder/Form.rb, line 136 def set_multiselector(widget) @multiselector=widget end
set_runmode(runmode)
click to toggle source
# File lib/FormHolder/Form.rb, line 234 def set_runmode(runmode) @runmode=runmode self end
to_s()
click to toggle source
# File lib/FormHolder/Form.rb, line 264 def to_s "Form id:#{get_id}(#{@title}[#{runmode}#{@multiselector ? "|multiselector":""}:#{@parentselected}])" end
update(notifier, pid=@parentselected,rm=@runmode)
click to toggle source
# File lib/FormHolder/Form.rb, line 268 def update(notifier, pid=@parentselected,rm=@runmode) einfo("notification from #{notifier} for [#{pid}]") @items.each{|i| i.unset_default} if @runmode!=rm && @built @runmode=rm @parentselected=pid case notifier.class.name when 'MyEditableList' # @parentselected=notifier.get_cursor_id @list_key=parentM.list_model.list_key if ['add','modify'].include?(runmode) @runmode='add' @runmode='modify' if @parentselected and @parentselected.to_i>=0 end when 'MyButton' @list_key="id" #FIXME # @runmode=notifier.function # @parentselected=notifier.parentselected when 'MyRendererComboWithNew','MyRendererList', 'MyRendererButton' @list_key="id" #FIXME # @parentselected=notifier.text when 'MyTouchWindow' @runmode='add' when 'NilClass' #we just run, currently known to call MyForm.update(nil) is from the Touchscreen stuff, kinda reinitialize when 'BarMenuItem', 'ButtonMenuItem' # @runmode='dry' ## set_id(notifier.target) else edebug("unknown routing: "+notifier.class.name,"form","warning") end unless @built edebug("building","form") if @runmode then @items.each{ |item| remove(item)} #destroy previous items if @caller.holder.class.name=='Gtk::Dialog' @caller.holder.title=@title pw=@caller.get_ancestor(MyWindow) if pw.class.name=="MyWindow" @caller.holder.set_icon(pw.mymenu.last.image.pixbuf) else @caller.holder.set_icon(pw.icon) end end @additional_on_update=String.new(@moditem['additional_on_update']) @additional_on_insert=String.new(@moditem['additional_on_insert']) @items.clear i=cache.get("#{get_id}items") i.each{|itemp| item=MyInputHolder.new(itemp,self) @tips.set_tip(item.eventbox,itemp['hint'],'extra hint') attach(item) @items << item } #setting observers, dependency tree built from itemVaule()-s in the SQLs @items.each{|item| q=String.new(item.querySQL) while first=q.index("itemValue(") var_first=first+"itemValue(".length q=q[var_first .. q.length] last=q.index(")")-1 dep=q[0 .. last].gsub("'","") if driverItem=findItem(dep) edebug(item.data+" depends on "+driverItem.data,"form","info") driverItem.add_observer(item) end q=q[last .. q.length] end } end end #if modify or copy than we load the default items' data case @runmode when 'modify','copy','info' then itemdata=qrow(eeval("\"#{@querySQL}\""),true) end @items.each{|i| default_data=nil if itemdata then default_data=itemdata[i.data] if itemdata.has_key?(i.data) default_data=itemdata["#{@table}.#{i.data}"] if itemdata.has_key?("#{@table}.#{i.data}") else case i.type when 'gtk_combo','gtk_combo_wn','gtk_const_combo' then default_data="-1" else default_data="" end end i.item["initial"]=default_data } run_events(get_id,'form-OnUpdate') @items.each{|i| i.update(self,i.default_set? ? i.default : i.initial )} @built=true show_all set_page(get_conf(get_id,0,"page").to_i) if get_conf(get_id,0,"page") end
wysiwygf?()
click to toggle source
# File lib/FormHolder/Form.rb, line 78 def wysiwygf? form_holder.runmode == "wysiwygf" end