Permalink
Browse files

override for default crud to add a simple passcode

  • Loading branch information...
1 parent 18fad08 commit 1bdd03f6acea50de2fd8ded0113fae6dccbbf19a @lashleigh committed Apr 26, 2012
Showing with 50 additions and 35 deletions.
  1. +3 −3 client/event_handlers.js
  2. +3 −3 client/utility_functions.js
  3. +24 −16 common/utility_functions.js
  4. +20 −13 server/setup.js
@@ -1,5 +1,5 @@
Template.slide_list.events = {
- 'click #index ul li': function(e) { console.log('li'); set_current_slide(e.currentTarget.id); },
+ 'click #index ul li': function(e) { set_current_slide(e.currentTarget.id); },
'click #new-slide': function(e) { insert_slide(e); },
'click a.admin-next': function(e) { move_next($(e.currentTarget).parents("li").attr("id")); },
'click a.admin-prev': function(e) { move_prev($(e.currentTarget).parents("li").attr("id")); },
@@ -20,7 +20,7 @@ Template.current_slide.events = {
var slide = slides.findOne(Session.get('client_current'));
var new_title = $('#slide-title').text().replace(/(^\s+|\s+$)/g,'');
if(new_title.length > 3 && Session.get('admin')) {
- slides.update(slide._id, {$set : {title: new_title}});
+ update(slide._id, {$set : {title: new_title}});
} else {
$('#slide-title').text(slide.title);
}
@@ -38,6 +38,6 @@ Template.current_slide.events = {
var slide = slides.findOne(Session.get('client_current'));
var new_body = $('#body-box').val();
if(slide && !_.isEqual(slide.body, new_body))
- slides.update(slide._id, {$set: {body: new_body}});
+ update(slide._id, {$set: {body: new_body}});
}
};
@@ -1,7 +1,7 @@
function normalize_slide_order() {
var slide_ids = $("#index li").map(function(i, s) { return s.id; });
for(i in _.range(slide_ids.length)) {
- slides.update({ _id: slide_ids[i] }, { $set: { order: i } });
+ update({ _id: slide_ids[i] }, { $set: { order: i } });
}
}
@@ -19,8 +19,8 @@ function set_current_slide(id) {
function set_db_current_slide(id) {
if(!Session.equals('current', id)) {
- slides.update({current: true}, { $set: { current: false } }, { multi: true });
- slides.update({ _id: id }, { $set: { current: true } });
+ update({current: true}, { $set: { current: false } }, { multi: true });
+ update({ _id: id }, { $set: { current: true } });
}
}
}
@@ -1,17 +1,31 @@
+function update(selector, updates, multi) {
+ if(!Session.get('passcode')) return;
+ multi = multi || false;
+ Meteor.call('update', selector, updates, multi, Session.get('passcode'));
+}
+function insert(attributes) {
+ if(!Session.get('passcode')) return;
+ Meteor.call('insert', attributes, Session.get('passcode'));
+}
+function remove(selector) {
+ if(!Session.get('passcode')) return;
+ Meteor.call('remove', selector, Session.get('passcode'));
+}
+
function current_slide() {
return slides.findOne({ current: true }) || slides.findOne({}, {sort: {order: 1}});
}
function add_slide() {
- set_current_slide(slides.insert({ title: "New Slide", body: "Edit me!", order: slides.find().count() }));
+ set_current_slide(insert({ title: "New Slide", body: "Edit me!", order: slides.find().count() }));
}
function insert_slide() {
var current = current_slide();
if(current) {
- slides.update({order : {$gt: current.order}}, {$inc: {order: 1}}, {multi: true});
- set_current_slide(slides.insert({ title: "New Slide"+current.order, body: "Edit me!", order: current.order+1 }));
+ update({order : {$gt: current.order}}, {$inc: {order: 1}}, {multi: true});
+ set_current_slide(insert({ title: "New Slide"+current.order, body: "Edit me!", order: current.order+1 }));
} else {
- set_current_slide(slides.insert({ title: "New Slide", body: "Edit me!", order: slides.find().count() }));
+ set_current_slide(insert({ title: "New Slide", body: "Edit me!", order: slides.find().count() }));
}
}
@@ -21,11 +35,8 @@ function move_prev(id) {
var p = slides.findOne({ order: { $lt: s.order } }, { sort: { order: -1 } });
if(!p) return;
- console.log("s:", s.title, s.order);
- console.log("p:", p.title, p.order);
-
- slides.update({_id: s._id}, { $set: { order: p.order } });
- slides.update({_id: p._id}, { $set: { order: s.order } });
+ update({_id: s._id}, { $set: { order: p.order } });
+ update({_id: p._id}, { $set: { order: s.order } });
}
function move_next(id) {
@@ -34,16 +45,13 @@ function move_next(id) {
var n = slides.findOne({order: { $gt: s.order } }, { sort: { order: 1 } });
if(!n) return;
- console.log("s:", s.title, s.order);
- console.log("n:", n.title, n.order);
-
- slides.update({_id: s._id}, { $set: { order: n.order } });
- slides.update({_id: n._id}, { $set: { order: s.order } });
+ update({_id: s._id}, { $set: { order: n.order } });
+ update({_id: n._id}, { $set: { order: s.order } });
}
function remove_slide(id) {
if(current_slide()) set_current_slide(slides.findOne({current: false})._id);
var slide = slides.findOne(id);
- slides.update({order : {$gt: slide.order}}, {$inc: {order: -1}}, {multi: true});
- slides.remove({ _id: id });
+ update({order : {$gt: slide.order}}, {$inc: {order: -1}}, {multi: true});
+ remove({ _id: id });
}
View
@@ -14,19 +14,26 @@ Meteor.publish('slides', function() {
return slides.find();
});
-/*
+var server_password = 'supersecret';
Meteor.methods({
- reset: function() {
- shows.remove({});
- slides.remove({});
- var show_id = shows.insert({title: 'Getting started with liveslides', created_at: Date.now()})
- var slides =[{title: 'welcome to your slideshow'},{}, {}]
- for (var i = 0; i < stops.length; i++)
- Days.insert({stop: stops[i], order: i+1, trip_id: trip_id, created_at: Date.now(), updated_at: Date.now()});
+ update: function(selector, updates, multi, passcode) {
+ if(passcode && passcode === server_password) {
+ slides.update(selector, updates, multi);
+ }
+ },
+ insert: function(attributes, passcode) {
+ if(passcode && passcode === server_password) {
+ slides.insert(attributes);
+ }
+ },
+ remove: function(selector, passcode) {
+ if(passcode && passcode === server_password) {
+ slides.remove(selector);
+ }
}
-})
+});
Meteor.startup(function() {
- if (Trips.find().count() === 0) {
- Meteor.call('reset');
- }
-});*/
+ Meteor.default_server.method_handlers['/slides/insert'] = function () {};
+ Meteor.default_server.method_handlers['/slides/update'] = function () {};
+ Meteor.default_server.method_handlers['/slides/remove'] = function () {};
+});

0 comments on commit 1bdd03f

Please sign in to comment.