Last active
July 5, 2016 01:14
-
-
Save benoror/bd59a8e2839dd88e9a0adb2f7a660ead to your computer and use it in GitHub Desktop.
modal-message component pattern - part of post: https://medium.com/p/dc024bfa203c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const { | |
Component, | |
get, | |
set, | |
computed | |
} = Ember; | |
export default Component.extend({ | |
mainActionText: 'Ok', | |
mainActionPendingText: 'Ok', | |
secondActionText: 'Cancelar', | |
secondActionPendingText: 'Cancelar', | |
didReceiveAttrs() { | |
set(this, 'mainAction', get(this, 'close')); | |
set(this, 'secondAction', get(this, 'close')); | |
this.setProperties(get(this, 'options') || {}); | |
}, | |
showInput: computed('type', function() { | |
return get(this, 'type') === 'prompt'; | |
}), | |
showCancel: computed('type', function() { | |
const type = get(this, 'type'); | |
return type && type !== 'alert'; | |
}), | |
actions: { | |
triggerMainAction() { | |
const mainAction = get(this, 'mainAction'); | |
const type = get(this, 'type'); | |
if(type === 'prompt') { | |
mainAction(get(this, 'prompt')); | |
} else if(type === 'confirm') { | |
mainAction(true); | |
} | |
return get(this, 'close')(); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment