diff --git a/app/components/subscribe-to.js b/app/components/subscribe-to.js new file mode 100644 index 0000000..962025b --- /dev/null +++ b/app/components/subscribe-to.js @@ -0,0 +1,37 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + actions: { + subscribe: function() { + var that = this; + + var email = this.get("subscribeEmail"); + var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + + if (re.test(email)) { + $('.error').removeClass('show').addClass('hide'); + $('.success').removeClass('hide').addClass('show'); + + if(localStorage.subscribeEmail === undefined) { + var subscribeEmail = []; + var lastEmail = {'id': 1,'email': email}; + } else { + var subscribeEmail = JSON.parse(localStorage.subscribeEmail); + var arrayLength = subscribeEmail.length; + var lastEmail = {'id': ++arrayLength,'email': email}; + } + + subscribeEmail.push(lastEmail); + localStorage.subscribeEmail = JSON.stringify(subscribeEmail) + + setTimeout(function() { + that.set('subscribeEmail', ''); + $('.success').removeClass('show').addClass('hide'); + }, 1000); + + } else { + $('.error').removeClass('hide').addClass('show'); + } + } + } +}); diff --git a/app/controllers/job.js b/app/controllers/job.js index eb6a61a..c49c1b8 100644 --- a/app/controllers/job.js +++ b/app/controllers/job.js @@ -1,3 +1,53 @@ import Ember from 'ember'; -export default Ember.ObjectController.extend(); +export default Ember.ObjectController.extend({ + needs: ['jobs'], + + getJobs: function() { + var that = this; + + var jobs = this.store.find('jobs') + .then(function(data) { + that.set("jobs", data); + + var jobsLength = that.get("jobs.length"), + currentJob = parseInt(that.get("id")), + nextJob = currentJob+1, + prevJob = currentJob-1; + + that.get('jobs') + .forEach(function (job, index) { + + if(++index === currentJob){ + + if(index < jobsLength){ + that.set("nextPage", nextJob); + } else { + that.set("nextPage", false); + } + + if(index > 0){ + that.set("prevPage", prevJob); + } else { + that.set("prevPage", false); + } + + } + + }); + + }); + }.observes("model").on("init"), + + prevJob : function() { + if (this.get("prevPage") !== undefined) { + return this.store.find("jobs", this.get("prevPage")); + } + }.property("prevPage"), + + nextJob : function() { + if (this.get("nextPage") !== undefined) { + return this.store.find("jobs", this.get("nextPage")); + } + }.property("nextPage") +}); diff --git a/app/controllers/jobs.js b/app/controllers/jobs.js index dcee46a..571f926 100644 --- a/app/controllers/jobs.js +++ b/app/controllers/jobs.js @@ -8,7 +8,6 @@ export default Ember.ArrayController.extend({ filteredContent: function(){ var filterPrice = this.get('filterPrice'); - var selectedCity = this.get('selectedCity.city'); var city = this.get('arrangedContent'); var rx = new RegExp(selectedCity); diff --git a/app/styles/items.scss b/app/styles/items.scss index 64ea735..1b83f96 100644 --- a/app/styles/items.scss +++ b/app/styles/items.scss @@ -160,6 +160,13 @@ button:hover { } } +.hide { display: none; } +.show { display: block; } + +.messages { padding: 10px; margin-bottom: 20px; font-size: 18px; } +.error { background: #ffb4ad; color: #fff;} +.success { background: #E9F5DE; } + @media (max-width: 768px) { .on-email--blog, .add-job a { diff --git a/app/templates/components/subscribe-to.hbs b/app/templates/components/subscribe-to.hbs new file mode 100644 index 0000000..4f417b8 --- /dev/null +++ b/app/templates/components/subscribe-to.hbs @@ -0,0 +1,7 @@ +
+
Error!
+
Success!
+ + {{input type="text" classNames='my-email' value=subscribeEmail placeholder="ваш email"}} + +
diff --git a/app/templates/job.hbs b/app/templates/job.hbs index b3628cd..e190971 100644 --- a/app/templates/job.hbs +++ b/app/templates/job.hbs @@ -33,10 +33,7 @@
Нові вакансії на email
-
- - -
+ {{subscribe-to}}
diff --git a/app/templates/jobs.hbs b/app/templates/jobs.hbs index df8de74..3c88c20 100644 --- a/app/templates/jobs.hbs +++ b/app/templates/jobs.hbs @@ -26,6 +26,7 @@

{{#link-to 'job' this classNames="items-title" }}{{title}}{{/link-to}}

+
{{city}} {{price}} $ @@ -49,10 +50,7 @@
Нові вакансії на email
-
- - -
+ {{subscribe-to}}
diff --git a/package.json b/package.json index ee28f87..c9fed95 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "ember-data": "1.0.0-beta.12", "ember-export-application-global": "^1.0.0", "ember-flex-grid": "0.0.2", + "ember-localstorage-adapter": "^0.5.2", "express": "^4.8.5", "glob": "^4.0.5", "rimraf": "2.2.8" diff --git a/tests/unit/components/subscribe-to-test.js b/tests/unit/components/subscribe-to-test.js new file mode 100644 index 0000000..6d9b9bf --- /dev/null +++ b/tests/unit/components/subscribe-to-test.js @@ -0,0 +1,21 @@ +import { + moduleForComponent, + test +} from 'ember-qunit'; + +moduleForComponent('subscribe-to', 'SubscribeToComponent', { + // specify the other units that are required for this test + // needs: ['component:foo', 'helper:bar'] +}); + +test('it renders', function() { + expect(2); + + // creates the component instance + var component = this.subject(); + equal(component._state, 'preRender'); + + // appends the component to the page + this.append(); + equal(component._state, 'inDOM'); +});