Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
gerard2perez committed Mar 24, 2015
2 parents 51ea874 + 59a048d commit 8a6849e
Show file tree
Hide file tree
Showing 13 changed files with 453 additions and 130 deletions.
8 changes: 7 additions & 1 deletion Brocfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

var EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

var app = new EmberAddon();
var app = new EmberAddon({
'ember-cli-bootstrap': {
'importBootstrapJS': true
}
});

// Use `app.import` to add additional libraries to the generated
// output files.
Expand All @@ -17,5 +21,7 @@ var app = new EmberAddon();
// modules that you would like to import into your application
// please specify an object with the list of modules as keys
// along with the exports of each module as its value.
app.import('bower_components/bootstrap/dist/js/bootstrap.js');
app.import('bower_components/bootstrap/dist/css/bootstrap.css');

module.exports = app.toTree();
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@

Master Branch: [![Build Status](https://travis-ci.org/gerard2p/ember-cli-crudtable.svg?branch=master)](https://travis-ci.org/gerard2p/ember-cli-crudtable)

Development Branch: [![Build Status](https://travis-ci.org/gerard2p/ember-cli-crudtable.svg?branch=development)](https://travis-ci.org/gerard2p/ember-cli-crudtable)
# Hello Every One
I've didn't notice that people was watching this proyect, so i'm sorry for the lack of documentation.
Today (24 March, 2015) I just finished one version wich is working, so hang on a second and tomorrow I'll update the docuemntation.

If you could support me by following me, or maybe by letting any comment on the issue section It'll be great.

Thank You :)

# Ember-cli-crudtable

This README outlines the details of collaborating on this Ember addon.
Expand Down
140 changes: 117 additions & 23 deletions addon/components/crud-table.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,145 @@
/*globals $*/
import Ember from 'ember';
import layout from '../templates/components/crud-table';

export default Ember.Component.extend({
var CustomField = Ember.Object.extend({
Field: null,
Value: null,
Type: null,
listener: function () {}.observes('Value')
});

var regenerateView = function (cmp) {
var ComplexModel = [];
if (cmp.value) {
cmp.value.forEach(function (row) {
var CustomProperties = [];
cmp.fields.forEach(function (field) {
var data = row.get ? row.get(field) : row[field];
var cfield = CustomField.create({
Field: field,
Value: data,
Type: typeof (data),
listener: function () {
row.set(this.get('Field'), this.get('Value'));
}.observes('Value')
});
CustomProperties.pushObject(cfield);
});
CustomProperties.RoutedRecord = row;
ComplexModel.pushObject(CustomProperties);
});
}
cmp.set('ComplexModel', ComplexModel);

stripped:false,
hover:false,
};
var showmodal = function () {
$("#CrudTableDeleteRecordModal").modal('show');
};

actions:{
edit:function(){
this.get('edit')();
var hidemodal = function () {
$("#CrudTableDeleteRecordModal").modal('hide');
};

export default Ember.Component.extend({

attributeBindings: ['style'],
style: function () {
return 'color: ' + this.get('name') + ';';
}.property('name'),
stripped: false,
hover: false,
createRecord: '',
updateRecord: '',
deleteRecord: '',
cancelRecord: 'cancel',
currentRecord: null,
getRecord: 'getRecord',
actions: {
confirm: function () {
var that = this;
var deferred;
if (this.get('newRecord')) {
deferred = Ember.RSVP.defer('crud-table#createRecord');
this.sendAction('createRecord', this.get('currentRecord').RoutedRecord, deferred);
} else {
if (this.get('isDeleting')) {
deferred = Ember.RSVP.defer('crud-table#deleteRecord');
this.sendAction('deleteRecord', this.get('currentRecord').RoutedRecord, deferred);
} else {
deferred = Ember.RSVP.defer('crud-table#updateRecord');
this.sendAction('updateRecord', this.get('currentRecord').RoutedRecord, deferred);
}
}
deferred.promise.then(function () {
regenerateView(that);
hidemodal();
}, function (data) {
alert(data.message);
});
},
delete:function(){
this.get('delete')();
internal_create: function () {
var that = this;
that.set('newRecord', true);
var deferred = Ember.RSVP.defer('crud-table#newRecord');
this.sendAction('getRecord', deferred);
deferred.promise.then(function ( /*record*/ ) {
regenerateView(that);
that.set('currentRecord', that.get('ComplexModel').get('lastObject'));
showmodal();
}, function ( /*data*/ ) {
alert('Something went wrong');
});
},
internal_edit: function (record) {
this.set('isDeleting', false);
this.set('currentRecord', record);
//$("#CrudTableDeleteRecordModal .modal-title").html("Updating");
showmodal();
},
internal_delete: function (record) {
this.set('newRecord', false);
this.set('isDeleting', true);
this.set('currentRecord', record);
showmodal();
//this.get('delete')();
}
},
layout: layout,
class: "",
value: [],
fields: "id",
edit: function () {
alert('edit');
},
delete: function () {
alert('delete');
},
init: function () {
var that = this;
this._super();
this.set('fields', this.fields.split(','));
this.set('editdelete', this.edit != null || this.delete !=null );
this.set('editdelete', this.deleteRecord != null || this.updateRecord != null);
this.init = function () {
that._super();
}.on('willInsertElement');
}.on('willInsertElement'),
setup: function () {
var that = this;
var model = [];
this.value.forEach(function (row) {
var rrrow = [];
that.fields.forEach(function (field) {
rrrow.push(row.get(field));
regenerateView(that);
//Ember.addObserver('value',that,function(){
// regenerateView(that);
//});
$("#CrudTableDeleteRecordModal").modal('hide');
$('#CrudTableDeleteRecordModal').on('hidden.bs.modal', function () {
var deferred = Ember.RSVP.defer('crud-table#cancelRecord');
that.sendAction('cancelRecord', that.get('currentRecord').RoutedRecord, deferred);
deferred.promise.then(function () {
regenerateView(that);
that.set('newRecord', false);
that.set('isDeleting', false);
that.set('currentRecord', null);
}, function (data) {
alert(data);
});
model.push(rrrow);

});
this.set('model', model);
}.on('didInsertElement'),

}.on('didInsertElement'),
teardown: function () {
//this._drop.destroy();
}.on('willDestroyElement'),
Expand Down
52 changes: 52 additions & 0 deletions addon/mixins/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Ember from 'ember';
//import App from '../app';
//import EmberValidations from 'ember-validations';

export default function (model /*settings*/) {
return Ember.ObjectController.extend({
isEditing: false,
actions: {
getRecord: function (deferred) {
deferred.resolve(this.store.createRecord(model));
},
create: function (record, deferred) {
if (record.get('isNew')) {
record.save().then(deferred.resolve, deferred.reject);
}
},
read: function () {

},
update: function (record, deferred) {
record.save().then(deferred.resolve, deferred.reject);
//var self = this;
//var promises = [];
//if(self.model.get('isDirty')){
//promises.push(record.save());
//}else{
// self.set('isEditing',false);
//}
/*Ember.A(Ember.keys(record._dependentRelations)).any(function (key) {
var value = Ember.get(self.model, key);
if (value.get('isDirty')) {
promises.push(value.get('content').save());
}
});*/
//Ember.RSVP.Promise.all(promises).then(deferred.resolve, deferred.reject);

},
delete: function (record, deferred) {
record.destroyRecord().then(deferred.resolve, deferred.reject);
},
cancel: function (record, deferred) {
if (record.get('isDirty')) {
record.rollback();
}
if (record.get('isNew')) {
record.deleteRecord();
}
deferred.resolve(true);
}
}
});
}
1 change: 0 additions & 1 deletion addon/templates/components/crud-table-row.hbs

This file was deleted.

59 changes: 31 additions & 28 deletions addon/templates/components/crud-table.hbs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<div class="row">
<div class="col-sm-5 m-b-xs">
<select class="input-sm form-control input-s-sm inline">
<option value="0">Option 1</option>
<option value="1">Option 2</option>
<option value="2">Option 3</option>
<option value="3">Option 4</option>
</select>
<div class="col-sm-3 m-b-xs">
<button class="btn btn-primary " type="button" data-action="create" {{action 'internal_create' value}}>
<i class="fa fa-check"></i>&nbsp;New Record</button>
</div>
<div class="col-sm-4 m-b-xs">
<div data-toggle="buttons" class="btn-group">
Expand All @@ -17,45 +13,52 @@
<input type="radio" id="option3" name="options"> Month </label>
</div>
</div>
<div class="col-sm-2 m-b-xs">
<select name="SearchField" class="input-sm form-control input-s-sm inline">
{{#each field in this.fields}}
<option {{bind-attr value=field}}>{{field}}</option>
{{/each}}
</select>
</div>
<div class="col-sm-3">
<div class="input-group">
<input type="text" placeholder="Search" class="input-sm form-control"> <span class="input-group-btn">
<button type="button" class="btn btn-sm btn-primary"> Go!</button> </span>
<button type="button" class="btn btn-sm btn-primary"> Go!</button> </span>
</div>
</div>
</div>
<div class="table-responsive">
<table {{bind-attr class=":table stripped:table-striped hover:table-hover"}} class="">
<table {{bind-attr class=":table stripped:table-striped hover:table-hover" }} class="">
<thead>
<tr>
{{#each field in this.fields}}
<th>{{field}}</th>
{{/each}}
{{#if this.editdelete}}
<th>{{field}}</th>
{{/each}} {{#if this.editdelete}}
<th width="80px">Actions</th>
{{/if}}
</tr>
</thead>
<tbody>

{{#each row in this.model}}
<tr>
{{render 'crud-table-row' row}}

{{#if this.editdelete}}
<td>
{{#if this.edit}}
<button class="btn btn-info btn-circle" {{action 'edit' row}}><i class="fa fa-edit" ></i></button>
{{/if}}
{{#if this.delete}}
<button class="btn btn-danger btn-circle" {{action 'delete' row}}><i class="fa fa-trash"></i></button>
{{/if}}
</td>
{{#each row in this.ComplexModel}}
<tr>
{{#if row}}
{{render 'crud-table-row' row}}
{{/if}}
{{#if this.editdelete}}
<td>
{{#if this.updateRecord}}
<button data-action="edit" class="btn btn-info btn-circle" {{action 'internal_edit' row}}><i class="fa fa-edit"></i>
</button>
{{/if}} {{#if this.deleteRecord}}
<button data-action="delete" class="btn btn-danger btn-circle" {{action 'internal_delete' row}}><i class="fa fa-trash"></i>
</button>
{{/if}}
</tr>
</td>
{{/if}}
</tr>
{{/each}}

</tbody>
</table>
</div>
{{yield}}
{{yield}} {{render 'crud-table-modal' this}}
43 changes: 43 additions & 0 deletions app/templates/crud-table-modal.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<div class="modal inmodal fade" id="CrudTableDeleteRecordModal" tabindex="-1" role="dialog" aria-hidden="false">
<div {{bind-attr class=":modal-dialog isDeleting:modal-sm"}}>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span>
</button>
<h4 class="modal-title">
{{#if newRecord}}
Add a New Record
{{else}}
{{#if isDeleting}}
You're about to delete a record
{{else}}
Updating
{{/if}}
{{/if}}
</h4>
</div>
<div class="modal-body">
{{this}}
{{#if newRecord}}
{{render 'crud-table-update' this.currentRecord}}
{{else}}
{{#if isDeleting}}
Deleting the record: <b>{{this.currentRecord.0.Value}}</b> is a permanent action.
{{else}}
{{render 'crud-table-update' this.currentRecord}}
{{/if}}
{{/if}}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-white" data-dismiss="modal">Cancel</button>
<button type="button" {{bind-attr class=":btn isDeleting:btn-danger:btn-primary"}} data-action="confirm" {{action 'confirm' this}}>
{{#if isDeleting}}
Delete
{{else}}
Save
{{/if}}
</button>
</div>
</div>
</div>
</div>
4 changes: 2 additions & 2 deletions app/templates/crud-table-row.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{#each value in this}}
<td>{{value}}</td>
{{#each property in this}}
<td>{{property.Value}}</td>
{{/each}}
Loading

0 comments on commit 8a6849e

Please sign in to comment.