Class: Myform::MyFormHolder

Inherits:
Object
  • Object
show all
Includes:
Conf, ManqodCommon, Myform, Observable
Defined in:
lib/FormHolder.rb

Defined Under Namespace

Classes: EmbeddedFormHolder

Constant Summary

Constants included from ManqodCommon

ManqodCommon::CRITICAL, ManqodCommon::DEBUG, ManqodCommon::ERROR, ManqodCommon::INFO, ManqodCommon::NORMAL, ManqodCommon::WARNING

Constants included from Eprint

Eprint::DOMAIN, Eprint::LEVEL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ManqodCommon

#add_where, #admin, #admin_cache, #admin_qrow, #admin_rows, #backtrace_to_debug, #cache, #changed_ids_of_base, #client, #client_fields, #client_image_of_id, #client_qrow, #client_query, #client_rows, #eeval, #escape_string, #getBinding, #guess_base, #guess_table, #image_of_id, #lzero, #manqod_db, #measure, #myexec, #nick, #nick_id, #number_format, #qrow, #query, #reconnect_manqod_db, #rows, #run_events, #send_message, #sendmail, #set_manqod_db_uri, #set_nick

Methods included from Eprint

#ecode, #edebug, #eerror, #einfo, #enormal, #eprint, #ewarn, #gtk_set_edebug, #set_edebug, #tell_exception

Methods included from Conf

#get_conf, #load_conf, #save_conf, #set_conf

Constructor Details

#initialize(mode = "dialog", caller = self, runmode = nil, form_id = nil) ⇒ MyFormHolder

Returns a new instance of MyFormHolder.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/FormHolder.rb', line 38

def initialize(mode="dialog",caller=self,runmode=nil,form_id=nil)
		@form_id=form_id
@caller=caller
@runmode=runmode
@form=Myform::MyForm.new(self,form_id,runmode)
case mode
	when "embedded"
		@holder=EmbeddedFormHolder.new(self)

 	when "dialog"
		#run in dialog window
#				form.set_id(caller.target)
		@holder=Gtk::Dialog.new().set_resizable(true)#.set_transient_for(@caller.get_ancestor(Gtk::Window))#.set_modal(true)
		#press calcel or close if user closes the window
		holder.signal_connect("delete-event"){|me,ev| if info? || wysiwyg? then @closeb.activate; else @cancel.activate; end }

		#restoring the saved width,height/top,bottom positions
		unless wysiwyg?
			if w=get_conf(form.get_id,0,"width") and h=get_conf(form.get_id,0,"height") then holder.resize(w.to_i,h.to_i) end
			if x=get_conf(form.get_id,0,"x") and y=get_conf(form.get_id,0,"y") then holder.move(x.to_i,y.to_i) end
			#save form dimensions and position when user resizes
			holder.signal_connect("configure-event"){|me,event|
				set_conf(form.get_id,0,"width",event.width.to_s)
				set_conf(form.get_id,0,"height",event.height.to_s)
				set_conf(form.get_id,0,"x",event.x.to_s)
				set_conf(form.get_id,0,"y",event.y.to_s)
 				false
			}
		end
		form_accel_group= Gtk::AccelGroup.new
		form_accel_group.connect(Gdk::Keyval::GDK_KEY_Return,Gdk::Window::CONTROL_MASK ,Gtk::ACCEL_VISIBLE){
  		if info? || wysiwyg? then @closeb.activate; else @ok.activate; end
		}
		form_accel_group.connect(Gdk::Keyval::GDK_KEY_Escape,nil ,Gtk::ACCEL_VISIBLE){
			if info? || wysiwyg? then @closeb.activate; else @cancel.activate; end
		}
		holder.add_accel_group(form_accel_group)
		@form.set_ag(form_accel_group)

		#adding the Form Buttons
		holder.vbox.pack_start(form,true,true,0)
		if info? || wysiwyg?
			@closeb=holder.add_button('',Gtk::Dialog::RESPONSE_CLOSE).set_image(Gtk::Image.new(Gtk::Stock::CLOSE,Gtk::IconSize::SMALL_TOOLBAR)).set_label('close').set_relief(Gtk::ReliefStyle::NONE)
  		else
  		@apply=holder.add_button('',Gtk::Dialog::RESPONSE_APPLY).set_image(Gtk::Image.new(Gtk::Stock::APPLY,Gtk::IconSize::SMALL_TOOLBAR)).set_label('apply').set_relief(Gtk::ReliefStyle::NONE) unless @form.gtk_attribute("apply_button")=="false"
  		@ok=holder.add_button('',Gtk::Dialog::RESPONSE_OK).set_image(Gtk::Image.new(Gtk::Stock::OK,Gtk::IconSize::SMALL_TOOLBAR)).set_label('ok').set_relief(Gtk::ReliefStyle::NONE) unless @form.gtk_attribute("ok_button")=="false"
  		@cancel=holder.add_button('',Gtk::Dialog::RESPONSE_CANCEL).set_image(Gtk::Image.new(Gtk::Stock::CANCEL,Gtk::IconSize::SMALL_TOOLBAR)).set_label('cancel').set_relief(Gtk::ReliefStyle::NONE)
		end
		holder.set_default_response(0)
		#holder.realize;holder.window.set_functions(Gdk::Window::WMFunction::ALL | Gdk::Window::WMFunction::CLOSE)

	when "touchscreen"
		@holder=Gtk::VBox.new
		@form.modify_bg(Gtk::STATE_NORMAL,Gdk::Color.new(65000, 0, 0))
		@form.items.each{|item| 
  		item.modify_bg(Gtk::STATE_NORMAL,Gdk::Color.new(0,65000, 0))
  		item.renderer.modify_bg(Gtk::STATE_NORMAL,Gdk::Color.new(0,35000, 0))
		}
		@holder.modify_bg(Gtk::STATE_NORMAL,Gdk::Color.new(0, 0, 65000))
		@holder.pack_start(@form,true,true)
		set_parentM(self)
 	else ewarn("not recognized form run mode: #{mode}","form")
