var request = require('request'),
  dbInstance = require('../db');

var noop = function() {};

var createLayout = function(options, callback) {
  var cb = callback || noop,
    opts = options || {};
  console.log("Start creating layout");
  if (!opts.name) {
    return cb("Layout name required");
  }
  if (!opts.layout) {
    return cb("Layout data required");
  }
  var data = {
    name: opts.name.trim(),
    data: opts.layout
  }
  var collection = dbInstance.collection("public_layouts");
  collection.insert(data, function(err, results) {
    if (err) {
      return cb("Please try again! Error insert new user");
    } else if (results && results.length) {
      console.log("cai j vay ss");
      return cb(null, results[0]);
    } else {
      console.log("cai j vay ssava");
      return cb('Create layout error');
    }
  });
}

var listPublic = function(options, callback) {
  var cb = callback || noop,
    opts = options || {};
  var collection = dbInstance.collection("public_layouts");
  var limit = opts.perpage || 20;
    collection.find(opts ,{limit: limit, sort: {'_id': -1}}).toArray(function(err, results){
      cb(err, results);
    })
}

exports = module.exports = {
  createLayout: createLayout,
  listPublic: listPublic
};

@@ -424,16 +424,41 @@
 s.layout
+,%0A    updated: new Date()
 %0A  %7D%0A  v
@@ -688,43 +688,8 @@
 ) %7B%0A
-      console.log(%22cai j vay ss%22);%0A
     

Add time updated layout share