Skip to content

Commit

Permalink
fixed the many to many data bindings and views
Browse files Browse the repository at this point in the history
  • Loading branch information
jredd committed Dec 9, 2014
1 parent f24740f commit d642677
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 30 deletions.
49 changes: 33 additions & 16 deletions redd/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ <h3>{{name}}</h3>
<li>Status: Inactive<span class="is_inactive"></span></li>
{{/if}}
<li>Projects: <ul>
{{#each content in project}}

{{#each content in model.project}}
<li>{{#link-to "project" content.id}}{{content.name}}{{/link-to}}</li>
{{/each}}
</ul> </li>
Expand Down Expand Up @@ -235,12 +236,12 @@ <h3>Edit</h3>
</div>
<div class="row form-group">
<div class="col-lg-12">
<div>{{view "select" class='form-control project_list'
<div>{{view "select" name=project class='form-control'
multiple=true
content=project
contentBinding="project.content"
optionValuePath="content.id"
optionLabelPath="content.name"
selection=model.project.content.content
selectionBinding="model.project.content"
}}
</div>
</div>
Expand Down Expand Up @@ -338,7 +339,7 @@ <h2>Assets</h2>
<h2>{{name}}</h2>
<ul>
<li>Creator: {{created_by}}</li>
<li>Project: {{project.content}}</li>
<li>Project: {{project.content.name}}</li>
</ul>
</section>
<section class="col-lg-4">
Expand Down Expand Up @@ -380,7 +381,7 @@ <h2>Assets</h2>
<h2>{{name}}</h2>
<ul>
<li>Creator: {{created_by}}</li>
<li>Project: {{project.content}}</li>
<li>Project: {{model.project.content.name}}</li>
</ul>
</section>
<section class="col-lg-4">
Expand Down Expand Up @@ -413,22 +414,30 @@ <h3>Edit</h3>
<div class="row form-group">
<span class="col-lg-12">Date Created: {{format-date date_created}}</span>
</div>
<div class="row form-group ">
<span class="col-lg-12">Project: {{project}}</span>
</div>
<div class="row form-group ">

<label class="col-lg-2">Project:</label>
<span class="col-lg-9">{{view "select" class='form-control'
content=project
contentBinding="project.content"
optionValuePath="content.id"
optionLabelPath="content.name"
selectionBinding="model.project.content"
}}</span>
</div>
</section>
<section class="col-lg-4">
<div class="row form-group ">
<span class="col-lg-12">Departments:</span>
<span class="col-lg-11">Department:</span>
</div>
<div class="row form-group">
<div class="col-lg-12">
<div>{{view "select" class='form-control'
<div>{{view "select" name=department class='form-control'
multiple=true
content=current_department.relation.content
contentBinding="department.content"
optionValuePath="content.id"
optionLabelPath="content.name"
selection=model.current_department.content
selectionBinding="model.current_department.content"
}}
</div>
</div>
Expand Down Expand Up @@ -502,16 +511,24 @@ <h3>Edit</h3>
</div>
</div>
<div class="form-group ">
<label>Project Status:</label>
<label>Department Status:
{{input type="checkbox" name="is_active" checked=is_active}}
</label>
</div>
</div>
<label>Projects:</label>

<div class="form-group ">
<div>{{view "select" multiple=true content=project class='form-control'}}</div>
<div>{{view "select" name=project class='form-control'
multiple=true
contentBinding="project.content"
optionValuePath="content.id"
optionLabelPath="content.name"
selectionBinding="model.project.content"
}}</div>
</div>
<p class="text-center">
<button type="submit" class="btn btn-red btn-lg">Create Project</button>
<button type="submit" class="btn btn-red btn-lg">Create Department</button>
</p>
</fieldset>
</form>
Expand Down
48 changes: 34 additions & 14 deletions redd/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ App.DepartmentRoute = App.AuthenticatedRoute.extend({
return this.store.find('department', params.department_id).then(function(data) {
return data
});
},
setupController: function(controller, model) {
controller.set('project', this.store.findAll('project'));
controller.set("model", model);
}
});

App.DepartmentCreateRoute = App.AuthenticatedRoute.extend({
model: function() {
return this.store.createRecord('department');
},
setupController: function(controller, model) {
controller.set('project', this.store.findAll('project'));
controller.set("model", model);
}
});

Expand All @@ -195,21 +209,23 @@ App.AssetsRoute = App.AuthenticatedRoute.extend({
return data
});
}

});

App.AssetRoute = App.AuthenticatedRoute.extend({
model: function(params) {
return this.store.find('asset', params.asset_id).then(function(data) {
return data
});
},
setupController: function(controller, model) {
controller.set('department', this.store.findAll('department'));
controller.set("model", model);
controller.set('project', this.store.findAll('project'));
}
});

App.AssetCreateRoute = App.AuthenticatedRoute.extend({
model: function() {
var new_asset = this.store.createRecord('asset')

return this.store.createRecord('asset');
},
setupController: function(controller, model) {
Expand All @@ -224,6 +240,7 @@ App.LoginRoute = Ember.Route.extend({
controller.reset();
}
});

App.IndexRoute = App.AuthenticatedRoute.extend();

// CONTROLLERS
Expand All @@ -237,6 +254,8 @@ App.AssetController = Ember.ObjectController.extend({
asset_creation_failed: false,
error_message: null,
is_editing: false,
department: null,
project: null,
actions: {
edit: function () {
this.set('is_editing', true);
Expand Down Expand Up @@ -304,6 +323,7 @@ App.DepartmentController = Ember.ObjectController.extend({
department_creation_failed: false,
error_message: null,
is_editing: false,
project: null,
actions: {
edit: function () {
this.set('is_editing', true);
Expand Down Expand Up @@ -336,25 +356,25 @@ App.DepartmentController = Ember.ObjectController.extend({
}
});

App.DepartmentCreateController = Ember.ArrayController.extend({
App.DepartmentCreateController = Ember.ObjectController.extend({
//username: this.controllerFor('login').get('user_name'),
name: null,
needs: ['login'],
project: null,
department: null,
selected_project: null,
actions: {
create_department: function() {
var data = this.getProperties('name', 'is_active');
data['created_by'] = this.controllerFor('login').get('user_name')
data['date_created'] = new Date()
//console.log(this.get('model').create())
var department = this.store.createRecord('department', data);
department.save().then(function(resp){
console.log(resp)
this.transitionTo('departments');
this.set('created_by', this.get('controllers.login').get('user_name'));
this.set('date_created', new Date());
this.get('model').save().then(function(resp){
console.log('success!', resp);
this.transitionToRoute('departments');
}.bind(this), function(resp){
if (resp.status === 400){
this.set("error_message", resp.responseText);
}else {
console.log(resp);
alert('an error occured communicating with the server.')
alert('an error occurred communicating with the server.')
}
this.set("department_creation_failed", true);
}.bind(this));
Expand Down

0 comments on commit d642677

Please sign in to comment.