end
end

Instance Attribute Details

#callerObject

Returns the value of attribute caller.



102
103
104
# File 'lib/FormHolder.rb', line 102

def caller
  @caller
end

#formObject

Returns the value of attribute form.



102
103
104
# File 'lib/FormHolder.rb', line 102

def form
  @form
end

#holderObject

Returns the value of attribute holder.



102
103
104
# File 'lib/FormHolder.rb', line 102

def holder
  @holder
end

#runmodeObject

Returns the value of attribute runmode.



102
103
104
# File 'lib/FormHolder.rb', line 102

def runmode
  @runmode
end

Instance Method Details

#add?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/FormHolder.rb', line 159

def add?
	runmode == "add"
end

#destroyObject



196
197
198
199
# File 'lib/FormHolder.rb', line 196

def destroy
	@form.destroy unless @form.nil? or @form.destroyed?
	@holder.destroy unless @holder.nil? or @holder.destroyed?
end

#embedd?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/FormHolder.rb', line 108

def embedd?
	@form.embedd?
end

#get_ancestor(classname) ⇒ Object



172
173
174
# File 'lib/FormHolder.rb', line 172

def get_ancestor(classname)
	@caller.get_ancestor(classname)
end

#info?Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/FormHolder.rb', line 162

def info?
	runmode == "info"
end

#is_embeddedObject



104
105
106
# File 'lib/FormHolder.rb', line 104

def is_embedded
	@form.is_embedded
end

#parentMObject



165
166
167
# File 'lib/FormHolder.rb', line 165

def parentM
@parent_moditem
end

#run(pid = @form.parentselected, batch = nil) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/FormHolder.rb', line 112

def run(pid=@form.parentselected,batch=nil)
	@form.parentselected=pid
	@form.batch=@form.batch_support? && batch.class == Array && batch.size>1 ? batch : nil
	batch=@form.batch_support? && batch.class == Array ? batch : [@form.parentselected]

ret=-1
if @holder
begin
		manqod_db.lock_id_of_base(@form.table,batch) unless add? || wysiwyg?
	@form.update(@caller)
 	ret=-1 #ha ret 0, akkor nem volt valtozas, ha -1, akkor hiba volt, ha >0, akkor az a parentid (addnal van hasznalva asszem, pozicionalasra)
 	while ret<0
		case response=@holder.run
			when Gtk::Dialog::RESPONSE_OK then #ok
				ret=@form.apply_changes(self).to_i
				einfo("apply_changes return: #{ret}","form")
				@caller.caller.list.save_cursor_id(ret) if @caller.class.name == 'MyButton'
			when Gtk::Dialog::RESPONSE_CANCEL, Gtk::Dialog::RESPONSE_CLOSE, Gtk::Dialog::RESPONSE_DELETE_EVENT then
				ret=0
			when Gtk::Dialog::RESPONSE_APPLY then #apply
				ret=@form.apply_changes(self).to_i
				manqod_db.unlock_id_of_base(@form.table,batch.push(ret)) unless pid == ret
				einfo("apply_changes return: #{ret}","form")
				@caller.caller.list.scroll_to_cursor(ret) if @caller.class.name == 'MyButton'
					manqod_db.lock_id_of_base(@form.table,ret) unless wysiwyg?
				update(@caller,ret,"modify") if ["add","copy"].include?(@form.runmode)
				ret=-1
			else eerror("unknown form return code: #{response}")
		end
		client.reload_moditem(@form_id) if wysiwyg? #if wysiwyg then reload it in server
 	end
 	@holder.destroy
 	rescue =>err
 		warn("Form error: #{err}",backtrace_to_debug(err),"form","error",false,true,err.to_s)
 	ensure
 		begin
 			manqod_db.unlock_id_of_base(@form.table,batch)
 			rescue => err
 			eerror("Form ensured unlock error: #{err}\n#{err.backtrace.join("\n")}","form")
 		end
 	end
end
ret
end

#set_parentM(parent_moditem) ⇒ Object



168
169
170
171
# File 'lib/FormHolder.rb', line 168

def set_parentM(parent_moditem)
@parent_moditem=parent_moditem
self
end

#show_allObject



184
185
186
187
# File 'lib/FormHolder.rb', line 184

def show_all
	@holder.show_all
	self.run if @runmode=="dialog"
end

#titleObject



192
193
194
# File 'lib/FormHolder.rb', line 192

def title
	"no title"
end

#to_sObject



175
176
177
# File 'lib/FormHolder.rb', line 175

def to_s
	"FormHolder of #{form}"
end

#update(notifier, pid = @form.parentselected, rm = @form.runmode) ⇒ Object



178
179
180
181
182
183
# File 'lib/FormHolder.rb', line 178

def update(notifier,pid=@form.parentselected,rm=@form.runmode)
if pid
		manqod_db.lock_id_of_base(@form.table,pid) unless add? || wysiwyg?
	@form.update(notifier,pid,rm)
	end
end

#vshrink(d) ⇒ Object



189
190
191
# File 'lib/FormHolder.rb', line 189

def vshrink(d)
holder.allocation.set_height(holder.allocation.height-d.to_i)
end

#wysiwyg?Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/FormHolder.rb', line 156

def wysiwyg?
	runmode == "wysiwygf"
end