diff --git a/.gitignore b/.gitignore index d7e0de8..5760b7f 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ server/*.js !app/assets/*/* +app/.idea/* +app/packages/demo/.idea/* diff --git a/Gruntfile.js b/Gruntfile.js index 26bc6e7..c2bc5ed 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -49,7 +49,7 @@ module.exports = function(grunt) { 'generators/**/*.coffee', 'server/*.coffee' ], - tasks: ['sass', 'coffee', 'server'] + tasks: ['coffee', 'server'] }, testacular: { diff --git a/app/app.coffee b/app/app.coffee index bc216e9..14b3321 100644 --- a/app/app.coffee +++ b/app/app.coffee @@ -2,7 +2,8 @@ define (require, exports, module) -> # Packages loading demoPackage = require 'packages/demo' - + orgteamPackage = require 'packages/org-team' + #Utils and other Utils = require 'shared/utils' @@ -17,6 +18,7 @@ define (require, exports, module) -> initialize: -> Utils.bindRoutes @, [ demoPackage.Controller + orgteamPackage.Controller ] unknownRoute: -> diff --git a/app/assets/css/main.css b/app/assets/css/main.css index 67ed738..e69de29 100644 --- a/app/assets/css/main.css +++ b/app/assets/css/main.css @@ -1,10 +0,0 @@ -body { - padding-top: 2px; - padding-bottom: 40px; } - -.table-users tbody td { - line-height: 36px; } -.table-users tfoot td.pagination-wrap { - background-color: #f8f8f8; } - .table-users tfoot td.pagination-wrap .pagination { - margin: 0px; } diff --git a/app/assets/json/orgs.json b/app/assets/json/orgs.json new file mode 100644 index 0000000..fa6a656 --- /dev/null +++ b/app/assets/json/orgs.json @@ -0,0 +1,20 @@ +[ + { + "id": 1, + "logo": "http://placehold.it/60x60", + "companyName": "Lohika", + "phone": "853-500-3367", + "email": "info@lohika.com", + "address": "37969, Alaska, Broome Streets", + "about": "Nulla sit tincidunt volutpat enim illum, autem ex iriure hendrerit iriure, volutpat eum vulputate diam. Luptatum, diam ad laoreet dolor commodo, ullamcorper dolore minim commodo ut, elit consequat iusto. Facilisi consequat, esse in vel iusto illum, eros dolor commodo consequat eum, vel dolore. Exerci euismod nisl, delenit ad blandit suscipit dolor, consectetuer dolore ad dolore." + }, + { + "id": 2, + "logo": "http://placehold.it/60x60", + "companyName": "Ciklum", + "phone": "841-471-3410", + "email": "info@ciklum.com", + "address": "28272, AmarilloAnaheim, Orchard Street", + "about": "Iusto et feugiat dolore dignissim minim, nulla dignissim molestie dolore dignissim, enim autem vulputate in. Vero, delenit vero commodo sit sed, qui blandit duis consequat vel, velit in et. Suscipit in, nonummy nonummy vulputate facilisis nonummy, at wisi ex duis qui, augue nisl. Velit consequat laoreet, zzril vel consectetuer magna duis, autem laoreet exerci amet nulla, sed. Ea ut dolor ut, wisi accumsan nulla et zzril, tation tation te facilisi zzril, autem sit amet at dolore, ad lobortis elit eros dolore, esse ex nostrud aliquip. Vel, accumsan at in odio diam." + } +] \ No newline at end of file diff --git a/app/config.coffee b/app/config.coffee index f136aaf..aaac348 100644 --- a/app/config.coffee +++ b/app/config.coffee @@ -40,5 +40,5 @@ require.config { 'sinon': 'assets/js/sinon-1.5.2' }, - packages: ['packages/demo', 'packages/organization'] + packages: ['packages/demo', 'packages/org-team'] } \ No newline at end of file diff --git a/app/packages/demo/main.coffee b/app/packages/demo/main.coffee index 46cac41..08adad2 100644 --- a/app/packages/demo/main.coffee +++ b/app/packages/demo/main.coffee @@ -6,13 +6,8 @@ define (require, exports, module)-> exports.Controller = class Controller extends BaseController routes: 'demo': 'demo' - 'demo/:id': 'demo' demo: -> console.log 'demo' - @currentView = new view.View( - model: new model.Model() - ) - $('#demo-box').html @currentView.render().$el return @ return diff --git a/app/packages/org-team/collections/collection.coffee b/app/packages/org-team/collections/collection.coffee new file mode 100644 index 0000000..2482542 --- /dev/null +++ b/app/packages/org-team/collections/collection.coffee @@ -0,0 +1,9 @@ +define (require, exports, module) -> + model = require '../models/model' + exports.Collection = Backbone.Collection.extend( + url: -> + '/org' + + model: model.Model + ) + return \ No newline at end of file diff --git a/app/packages/org-team/main.coffee b/app/packages/org-team/main.coffee new file mode 100644 index 0000000..0d33153 --- /dev/null +++ b/app/packages/org-team/main.coffee @@ -0,0 +1,27 @@ +define (require, exports, module)-> + orgsView = require './views/organizations' + orgView = require './views/organization' + BaseController = require 'shared/base_controller' + + exports.Controller = class Controller extends BaseController + routes: + 'org-team': 'getOrgsTeam' + 'org-team/:id': 'getOrgTeam' + + getOrgsTeam: -> + @orgsView = new orgsView.View + @orgsView.collection.fetch + success: (collection, resp, options) => + console.dir(collection) + $('#demo-box').html @orgsView.render().el + return @ + + getOrgTeam: (id)-> + @orgView = new orgView.View() + @orgView.model.set {id: id} + @orgView.model.fetch + success: (model, resp, options) => + $('#demo-box').html @orgView.render().el + return @ + + return \ No newline at end of file diff --git a/app/packages/org-team/models/model.coffee b/app/packages/org-team/models/model.coffee new file mode 100644 index 0000000..3cef906 --- /dev/null +++ b/app/packages/org-team/models/model.coffee @@ -0,0 +1,14 @@ +define (require, exports, module) -> + exports.Model = Backbone.Model.extend( + url: -> + "/org/#{@id}" + + defaults: + logo: "http://placehold.it/32x32", + companyName: "Test company name", + phone: "", + email: "", + address: "", + about: "" + ) + return \ No newline at end of file diff --git a/app/packages/org-team/spec/collection.coffee b/app/packages/org-team/spec/collection.coffee new file mode 100644 index 0000000..bb6282a --- /dev/null +++ b/app/packages/org-team/spec/collection.coffee @@ -0,0 +1,12 @@ +expect = chai.expect + +describe 'Test', -> + dep = null + + beforeEach (done) -> + require [], (_dep) -> + dep = _dep + done() + + it 'should be test', (done) -> + done() \ No newline at end of file diff --git a/app/packages/org-team/spec/main.coffee b/app/packages/org-team/spec/main.coffee new file mode 100644 index 0000000..bb6282a --- /dev/null +++ b/app/packages/org-team/spec/main.coffee @@ -0,0 +1,12 @@ +expect = chai.expect + +describe 'Test', -> + dep = null + + beforeEach (done) -> + require [], (_dep) -> + dep = _dep + done() + + it 'should be test', (done) -> + done() \ No newline at end of file diff --git a/app/packages/org-team/spec/model.coffee b/app/packages/org-team/spec/model.coffee new file mode 100644 index 0000000..bb6282a --- /dev/null +++ b/app/packages/org-team/spec/model.coffee @@ -0,0 +1,12 @@ +expect = chai.expect + +describe 'Test', -> + dep = null + + beforeEach (done) -> + require [], (_dep) -> + dep = _dep + done() + + it 'should be test', (done) -> + done() \ No newline at end of file diff --git a/app/packages/org-team/spec/view.coffee b/app/packages/org-team/spec/view.coffee new file mode 100644 index 0000000..bb6282a --- /dev/null +++ b/app/packages/org-team/spec/view.coffee @@ -0,0 +1,12 @@ +expect = chai.expect + +describe 'Test', -> + dep = null + + beforeEach (done) -> + require [], (_dep) -> + dep = _dep + done() + + it 'should be test', (done) -> + done() \ No newline at end of file diff --git a/app/packages/org-team/templates/organization.html b/app/packages/org-team/templates/organization.html new file mode 100644 index 0000000..ccba4cf --- /dev/null +++ b/app/packages/org-team/templates/organization.html @@ -0,0 +1,24 @@ +
+

<%= org.companyName%>

+
+
+
+
+
+ <%= org.companyName%> +
+
+
    +
  • Phone: <%= org.phone%>
  • +
  • Email: <%= org.email%>
  • +
  • Address: <%= org.address%>
  • +
+
+
+
+
+
+ <%= org.about%> +
+
+
\ No newline at end of file diff --git a/app/packages/org-team/templates/organizations.html b/app/packages/org-team/templates/organizations.html new file mode 100644 index 0000000..87a3ab3 --- /dev/null +++ b/app/packages/org-team/templates/organizations.html @@ -0,0 +1,12 @@ +
+

Organizations

+
+
+ +
+
+
\ No newline at end of file diff --git a/app/packages/org-team/views/organization.coffee b/app/packages/org-team/views/organization.coffee new file mode 100644 index 0000000..88fc918 --- /dev/null +++ b/app/packages/org-team/views/organization.coffee @@ -0,0 +1,16 @@ +define (require, exports, module)-> + tpl = require 'text!../templates/organization.html' + model = require '../models/model' + + exports.View = Backbone.View.extend( + template: _.template tpl + model: new model.Model + + initialize: -> + + render: ()-> + @$el.html @template({org: @model.toJSON()}) + return @ + + ) + return \ No newline at end of file diff --git a/app/packages/org-team/views/organizations.coffee b/app/packages/org-team/views/organizations.coffee new file mode 100644 index 0000000..edd8ba8 --- /dev/null +++ b/app/packages/org-team/views/organizations.coffee @@ -0,0 +1,15 @@ +define (require, exports, module)-> + tpl = require 'text!../templates/organizations.html' + collection = require '../collections/collection' + + exports.View = Backbone.View.extend( + template: _.template tpl + collection: new collection.Collection + + initialize: -> + + render: -> + @$el.html @template(listOrg: @collection.toJSON()) + return @ + ) + return \ No newline at end of file diff --git a/app/server.coffee b/app/server.coffee index 511cf85..91ee1b0 100644 --- a/app/server.coffee +++ b/app/server.coffee @@ -2,8 +2,11 @@ define (require, exports, module) -> require('sinon') - json = - users: JSON.parse require 'text!assets/json/users.json' + + json = { + users: JSON.parse require 'text!assets/json/users.json' + orgs: JSON.parse require 'text!assets/json/orgs.json' + } _buildResponse = (content, status = 200) -> [ @@ -41,6 +44,19 @@ define (require, exports, module) -> response = _buildResponse JSON.stringify(data), status xhr.respond.apply xhr, response + _getOrg = (xhr, id) -> + org = null + id = parseInt id + org = _(json.orgs).findWhere {id: id} + if org + data = org + status = 200 + else + data = {error: 'Organization not found'} + status = 404 + response = _buildResponse JSON.stringify(data), status + xhr.respond.apply xhr, response + _getUsers = (xhr, queryString) -> params = getQuerySringParams xhr.url items = json.users.concat (_createUser id for id in [20..100]) @@ -65,6 +81,11 @@ define (require, exports, module) -> then 'AUTO_PUBLISH' else 'MODERATE TOUTS' + _getOrgs = (xhr) -> + data = JSON.stringify(json.orgs) + response = _buildResponse data + xhr.respond.apply xhr, response + requests = [ { method: 'GET' @@ -81,6 +102,16 @@ define (require, exports, module) -> route: /\/organization\/user\/(\d+)/ response: _getUser } + { + method: 'GET' + route: '/org' + response: _getOrgs + } + { + method: 'GET' + route: /\/org\/(\d+)/ + response: _getOrg + } ] for req in requests then do (req) -> diff --git a/generators/package/main.coffee.hbs b/generators/package/main.coffee.hbs index 0df217a..4099685 100644 --- a/generators/package/main.coffee.hbs +++ b/generators/package/main.coffee.hbs @@ -4,6 +4,6 @@ define (require, exports, module)-> BaseController = require 'shared/base_controller' exports.Controller = class Controller extends BaseController - routes: + routes:[] return \ No newline at end of file diff --git a/package.json b/package.json index 40c991b..d457b17 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,8 @@ "node": "~0.6.10 || 0.8 || 0.9" }, "scripts": { - "test": "node_modules/.bin/testacular start tests/testacular-config.js --single-run --browsers=PhantomJS", - "start": "node_modules/.bin/grunt run" + "test": "node_modules\\.bin\\testacular start tests\\testacular-config.js --single-run --browsers=PhantomJS", + "start": "node_modules\\.bin\\grunt run" }, "dependencies": {}, "devDependencies": {