Skip to content

Instantly share code, notes, and snippets.

@vigneshrajarr
Created June 12, 2018 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vigneshrajarr/c928e3c123a556c7a55da1fc8ee0cc90 to your computer and use it in GitHub Desktop.
Save vigneshrajarr/c928e3c123a556c7a55da1fc8ee0cc90 to your computer and use it in GitHub Desktop.
StackOverFlow - ember rollback attributes when user cancel the edit action
import Ember from 'ember';
export default Ember.Component.extend({
actions:{
saveDetails : function(){
this.sendAction("saveModel");
},
cancelEdit:function(){
this.sendAction("cancelModel");
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
iseditmode : false,
actions:{
editDetails : function(){
this.set("iseditmode",true);
},
saveDetails:function(){
this.get("model").save();
},
cancelEdit : function(){
this.get("model").rollbackAttributes();
}
}
});
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';
export default Model.extend({
});
import Ember from 'ember';
export default Ember.Route.extend({
model:function(){
return [{firstname:"Vignesh",lastname:"Raja",place:"TamilNadu",company:"Zoho"}];
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
Firstname : {{model.firstname}}<br>
Lastname : {{model.lastname}}<br>
Place : {{model.place}}<br>
Company : {{model.company}}<br>
<button {{action "editDetails"}}>Edit Details</button>
<br><br>
{{#if iseditmode}}
{{edit-details details=model saveModel="saveDetails" cancelModel="cancelEdit"}}
{{/if}}
<fieldset>
{{input type=text value=details.firstname}}
{{input type=text value=details.lastname}}
{{input type=text value=details.place}}
{{input type=text value=details.company}}
<br><br>
<button {{action "saveDetails"}}>Save Details</button>
<button {{action "cancelEdit"}}>Cancel</button>
</fieldset>
{
"version": "0.14.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": true
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "2.18.2",
"ember-template-compiler": "2.18.2",
"ember-testing": "2.18.2"
},
"addons": {
"ember-data": "2.18.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment