Commits

benoitc@localhost.nymphormation.net  committed 8de8d4f

some change in edit. Change account page so we don't have to change db
settings when we deploy.

  • Participants
  • Parent commits 8fffb73

Comments (0)

Files changed (13)

File _attachments/account.html

     <script src="/_utils/script/jquery.js"></script>
     <script src="/_utils/script/jquery.cookies.js"></script>
     <script src="/_utils/script/jquery.couch.js"></script>
-    <script>
-    // ugly hack for rewriting
-        $.extend({
-            blog: {
-                dbname: "benoitc-dev",
-                dname: "benoitc"
-            }
-        });
-    </script>
+
     <script src="js/jquery.couchapp.js"></script>
     
     <script>
         $.CouchApp(function(app) {
-            var redirectUrl = document.location.hash.replace('#','');
+
+            // ugly hack for rewriting
+            var href = document.location.href;
+            var redirectUrl = '';
+            if (href.split('#').length > 1) {
+                var fragments = href.split('#')[1].split(',');
+
+                var redirectUrl = fragments.pop();
+            }
             $('#content').append('<p>Attempting login.</p>');
             app.attemptLogin(function(login) {
                 if (redirectUrl) document.location = unescape(redirectUrl).replace('_design/','_design%2F');

File _attachments/css/benoitc.css

 	float: left;
 }
 
-header.about {
-	margin:2em 20px;
-	text-align:center;
-}
-header.about h1 {
-	margin:0;
-}
-header h1.about:first-child {
-	margin-top:1.5em;
-}
-header.about h1 a,
-header.about h1 a:link,
-header.about h1 a:visited,
-header.about h1 a:hover {
-	background:transparent none repeat scroll 0 0;
-	color:#000000;
-	text-decoration:none;
-}
-header.about p {
-	color:#777777;
-	font-variant:small-caps;
-	margin:0;
-	text-transform:capitalize;
+
+#adminheader {
+	display: block;
+	text-align: center;
+	font-size: 80%;
+	height: 12px;
+	margin: 0;
+	padding:0;
 }
 
 /* COMMENTS */
     overflow: auto;    
 }
 
-#fedit p {
+#fedit ol {
+	list-style: none;
+}
+#fedit ol,
+#fedit ol li {
+	margin: 0;
+	padding: 0;
+}
+
+#fedit label {
     display: block;
-    padding-bottom: 5px;
-}
-#fedit form label {
-    display: block;
-    width: 14em;
+    width: 14em; 
     height: 11px;
     float: left;
     padding: 0 1em 3px 0;
+	font-size: 12px; 
 }
 #fedit input[type='text'], 
 #fedit input[type='password'],
     width: 174px;
     border: 1px solid;
     margin: 0;
+	font-size: 12px;
 }
 
 #fedit textarea {
 #main-footer p {
 	margin:0;
 }
-#main-footer form {
-	float:right;
-}
-#main-footer input{
-	font-size:10px;
-}
+
 
 /* MISC HELPER STYLES */
 
 	font-style:italic;
 }
 
+
+/* friendpaste snippets */
+
 .friendpaste,
 .friendpaste *,
 .friendpaste * * {
 }
 
 
-/* RESUME */
-
-.chrono h3 {
-	margin-bottom:0;
-}
-.chrono p.period {
-	text-align:right;
-	font-weight:bold;
-}
-.chrono p.biz {
-	float:left;
-}
-.chrono .stuff {
-	clear:all;
-}
-.chrono li li {
-	list-style-type:disc;
-}
-@media print {
-	.chrono p.biz a {
-		font-weight:bold;
-	}
-}
-
 /* ABOUT */
 
 .about img.me {
 	border:1px solid #333;
 	margin:5px 25px 25px 0;
 }
