Permalink
Browse files

Changed edit templtating and enabled multiple nakkitypes creation in …

…single editing session.
  • Loading branch information...
1 parent 9b6923e commit 57c28af587d7ad32f3f9c0f1e22d3d18507291db @d4gg4d d4gg4d committed Jul 28, 2012
Showing with 38 additions and 15 deletions.
  1. +15 −11 public/javascripts/templates/edit-nakkis.html
  2. +23 −4 public/javascripts/views/admin.js
@@ -1,12 +1,16 @@
-<table>
-<% _.each(data, function(nakki){ %>
-<tr>
- <td><input type="text" name="type" value="<%= nakki.type %>"></input></td>
- <td><input type="text" name="start" value="<%= nakki.start %>"></input></td>
- <td><input type="text" name="end" value="<%= nakki.end %>"></input></td>
- <td><button class="deletor" value="<%= nakki.id %>">delete</button></td>
-</tr>
-<% }); %>
-</table>
-
+<button class="setter">Save Changes</button>
+<button class="creator">Create New Type</button>
+<div class="table">
+ <% _.each(data, function(nakki){ %>
+ <div class="row">
+ <form>
+ <input type="hidden" name="cid" value="<%= nakki.cid %>"/>
+ <input type="text" name="type" value="<%= nakki.get('type') %>" />
+ <input type="text" name="start" value="<%= nakki.get('start') %>" />
+ <input type="text" name="end" value="<%= nakki.get('end') %>" />
+ </form>
+ <button class="deletor" value="<%= nakki.cid %>">delete</button>
+ </div>
+ <% }); %>
+</div>
@@ -33,6 +33,8 @@ define(['jquery',
var nakkitypes = new collections.Nakkitypes();
+ var counter = 1;
+
var Party_Selector = bb.View.extend({
events: {
"change .selector" : "select",
@@ -93,14 +95,16 @@ define(['jquery',
var Nakki_List = bb.View.extend({
events: {
'click .editor' : 'edit',
+ 'click .setter' : 'saveCollection',
+ 'click .creator' : 'create',
'click .deletor' : 'remove'
},
initialize: function(){
_.bindAll(this);
vent.on('changeParty', this.refresh);
- nakkitypes.on('add', this.render);
- nakkitypes.on('remove', this.render);
+ nakkitypes.on('add', this.edit);
+ nakkitypes.on('remove', this.edit);
this.render();
},
@@ -125,18 +129,33 @@ define(['jquery',
},
create: function(){
- nakkitypes.add(new models.Nakkitype());
+ nakkitypes.add(new models.Nakkitype({type:'tyyppi' + counter++}));
},
edit: function(){
- this.$el.html(nakkilist_edit_template({data:nakkitypes.toJSON()}));
+ this.$el.html(nakkilist_edit_template({data:nakkitypes.models}));
return this.$el;
},
//TODO not work if created model, which doesn't have id yet(maybe disable delete for tehm...).
remove: function(target){
var removeId = target.currentTarget.attributes['value'].nodeValue;
nakkitypes.remove(removeId);
+ },
+
+ saveCollection: function(){
+ //TODO here we would reset whole collection based on input of the edit table.
+ $('#nakit form').each(function(){
+ var arr = $(this).serializeArray();
+ var data = _(arr).reduce(function(acc, field) {
+ acc[field.name] = field.value;
+ return acc;
+ }, {});
+ var model = nakkitypes.getByCid(data["cid"]);
+ delete data['cid'];
+ model.save(data); //TODO handling new nakki type cases?
+ });
+ this.render();
}
});

0 comments on commit 57c28af

Please sign in to comment.