diff --git a/app/components/project/modals/edit-instance-action.coffee b/app/components/project/modals/edit-instance-action.coffee index fc625c2..3e8037e 100644 --- a/app/components/project/modals/edit-instance-action.coffee +++ b/app/components/project/modals/edit-instance-action.coffee @@ -10,7 +10,7 @@ export default ModalBase.extend new_note_content: '' new_note_content_is_blank: Ember.computed.not 'new_note_content.length' has_uncompleted_constraints: false - attached_instance_action_connections: [] + #attached_instance_action_connections: [] attached_conditions_not_met_warning: '' can_edit_action: Ember.computed 'model.workflow_action_definition.organization.users.[]', -> @@ -44,23 +44,27 @@ export default ModalBase.extend @set 'number_value', @get('model.number_value') @set 'text_value', @get('model.text_value') @set 'timestamp_value', @get('model.timestamp_value') - @set 'attached_instance_action_connections', [] - @set 'attached_conditions_not_met_warning', '' # important te reset since attached actions can be completed on re-open of parent - @get('model.pointing_project_instance_action_connections').forEach (pointing_connection) => - if pointing_connection.get('connection_type') is 'constraint' and not @get('has_uncompleted_constraints') - @set 'has_uncompleted_constraints', true unless pointing_connection.get('project_instance_action.completed') - if pointing_connection.get('connection_type') is 'attached' - if conditional_value = pointing_connection.get('conditional_base_value') - switch @get('model.workflow_action_definition.value_type') - when 'boolean' - 3 - when 'select' - @get('attached_instance_action_connections').pushObject pointing_connection if conditional_value is @get('string_value') + #@set 'attached_instance_action_connections', [] + # set this action here to be able to propagate the save callback. This makes double nested attached actions work smoothly + @set 'actions.open_current_modal', -> @modal 'project/edit-instance-action', model: @get('model'), save: @get('modal_options.save') - else - # always display non conditional attached actions - @get('attached_instance_action_connections').pushObject pointing_connection - #@get('pointing_project_instance_action_connections').forEach (pointing_connection) -> + # constraints setup + #@set 'attached_conditions_not_met_warning', 'validating attached actions...' # important te reset since attached actions can be completed on re-open of parent + @set 'attached_conditions_not_met_warning', '' + @set 'has_uncompleted_constraints', false + base = @ + @get('model.pointing_project_instance_action_connections').then (pointing_connections) => + pointing_connections.forEach (pointing_connection) -> + return if base.get('has_uncompleted_constraints') # already found, no need to search further + pointing_connection.get('project_instance_action').then (pointing_project_instance_action) -> + return if pointing_project_instance_action.get('completed') + if pointing_connection.get('connection_type') is 'constraint' + return base.set 'has_uncompleted_constraints', true + if pointing_connection.get('connection_type') is 'attached' + if conditional_value = pointing_connection.get('conditional_base_value') + if base.get('model.workflow_action_definition.value_type') isnt 'select' or conditional_value is base.get('model.string_comparison_value') + pointing_project_instance_action.get('workflow_action_definition').then (pointing_workflow_action_definition) -> + base.set 'attached_conditions_not_met_warning', "#{pointing_workflow_action_definition.get('title')} not completed" select_class_names: Ember.computed 'model.string_value', -> return ['green'] @@ -80,7 +84,7 @@ export default ModalBase.extend #@set attribute, value # internal setting for validation @set 'action_value', value @set "model.#{attribute}", value - @send 'saveRecord' + @send 'validate_and_progress' set_string_value: -> @send 'set_value', 'string_value', @get('string_value') @@ -98,8 +102,6 @@ export default ModalBase.extend Ember.$('body').off('keyup.modal-dialog') @_super arguments... - open_current_modal: -> @modal 'project/edit-instance-action', model: @get('model') - continue_from_inquiry: -> record = @get('model') if target_date = @get('model.target_date') @@ -109,6 +111,7 @@ export default ModalBase.extend record.set 'state', state record.save().then -> record.get('events').reload() + add_new_note: -> return unless content = @get('new_note_content') now = moment() @@ -122,6 +125,7 @@ export default ModalBase.extend @get('model.events').pushObject new_note_event @set 'new_note_content', '' #@send 'close' + start_inquiry: -> record = @get('model') record.set 'state', 'inquiry' @@ -129,7 +133,8 @@ export default ModalBase.extend #record.save().then -> # record.get('events').reload() - saveRecord: -> + validate_and_progress: -> + # these validations are only needed for select value_type actions, since all the others have no dynamic values that will limit the progress all_attached_actions_are_valid = true @set 'attached_conditions_not_met_warning', '' @get('model.pointing_project_instance_action_connections').forEach (pointing_connection) => @@ -139,4 +144,4 @@ export default ModalBase.extend @set 'attached_conditions_not_met_warning', "#{pointing_connection.get('project_instance_action.workflow_action_definition.title')} not completed" all_attached_actions_are_valid = false #alert 'Attached not completed' - @_super arguments... if all_attached_actions_are_valid + @send('saveRecord') if all_attached_actions_are_valid diff --git a/app/templates/project/-edit-instance-action.emblem b/app/templates/project/-edit-instance-action.emblem index aee3cf2..aa75936 100644 --- a/app/templates/project/-edit-instance-action.emblem +++ b/app/templates/project/-edit-instance-action.emblem @@ -52,7 +52,8 @@ table.ui.top.attached.compact.definition.table if (eq value_type 'text') .ui.bottom.attached.segment = textarea value=text_value -each attached_instance_action_connections as |attached_instance_action_connection| + +/each attached_instance_action_connections as |attached_instance_action_connection| .ui.horizontal.divider span Attached action = attached_instance_action_connection.project_instance_action.workflow_action_definition.title @@ -86,7 +87,7 @@ table.ui.top.attached.compact.definition.table .modal-actions.sticky /button.ui.primary.button.modal-save.pull-right{action "saveRecord"}= t 'general.save' /button.ui.negative.button.modal-destroy.pull-right{action "destroyRecord"}= t 'general.destroy.button' - if can_edit_action + if (and can_edit_action model.pointing_project_instance_action_connections.isFulfilled) if (eq model.state 'inquiry') button.ui.pink.button.pull-right{action 'continue_from_inquiry'}= t 'action_list.continue_from_inquiry' else