+header.about {
+	margin:2em 20px;
+	text-align:center;
+}
+header.about h1 {
+	margin:0;
+}
+header h1.about:first-child {
+	margin-top:1.5em;
+}
+header.about h1 a,
+header.about h1 a:link,
+header.about h1 a:visited,
+header.about h1 a:hover {
+	background:transparent none repeat scroll 0 0;
+	color:#000000;
+	text-decoration:none;
+}
+header.about p {
+	color:#777777;
+	font-variant:small-caps;
+	margin:0;
+	text-transform:capitalize;
+}
 
 
-/* FUCKING IE */
+/* IE */
 
 * html body{width:40em}
 * html div.index{width:34.5em}

File _attachments/js/jquery.couchapp.js

 // Monkeypatching Date. 
 
 
+
+
+
 (function($) {
+  function getEnv() {
+    var href = document.location.href;
+    if (href.split('#').length <= 1)
+        return;
+    var fragments = href.split('#')[1].split(',');
+
+    if (fragments.length == 4) {
+        $.extend({
+            blog: {
+                'dbname': fragments[0],
+                'dname': fragments[1],
+                'cookie_path': fragments[2]
+            }
+        });
+    } else if (fragments.length == 3) {
+        $.extend({
+            blog: {
+                'dbname': fragments[0],
+                'dname': fragments[1]            
+            }
+        });
+    } else if (fragments.length == 2) {
+        $.extend({
+            blog: {
+                'dbname': fragments[0]            
+            }
+        });
+    }
+  }
 
   function f(n) {    // Format integers to have at least two digits.
       return n < 10 ? '0' + n : n;
   function init(app) {
 
     $(function() {
+      getEnv();
       if ($.blog && $.blog.dbname) {
         var dbname = $.blog.dbname;
       } else {
         },
         attemptLogin : function(win, fail) {
           // depends on nasty hack in blog validation function
+          if ($.blog && $.blog.cookie_path) {
+            var cookie_path = $.blog.cookie_path;
+          } else {
+            var cookie_path = "/" + dbname;
+          }
           db.saveDoc({"author":"_self"}, { error: function(s, e, r) {
             var namep = r.split(':');
             if (namep[0] == '_self') {
               login = namep.pop();
-              $.cookies.set("login", login, '/'+dbname)
+              $.cookies.set("login", login, cookie_path)
               win && win(login);
             } else {
-              $.cookies.set("login", "", '/'+dbname)
+              $.cookies.set("login", "", cookie_path)
               fail && fail(s, e, r);
             }
           }});        
             loggedOut && loggedOut();
           }
         },
+        is_logged: function() {
+            login = login || $.cookies.get("login");
+            if (login)
+                return true;
+            return false;
+        },
         db : db,
         design : design,
         docForm : docForm

File _attachments/style/main.css

-/* add styles here */
             "show_url": "show",
             "list_url": "list",
             "dbname": "benoitc-dev",
-            "dname": "benoitc"
+            "dname": "benoitc",
+            "cookie_path": "/"
         }
     }
 }

File lib/helpers/couchapp.js

 function getEnv() {
     default_env = {
         'dbname': req.path[0],
-        'dname': req.path[2]
+        'dname': req.path[2],
+        'cookie_path': '/' + req.path[0]
     };
 
     new_env = {};

File lib/templates/edit.html

                         
                 <textarea name="body" id="body" cols="80"
                     rows="20"></textarea>
+                
+                <ol>
+                    <li><label for="title">Titre<label><input type="text"
+                            name="title" id="title" value=""></li>
 
-                <p><label for="title">Titre<label><input type="text"
-                        name="title" id="title" value=""></p>
-
-                <p><label for="labels">Libellés</label><input type="text"
-                name="labels" id="labels" value=""></p>
-                
+                    <li><label for="labels">Libellés</label><input type="text"
+                name="labels" id="labels" value=""></li>
+                </ol>
                 
                 <p><input type="submit" name="save" id="save" value="Save">
                 or <a href="<%= index %>">Cancel</a> <span id="saved" style="display:none;">Saved</span></p>
         $.extend({
             blog: {
                 dbname: "<%= env.dbname %>",
-                dname: "<%= env.dname %>"
+                dname: "<%= env.dname %>",
+                cookie_path: "<% env.cookie_path %>"
             }
         });    
     </script>
 
             $.CouchApp(function(app) {
                 app.loggedInNow(function(login) {
-                    $("#header").prepend('<span id="login">'+login+'</span>');
+                    $("header").prepend('<span id="login">'+login+'</span>');
                     
                     var B = new Blog(app);
 
                     new Editor(); 
                     }, function() {
                     // callback
-                    $('body').append('<a href="<%= assets %>/account.html#'+document.location+'">redirect</a>');
+                    $('body').append('<a href="<%= assets %>/account.html#<%= env.dbname %>,<%= env.dname %>,<%= env.cookie_path %>,'+document.location+'">redirect</a>');
                     var absurl = $('body a:last')[0].href;
                     document.location = absurl;
                 });

File lib/templates/index/tail.html

-        <p class="next"><a href="<%= nextPath %>">suite »</a></p>
+        <p class="next"><a href="<%= nextPath %>">articles suivants »</a></p>
 
         <footer id="main-footer">
             <p>2009 (c) <a href="<%= assets %>/benoitc.html">Benoît Chesneau</a> - <a rel="license" href="http://creativecommons.org/licenses/by/2.0/fr/">Certains droits reservés</a>.</p>

File lib/templates/post.html

 
 <body>
     <div id="container">
-        <header>
-            
-        </header>
+        <header id="adminheader"></header>
         <section id="maincontent"> 
         <article class="article content">
             <header>
     <script src="/_utils/script/json2.js"></script>
     <script src="/_utils/script/jquery.js"></script>
     <script src="/_utils/script/jquery.couch.js"></script>
+    <script src="/_utils/script/jquery.cookies.js"></script>
 
     <script>
         // ugly hack for rewriting
             localizeDates();
 
             $.CouchApp(function(app) {
+                if (app.is_logged()) {
+                    $("#adminheader").html('<p><a href="<%= editPath %>">Edit</a>'
+                    +'</p>');
+                }
                 var docid = document.location.pathname.split('/').pop();
                 var B = new Blog(app);
                 function displayComments() {

File lists/feeds.js

-function(head, row, req, row_info) {
-  // !json lib.templates.feeds
-  // !code lib.helpers.couchapp
-  // !code lib.helpers.template
-
-    return respondWith(req, {
-        html: function() {
-            if (head) {
-                return template(lib.templates.feeds.head, {
-                    assets: assetPath()
-                });
-            } else if (row) {
-                return '';
-            } else {
-                return template(lib.templates.feeds.tail, {});
-            }
-        }
-    })
-};

File lists/twitter.js

-function(head, row, req, row_info) {
-    // !json lib.templates.twitter
-    // !json !code lib.helpers.couchapp
-    // !code lib.helpers.ejs.ejs
-    // !code lib.helpers.ejs.view
-    // !code lib.helpers.template2
-
-    return respondWidth(req, {
-        html: function() {
-            if (head) {
-                return template(lib.templates.index.head, {});
-            } else if (row) {
-            } else {
-                return  template(lib.templates.index.tail, {});
-            }
-        }
-    }

File shows/edit.js

   // !code lib.helpers.couchapp
 
   // we only show html
+  //
+  
+
   return template(lib.templates.edit, {
     doc : doc,
     docid : toJSON((doc && doc._id) || null), 
     assets : assetPath(),
     index : listPath('index','recent-posts',{descending:true,limit:8}),
     env: getEnv()
-  });
+    });
 }

File shows/post.js

                   + '" rel="tag">'+ doc.labels[i] + '</a>');
       }
   }
+
+  var editPath = showPath("edit", doc._id);
   // we only show html
   return template(lib.templates.post, {
     doc: doc,
     editPostPath : showPath('edit', doc._id),
     labels: labels.join(', '),
     index : listPath('index','recent-posts',{descending:true, limit:8}),
-    env: getEnv()
+    env: getEnv(),
+    editPath: editPath
   });
 }