Class: Form
- Inherits:
-
React::Component::Base
- Object
- React::Component::Base
- Form
show all
- Includes:
- MNotification
- Defined in:
- lib/bull/ui_core.rb
Instance Method Summary
collapse
notification_controller=, #notifications, notifications, #notify_error, #notify_info, #notify_ok
Instance Method Details
#change_attr(attr) ⇒ Object
609
610
611
612
613
614
615
616
617
|
# File 'lib/bull/ui_core.rb', line 609
def change_attr(attr)
lambda do |value|
@dirty.add attr
doc = state.__send__(attr.split('.')[0])
set_nested(attr, value, doc){|r, v| state.__send__(r+'!', v)}
state.__send__('dirty_' + attr.gsub('.', '_') + '!', true)
state.dirty! true
end
end
|
#clear_dirty ⇒ Object
640
641
642
643
|
# File 'lib/bull/ui_core.rb', line 640
def clear_dirty
@dirty.each {|attr| state.__send__('dirty_' + attr.gsub('.', '_')+'!', false)}
@dirty.clear
end
|
#dirty? ⇒ Boolean
591
592
593
|
# File 'lib/bull/ui_core.rb', line 591
def dirty?
!@dirty.empty?
end
|
#discard ⇒ Object
645
646
647
648
649
650
651
652
653
|
# File 'lib/bull/ui_core.rb', line 645
def discard
@selected.value = nil
clear
clear_dirty
state.discard! false
state.dirty! false
end
|
#expand_attr(hsh = {}) ⇒ Object
595
596
597
598
599
600
601
602
603
604
605
606
607
|
# File 'lib/bull/ui_core.rb', line 595
def expand_attr(hsh={})
lambda do |value|
value.each_pair do |k, v|
if !hsh[k].nil?
k = hsh[k]
end
@dirty.add k
state.__send__(k+'!', v)
state.__send__('dirty_' + k + '!', true)
state.dirty! true
end
end
end
|
#get(selected) ⇒ Object
686
687
688
689
690
691
692
693
694
695
696
697
698
699
|
# File 'lib/bull/ui_core.rb', line 686
def get selected
@selected = selected
selected.add_form self
@rvs = reactive(selected) do
@dirty.each {|attr| state.__send__('dirty_' + attr+'!', false)}
@dirty.clear
clear
$controller.rpc('get_' + @@table, selected.value).then do|response|
response.each do |k, v|
state.__send__(k+'!', v)
end
end
end
end
|
#get_unique(kw) ⇒ Object
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
|
# File 'lib/bull/ui_core.rb', line 701
def get_unique kw
k, selected = kw.shift
@selected = selected
selected.add_form self
@rvs = reactive(selected) do
@dirty.each {|attr| state.__send__('dirty_' + attr+'!', false)}
@dirty.clear
clear
$controller.rpc('get_unique_' + @@table, k, selected.value).then do|response|
response.each do |k, v|
state.__send__(k+'!', v)
end
end
end
end
|
#hash_from_state ⇒ Object
619
620
621
622
623
624
625
626
627
628
|
# File 'lib/bull/ui_core.rb', line 619
def hash_from_state
ret = {}
@dirty.each do |attr|
get_nested!(ret, attr) {|r| state.__send__(r)}
end
@@constants.each do |cte|
get_nested!(ret, cte) {|r| params.__send__(r)}
end if @@constants
ret
end
|
#insert ⇒ Object
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
|
# File 'lib/bull/ui_core.rb', line 655
def insert
$controller.insert(@@table, hash_from_state).then do |response|
if response.nil?
notify_error 'form: data not inserted', 1
else
params.selected.value = response
notify_ok 'form: data inserted', 1
end
end
clear_dirty
end
|
#save ⇒ Object
630
631
632
633
634
635
636
637
638
|
# File 'lib/bull/ui_core.rb', line 630
def save
if state.id
update
else
insert
end
state.discard! false
state.dirty! false
end
|
#update ⇒ Object
671
672
673
674
675
676
677
678
679
680
681
682
683
684
|
# File 'lib/bull/ui_core.rb', line 671
def update
$controller.update(@@table, state.id, hash_from_state).then do |count|
if count == 0
notify_error 'form: data not updated', 1
elsif count == 1
notify_ok 'form: data updated', 1
end
end
clear_dirty
end
|