-
-
Save kenelliott/b96fec30d9c02703b06b to your computer and use it in GitHub Desktop.
AutoFocus Component
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'; | |
export default Ember.Route.extend({ | |
init() { | |
this._super(...arguments); | |
$.mockjax({ | |
url: '/api/mock', | |
type: "POST", | |
status: 422, | |
responseText: { | |
errors: { | |
first_name: "is required" | |
} | |
} | |
}); | |
}, | |
model() { | |
return $.getJSON('/api/mock'); | |
} | |
}); |
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'; | |
export default Ember.Controller.extend({ | |
appName:'Ember Twiddle' | |
}); |
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, observer, computed, $} = Ember; | |
/** | |
* Displays inputs for a percentage and a flat amount | |
* | |
* @class FlatPercentageInputs | |
* @namespace Components | |
*/ | |
export default Component.extend({ | |
/** | |
* Is set to the percentage/flat discount type | |
* | |
* @property discountType | |
* @type {String} | |
* @default null | |
*/ | |
discountType: null, | |
didInitAttrs() { | |
console.log('didReceiveAttrs'); | |
this.setAmount(this.get('discountAmount'), this.get('discountType')); | |
}, | |
/** | |
* Used to for the value of the flat discount input | |
* | |
* @property discountFlat | |
* @type {Number} | |
* @default null | |
*/ | |
discountFlat: null, | |
/** | |
* Used to for the value of the percent discount input | |
* | |
* @property discountPercent | |
* @type {Number} | |
* @default null | |
*/ | |
discountPercentage: null, | |
/** | |
* The value for the flat/percentage input is set into this property | |
* | |
* @property discountAmount | |
* @type {Number} | |
* @default null | |
*/ | |
discountAmount: null, | |
setAmount(amount, type) { | |
console.log('setAmount', ...arguments); | |
if(type === 'percentage') { | |
this.setProperties({ | |
discountType: 'percentage', | |
discountPercentage: amount, | |
discountFlat: null | |
}); | |
} else { | |
this.setProperties({ | |
discountType: 'flat', | |
discountFlat: amount, | |
discountPercentage: null | |
}); | |
} | |
}, | |
actions: { | |
changeAmount(amount, event) { | |
console.log('action fired'); | |
if($(event.target).hasClass('js-percentage')) { | |
this.setAmount(amount, 'percentage'); | |
console.log('percentage'); | |
} else { | |
this.setAmount(amount, 'flat'); | |
console.log('flat'); | |
} | |
} | |
} | |
}); |
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 {TextField, on} = Ember; | |
/** | |
* Extends the TextField component by setting the focus to the current input | |
* when it is inserted | |
* | |
* @class FocusInput | |
* @namespace Components | |
*/ | |
export default TextField.extend({ | |
/** | |
* Sets the focus on the current element when inserted | |
* | |
* @method setAutofocus | |
*/ | |
setAutofocus: on('didInsertElement', function() { | |
this.$().focus(); | |
}) | |
}); |
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'; | |
import config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: config.locationType | |
}); | |
Router.map(function() { | |
this.resource('widgets'); | |
this.resource('fidgets'); | |
}); | |
export default Router; |
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
{ | |
"version": "0.4.8", | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.13/ember.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.13/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.8/ember-template-compiler.js", | |
"jquery-mockjax": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment