[bknr-cvs] hans changed trunk/projects/quickhoney/

BKNR Commits bknr at bknr.net
Tue Sep 9 19:50:55 UTC 2008


Revision: 3872
Author: hans
URL: http://bknr.net/trac/changeset/3872

Fix image editing.  Factor out login Javascript.  Minor tweaks.

U   trunk/projects/quickhoney/src/handlers.lisp
U   trunk/projects/quickhoney/src/webserver.lisp
U   trunk/projects/quickhoney/website/static/javascript.js
A   trunk/projects/quickhoney/website/static/login.js
U   trunk/projects/quickhoney/website/templates/image-browse.xml
U   trunk/projects/quickhoney/website/templates/index.xml
U   trunk/projects/quickhoney/website/templates/login.xml

Modified: trunk/projects/quickhoney/src/handlers.lisp
===================================================================
--- trunk/projects/quickhoney/src/handlers.lisp	2008-09-09 17:41:22 UTC (rev 3871)
+++ trunk/projects/quickhoney/src/handlers.lisp	2008-09-09 19:50:55 UTC (rev 3872)
@@ -139,26 +139,32 @@
   (:default-initargs :object-class 'quickhoney-image))
 
 (defmethod handle-object-form ((handler json-edit-image-handler) action image)
-  (format t "; invalid action ~A or invalid object ~A~%" action image))
+  (with-json-response ()
+    (encode-object-element "result" "error")
+    (encode-object-element "message" (format nil "; invalid action ~A or invalid object ~A~%" action image))))
 
 (defun image-keywords-from-request-parameters ()
   (let (retval)
-    (dolist (keyword *editable-keywords* retval)
+    (dolist (keyword *editable-keywords*
+             retval)
       (when (query-param (string-downcase (symbol-name keyword)))
         (push keyword retval)))))
   
 (defmethod handle-object-form ((handler json-edit-image-handler) (action (eql :edit)) image)
   (with-query-params (client spider-keywords)
+    (format t "editing image ~A client ~A spider-keywords ~A~%" image client spider-keywords)
     (with-transaction (:edit-image)
       (setf (quickhoney-image-client image) client
             (quickhoney-image-spider-keywords image) spider-keywords
             (store-image-keywords image) (append (set-difference (store-image-keywords image) *editable-keywords*)
                                                  (image-keywords-from-request-parameters)))))
+  (setf *last-image-upload-timestamp* (get-universal-time))
   (with-json-response ()
     (encode-object-element "result" "edited")))
 
 (defmethod handle-object-form ((handler json-edit-image-handler) (action (eql :delete)) (image quickhoney-image))
   (delete-object image)
+  (setf *last-image-upload-timestamp* (get-universal-time))
   (with-json-response ()
     (encode-object-element "result" "deleted")))
 
@@ -292,7 +298,8 @@
 		(let* ((image (make-store-image :name (pathname-name (upload-original-filename uploaded-file))
 						:class-name 'quickhoney-image
 						:keywords (cons :upload (image-keywords-from-request-parameters))
-						:initargs (list :cat-sub (mapcar #'make-keyword-from-string (decoded-handler-path handler))
+						:initargs (list :owner (bknr-session-user)
+                                                                :cat-sub (mapcar #'make-keyword-from-string (decoded-handler-path handler))
                                                                 :client client
                                                                 :spider-keywords spider-keywords))))
 		  (with-http-response ()

Modified: trunk/projects/quickhoney/src/webserver.lisp
===================================================================
--- trunk/projects/quickhoney/src/webserver.lisp	2008-09-09 17:41:22 UTC (rev 3871)
+++ trunk/projects/quickhoney/src/webserver.lisp	2008-09-09 19:50:55 UTC (rev 3872)
@@ -59,4 +59,4 @@
 		 :site-logo-url "/image/quickhoney/color,000000,33ff00"
 		 :login-logo-url "/image/quickhoney/color,000000,33ff00/double,3"
 		 :style-sheet-urls '("/static/yui/reset-fonts/reset-fonts.css" "/static/quickhoney.css" "/static/cms.css")
-		 :javascript-urls '("/static/javascript.js")))
+		 :javascript-urls '("/MochiKit/MochiKit.js" "/static/javascript.js")))

Modified: trunk/projects/quickhoney/website/static/javascript.js
===================================================================
--- trunk/projects/quickhoney/website/static/javascript.js	2008-09-09 17:41:22 UTC (rev 3871)
+++ trunk/projects/quickhoney/website/static/javascript.js	2008-09-09 19:50:55 UTC (rev 3872)
@@ -97,31 +97,76 @@
 
 /* image editing */
 
+function all_inputs(parent) {
+    var inputs = [];
+    map(function (tag) {
+            inputs = inputs.concat(getElementsByTagAndClassName(tag, null, parent));
+        }, ['textarea', 'select', 'input']);
+    return inputs;
+}
+
+function submit_json(url, form, handler) {
+    var names = [];
+    var values = [];
+
+    if (form) {
+        map(function (input) {
+                names.push(input.name);
+                if (input.type != 'checkbox' || input.checked) {
+                    values.push(input.value);
+                }
+            }, all_inputs(form));
+    }
+
+    MochiKit.Async.doXHR(url, { mimeType: 'text/plain',
+                                headers: [['Accept', 'application/json']],
+                                method: 'POST',
+                                headers: {"Content-Type":"application/x-www-form-urlencoded"},
+                                sendContent: queryString(names, values) })
+        .addCallbacks(function (req) { handler(MochiKit.Base.evalJSON(req.responseText)) },
+                      alert);
+
+}
+
 function do_edit() {
     current_image.client = $("edit_client").value;
     current_image.spider_keywords = $("edit_keywords").value;
     current_image.keywords.explicit = $("edit_explicit").checked ? true : false;
 
     show_cms_window('saving_edits_form'); // hide edit window until server replies
+
+    submit_json('/json-edit-image/' + current_image.id + '?action=edit', 'edit_form_element', image_edited);
+
+    return false;
 }
 
-function image_edited() {
+function image_edited(json_data) {
+    if (json_data.result == 'error') {
+        alert(json_data.message);
+    }
     show_cms_window("image_edited_form");
     setTimeout("show_cms_window('edit_form')", 2000);
     // reload_clients();
 }
 
+function do_delete() {
+
+    if (confirm('delete this image?')) {
+        show_cms_window('saving_edits_form'); // hide edit window until server replies
+
+        submit_json('/json-edit-image/' + current_image.id + '?action=delete', null, image_deleted);
+    }
+
+    return false;
+}
+
 function image_deleted() {
 
     show_cms_window("image_deleted_form");
     current_image = null;
     $("image_detail").innerHTML = '';
-    if (current_directory == 'home') {
-	load_button_images();
-    } else {
-	setTimeout("if (!current_image) { show_cms_window('upload_form'); }", 2000);
-	do_query();
-    }
+    setTimeout("if (!current_image) { show_cms_window('upload_form'); }", 2000);
+    do_query();
 }
 
 /* clients list */
@@ -441,6 +486,11 @@
     }
 }
 
+function do_query()
+{
+    query_imagedb(current_directory, current_subdirectory, true);
+}
+
 /* pages handling */
 
 function Page(link_color, action) {
@@ -469,6 +519,7 @@
 
     if (logged_in) {
 	if (current_directory == "home") {
+            show_cms_window();
         } else if (current_directory == "news") {
             show_cms_window("edit_news");
 	} else if (current_directory && current_subdirectory) {
@@ -1008,14 +1059,12 @@
         wait_for_images(function () { img.style.visibility = 'inherit' });
     }
 
-
     if (logged_in) {
-	$("edit_form_element").setAttribute("action", "/edit-image-js/" + current_image.id);
 	$("edit_client").value = current_image.client;
-        $("edit_keywords").value = current_image.spider_keywords;
+        $("edit_keywords").value = current_image.spider_keywords || "";
         map(function(keyword) {
                 $('edit_' + keyword).checked = current_image.keywords[keyword] ? true : false;
-            }, ['explicit', 'buy-file', 'buy-print', 'buy-t-shirt']);
+            }, ['explicit']);
 	show_cms_window("edit_form");
     }
 }
@@ -1217,7 +1266,11 @@
 }
 
 function make_ipod_image() {
-    window.open('/image/' + encodeURI(current_image.name) + '/cell,,320,480/download,' + encodeURI(current_image.name) + '.jpg');
+    window.open('/image/'
+                + encodeURI(current_image.name)
+                + '/cell,,'
+                + ((current_image.width < current_image.height) ? '320,480' : '480,320')
+                + '/download,' + encodeURI(current_image.name) + '.jpg');
 }
 
 NOTICE = partial(SPAN, { 'class': 'notice' });
@@ -1414,7 +1467,7 @@
                     hidden_IMG({ src: recolored_image_path('hey'), 'class': 'flag', width: 37, height: 16}),
                     DIV({ 'class': 'button-section-items last' },
                         UL(null,
-                           make_image_action_button('ipod', 'iPod', make_ipod_image),
+                           make_image_action_button('ipod', 'iPhone', make_ipod_image),
                            make_image_action_button('comment', 'Comment', make_comment_form)))));
 
     replaceChildNodes('image_action_buttons', groups);
@@ -1436,18 +1489,3 @@
     wait_for_images(function () { $('image_action_buttons').style.visibility = 'inherit'; });
 }
 
-/* login stuff */
-
-function init_login () {
-    $('username').focus();
-    $('login_form').style.display = 'block';
-}
-
-function do_login () {
-
-    $('login_form').style.display = 'none';
-    $('logging-in').style.display = 'block';
-
-    return true;
-}
-

Added: trunk/projects/quickhoney/website/static/login.js
===================================================================
--- trunk/projects/quickhoney/website/static/login.js	                        (rev 0)
+++ trunk/projects/quickhoney/website/static/login.js	2008-09-09 19:50:55 UTC (rev 3872)
@@ -0,0 +1,15 @@
+/* login stuff */
+
+function init_login () {
+    $('login_form').style.display = 'block';
+    $('username').focus();
+}
+
+function do_login () {
+
+    $('login_form').style.display = 'none';
+    $('logging-in').style.display = 'block';
+
+    return true;
+}
+

Modified: trunk/projects/quickhoney/website/templates/image-browse.xml
===================================================================
--- trunk/projects/quickhoney/website/templates/image-browse.xml	2008-09-09 17:41:22 UTC (rev 3871)
+++ trunk/projects/quickhoney/website/templates/image-browse.xml	2008-09-09 19:50:55 UTC (rev 3872)
@@ -10,8 +10,6 @@
     <link rel="stylesheet" href="/static/yui/reset-fonts/reset-fonts.css" />
     <link rel="stylesheet" href="/static/quickhoney.css" />
     <link rel="stylesheet" href="/static/image-browse.css" />
-    <script src="/static/javascript.js" type="text/javascript"><!-- x -->   
-    </script> 
     <title>QuickHoney image</title>
   </head>
   <body id="image-browse">

Modified: trunk/projects/quickhoney/website/templates/index.xml
===================================================================
--- trunk/projects/quickhoney/website/templates/index.xml	2008-09-09 17:41:22 UTC (rev 3871)
+++ trunk/projects/quickhoney/website/templates/index.xml	2008-09-09 19:50:55 UTC (rev 3872)
@@ -179,12 +179,15 @@
             <input type="text" id="upload_client" name="client" value="" /><br />
             <span id="upload_client_select">
             </span>
+            <br />
             Keywords:<br />
             <input type="text" id="upload_keywords" name="spider-keywords" value="" /><br />
             <input type="checkbox" id="explicit" name="explicit" value="1" /> Explicit<br/>
+            <!-- shop disabled for now
             <input type="checkbox" name="buy-file" value="1"/> Sell as file<br/>
             <input type="checkbox" name="buy-print" value="1"/> Sell as print<br/>
             <input type="checkbox" name="buy-t-shirt" value="1"/> Sell as t-shirt<br/>
+            -->
           </p>
           <p class="cms">
             <input type="submit" name="upload" value="upload" />
@@ -240,24 +243,26 @@
       </div>
       
       <div id="edit_form" class="cms_form">
-        <form id="edit_form_element" action="/edit-image-js" target="edit_iframe" method="post"
-              onsubmit="return do_edit();">
+        <form id="edit_form_element" action="#" method="post" onsubmit="return false;">
           <div class="cms_title">Edit image</div>
           <p class="cms">
             Client:<br />
             <input type="text" id="edit_client" name="client" value="" /><br />
             <span id="edit_client_select">
             </span>
+            <br />
             Keywords:<br />
             <input type="text" id="edit_keywords" name="spider-keywords" value="" /><br />
             <input type="checkbox" id="edit_explicit" name="explicit" value="1" /> Explicit<br/>
+            <!-- shop disabled for now
             <input type="checkbox" id="edit_buy-file" name="buy-file" value="1"/> Sell as file<br/>
             <input type="checkbox" id="edit_buy-print" name="buy-print" value="1"/> Sell as print<br/>
             <input type="checkbox" id="edit_buy-t-shirt" name="buy-t-shirt" value="1"/> Sell as t-shirt<br/>
+            -->
           </p>
           <p class="cms">
-            <input type="submit" name="action" value="edit" />
-            <input type="submit" name="action" value="delete" onclick="return confirm('Really delete this image?');" />
+            <button type="submit" onclick="do_edit();">edit</button>
+            <button type="submit" onclick="do_delete();">delete</button>
           </p>
         </form>
       </div>

Modified: trunk/projects/quickhoney/website/templates/login.xml
===================================================================
--- trunk/projects/quickhoney/website/templates/login.xml	2008-09-09 17:41:22 UTC (rev 3871)
+++ trunk/projects/quickhoney/website/templates/login.xml	2008-09-09 19:50:55 UTC (rev 3872)
@@ -10,7 +10,7 @@
     <link rel="stylesheet" href="/static/yui/reset-fonts/reset-fonts.css" />
     <link rel="stylesheet" href="/static/login.css" />
     <script src="/MochiKit/MochiKit.js" type="text/javascript"> </script> 
-    <script src="/static/javascript.js" type="text/javascript"> </script> 
+    <script src="/static/login.js" type="text/javascript"> </script> 
     <title>QuickHoney CMS Login</title>
   </head>
 




More information about the Bknr-cvs mailing list