Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there an easy way to make afformlet crm-editable? #15

Open
eileenmcnaughton opened this issue Apr 28, 2019 · 1 comment
Open

Is there an easy way to make afformlet crm-editable? #15

eileenmcnaughton opened this issue Apr 28, 2019 · 1 comment

Comments

@eileenmcnaughton
Copy link
Contributor

I have a very minor form - basic contact name details which I would like to make crm-editable. I'm wondering if there is an easy way / helper. I guess maybe I don't truly mean crm-editable as I'm undecided about instant edit vs edit + click a button

@eileenmcnaughton
Copy link
Contributor Author

eileenmcnaughton commented Jun 3, 2019

OK - I have it editable with xeditable. I am finding that to improve it I need a js save function to use rather than a directive as I want to use 'onPreSave' to do a form rather than field by field

  <div ng-if="!options.contact_id">
    {{ts('No contact id provided')}}
  </div>
  <div ng-if="options.contact_id"
       afform-api3="['Contact', 'getsingle', {id: options.contact_id, return: 'first_name,last_name,email, middle_name, display_name, contact_type'}]"
       afform-api3-ctrl="contact">
    <form name="basicContact"
      onaftersave="crmApi4('Contact','update', {
        'where' :[['id','=', options.contact_id]],
        'values' : {
          last_name: contact['result'].last_name,
          first_name: contact['result'].first_name,
          middle_name: contact['result'].middle_name,
          email: contact['result'].email
        }
     })"
     onhide="contact.refresh()"
     editable-form crm-ui-id-scope>
    <h1 class="basic-contact-heading" ng-show="!contact['result'].display_name">{{options.display_name}}</h1>
    <div><h1 class="basic-contact-heading" ng-bind="contact['result'].display_name">{{contact['result'].display_name}}</h1></div>
    <div>
    </div>
    <div><strong class="basic-contact-field">{{ ts('First Name') }}</strong>: <span editable-text="contact['result'].first_name">{{contact['result'].first_name || ".."}}</span></div>
    <div><strong class="basic-contact-field">{{ ts('Middle Name') }}</strong>:<a href='#' editable-text="contact['result'].middle_name">{{contact['result'].middle_name || ".."}}</a></div>
    <div><strong class="basic-contact-field">{{ ts('Last Name') }}</strong>: <span editable-text="contact['result'].last_name">{{contact['result'].last_name || ".."}}</span></div>

    <div><strong class="basic-contact-field">{{ts('Primary Email')}}</strong>: <span editable-text="contact['result'].email">{{contact['result'].email || ".."}}</span></div>
    <div><strong class="basic-contact-field">{{ts('Contact ID')}}</strong>: <a target="_blank" ng-if="options.contact_url" href="{{options.contact_url}}{{contact['result'].contact_id}}">{{contact['result'].id}}</a></div>

    <p></p>

    <div class="buttons">
      <!-- button to show form -->
      <button type="button" class="btn btn-default" ng-click="basicContact.$show()" ng-show="!basicContact.$visible">
        Edit
      </button>
      <!-- buttons to submit / cancel form -->
      <span ng-show="basicContact.$visible">
        <button ng-disabled="basicContact.$waiting" class="btn btn-secondary">{{ts('Save')}}</button>
        <button type="button" class="btn btn-default" ng-disabled="basicContact.$waiting" ng-click="basicContact.$cancel()">
          Cancel
        </button>
      </span>
    </div>
  <div ng-if="options.contact_id"
       afform-api3="['Contribution', 'get', {contact_id: options.contact_id, 'sequential': 1, return : 'receive_date', options: {limit: 1, sort: 'receive_date DESC'}}]"
       afform-api3-ctrl="contribution">
    <div ng-show="contribution.result.values[0]"><div>{{ ts('Last Contributed on')}}</div><div></div><strong>{{contribution.result.values[0].receive_date}}</strong></div></div>
  </form>
</div>


eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this issue Jun 3, 2019
From my digging xeditable seems like the main option for angular edit in place
https://vitalets.github.io/angular-xeditable/#overview

I think it makes sense to ship with core & sooner rather than later so we don't get
in muddles with different versions in extensions

My sample afform using this is here

totten/afform#15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant