Skip to content

Instantly share code, notes, and snippets.

@amk221
Forked from olenderhub/components.nice-modal.js
Last active June 26, 2017 10:21
Show Gist options
  • Save amk221/1711d5cc82914f742abf06290602089a to your computer and use it in GitHub Desktop.
Save amk221/1711d5cc82914f742abf06290602089a to your computer and use it in GitHub Desktop.
oldernhub 2
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
save() {
this.get('onSave')(this.get('niceThing'));
},
close() {
this.get('onClose')(this.get('niceThing'));
}
}
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
name: attr('string')
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('main', { path: '/' }, function() {
this.route('nice-modal');
});
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.get('store').createRecord('nice-thing', {
name: 'Nice Thing 1'
});
},
actions: {
save(niceThing) {
console.log('saving', niceThing.toJSON());
},
rollback(routeName, niceThing) {
console.log('rolling back', niceThing.toJSON());
// If niceThing is new, rolling back will
// remove it from the store, which you don't want
// so, we only rollback if we are editing
// an existing niceThing, that has been changed.
if (!niceThing.get('isNew')) {
niceThing.rollbackAttributes();
}
// Close the modal
this.transitionTo(routeName);
}
}
});
Application
<br>
{{outlet}}
{{niceThing.name}}
<button onclick={{action 'save'}}>
Save
</button>
<button onclick={{action 'close'}}>
Close
</button>
<br>
Main
<br><br>
{{link-to 'Open main nice modal' 'main.nice-modal'}}
<br><br>
{{outlet}}
{{nice-modal
niceThing=model
onSave=(route-action 'save')
onClose=(route-action 'rollback' 'main')}}
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1",
"ember-route-action-helper": "2.0.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment