Changeset 3653

Show
Ignore:
Timestamp:
07/28/08 12:48:50 (4 months ago)
Author:
ksprotte
Message:

poi-handlers changed to get them up-to-date with hunchentoot - all the old functionality is working now again

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/projects/bos/payment-website/static/cms.js

    r2160 r3653  
    9393    } 
    9494} 
     95 
     96function confirm_delete(field_name, value, confirm_string) 
     97{ 
     98    $(field_name).value = value; 
     99    return confirm(confirm_string); 
     100} 
  • trunk/projects/bos/web/poi-handlers.lisp

    r3652 r3653  
    1  
    21(in-package :bos.web) 
    32 
     
    65(defclass make-poi-handler (page-handler) 
    76  ()) 
    8    
     7 
    98(defmethod handle ((handler make-poi-handler)) 
    109  (with-query-params (name) 
     
    6564        (setf (nth old-position new-images) (nth (+ shift-by old-position) new-images)) 
    6665        (setf (nth (+ shift-by old-position) new-images) tmp) 
    67         (change-slot-values poi 'bos.m2::images new-images))) 
     66        (with-transaction ("setf poi-images") 
     67          (setf (poi-images poi) new-images)))) 
    6868    (with-bos-cms-page (:title "Edit POI") 
    6969      (content-language-chooser) 
     
    112112                   do (html (:td ((:a :href (format nil "/edit-poi-image/~a?poi=~A" (store-object-id image) (store-object-id poi))) 
    113113                                  ((:img :border "0" :src (format nil "/image/~a/thumbnail,,55,55" (store-object-id image))))) 
    114                                  :br 
    115                                  (if (eql index 1) 
    116                                      (html ((:img :src "/images/trans.gif" :width "16"))) 
    117                                      (html ((:a :href (format nil "/edit-poi/~A?shift=~A&shift-by=-1" 
    118                                                               (store-object-id poi) 
    119                                                               (store-object-id image))) 
    120                                             ((:img :border "0" :src "/images/pfeil-l.gif"))))) 
    121                                  ((:img :src "/images/trans.gif" :width "23")) 
    122                                  (unless (eql index (length (poi-images poi))) 
    123                                    (html ((:a :href (format nil "/edit-poi/~A?shift=~A&shift-by=1" 
    124                                                             (store-object-id poi) 
    125                                                             (store-object-id image))) 
    126                                           ((:img :border "0" :src "/images/pfeil-r.gif")))))))))) 
     114                             :br 
     115                             (if (eql index 1) 
     116                                 (html ((:img :src "/images/trans.gif" :width "16"))) 
     117                                 (html ((:a :href (format nil "/edit-poi/~A?shift=~A&shift-by=-1" 
     118                                                          (store-object-id poi) 
     119                                                          (store-object-id image))) 
     120                                        ((:img :border "0" :src "/images/pfeil-l.gif"))))) 
     121                             ((:img :src "/images/trans.gif" :width "23")) 
     122                             (unless (eql index (length (poi-images poi))) 
     123                               (html ((:a :href (format nil "/edit-poi/~A?shift=~A&shift-by=1" 
     124                                                        (store-object-id poi) 
     125                                                        (store-object-id image))) 
     126                                      ((:img :border "0" :src "/images/pfeil-r.gif")))))))))) 
    127127              (unless (eql 6 (length (poi-images poi))) 
    128128                (html 
     
    140140                            :br 
    141141                            (submit-button "upload-airal" "upload-airal"))))) 
    142         (:tr (:td "panorama view") 
     142        (:tr (:td "panorama view" 
     143                  ((:input :id "panorama-id" :type "hidden" :name "panorama-id"))) 
    143144             (:td (dolist (panorama (poi-panoramas poi)) 
    144145                    (html (:princ-safe (format-date-time (blob-timestamp panorama))) 
    145146                          ((:a :href (format nil "/image/~D" (store-object-id panorama)) :target "_new" :class "cmslink") 
    146147                           " view ") 
    147                           (submit-button "delete-panorama" "delete-panorama" :confirm "Really delete this panorama image?") 
     148                          (submit-button "delete-panorama" "delete-panorama" 
     149                                         :formcheck #?"javascript:confirm_delete('panorama-id', $((store-object-id panorama)), 'Really delete this panorama image?')") 
    148150                          :br)) 
    149151                  (html "Upload new panorama view" 
     
    192194      (error "no file uploaded in upload handler")) 
    193195    (with-image-from-upload* (uploaded-file) 
    194       (unless (and (eql (cl-gd:image-width) *poi-image-width*) 
    195                    (eql (cl-gd:image-height) *poi-image-height*)) 
    196         (with-bos-cms-page (:title "Invalid image size") 
    197           (:h2 "Invalid image size") 
    198           (:p "The image needs to be " 
    199               (:princ-safe *poi-image-width*) " pixels wide and " 
    200               (:princ-safe *poi-image-height*) " pixels high.  Your uploaded image is " 
    201               (:princ-safe (cl-gd:image-width)) " pixels wide and " 
    202               (:princ-safe (cl-gd:image-height)) " pixels high.  Please use an image editor " 
    203               "to resize the image and upload it again.") 
    204           (:p (cmslink (edit-object-url poi) "Back to POI"))) 
    205         (return-from handle-object-form t))) 
    206     (change-slot-values poi 'airals (list (import-image (upload-pathname uploaded-file) 
    207                                                         :class-name 'store-image)))) 
    208   (redirect (format nil "/edit-poi/~D" 
    209                     (store-object-id poi)))) 
     196      (cond 
     197        ((and (eql (cl-gd:image-width) *poi-image-width*) 
     198              (eql (cl-gd:image-height) *poi-image-height*)) 
     199         (with-transaction ("set airals") 
     200           (setf (poi-airals poi) (print (list (import-image uploaded-file :class-name 'store-image))))) 
     201         (redirect (format nil "/edit-poi/~D" 
     202                           (store-object-id poi)))) 
     203        (t 
     204         (with-bos-cms-page (:title "Invalid image size") 
     205           (:h2 "Invalid image size") 
     206           (:p "The image needs to be " 
     207               (:princ-safe *poi-image-width*) " pixels wide and " 
     208               (:princ-safe *poi-image-height*) " pixels high.  Your uploaded image is " 
     209               (:princ-safe (cl-gd:image-width)) " pixels wide and " 
     210               (:princ-safe (cl-gd:image-height)) " pixels high.  Please use an image editor " 
     211               "to resize the image and upload it again.") 
     212           (:p (cmslink (edit-object-url poi) "Back to POI")))))))) 
    210213 
    211214(defmethod handle-object-form ((handler edit-poi-handler) 
     
    213216                               (poi poi)) 
    214217  (let ((airals (poi-airals poi))) 
    215     (change-slot-values poi 'airals nil) 
     218    (with-transaction ("setf poi-airals nil") 
     219      (setf (poi-airals poi) nil)) 
    216220    (mapc #'delete-object airals)) 
    217221  (redirect (format nil "/edit-poi/~D" 
     
    221225                               (action (eql :delete-movie)) 
    222226                               (poi poi)) 
    223   (change-slot-values poi 'movies nil) 
     227  (with-transaction ("setf poi-movies nil") 
     228    (setf (poi-movies poi) nil)) 
    224229  (redirect (format nil "/edit-poi/~D" (store-object-id poi)))) 
    225230 
     
    230235    (unless uploaded-file 
    231236      (error "no file uploaded in upload handler")) 
    232     (with-image-from-upload* (uploaded-file) 
    233                                         ; just open the image to make sure that gd can process it 
    234       ) 
    235     (change-slot-values poi 'panoramas (cons (import-image (upload-pathname uploaded-file) 
    236                                                            :class-name 'store-image) 
    237                                              (poi-panoramas poi)))) 
     237    ;; just open the image to make sure that gd can process it 
     238    (with-image-from-upload* (uploaded-file)) 
     239    (with-transaction ("add poi-panorama") 
     240      (push (import-image uploaded-file :class-name 'store-image) (poi-panoramas poi)))) 
    238241  (redirect (format nil "/edit-poi/~D" 
    239242                    (store-object-id poi)))) 
     
    244247  (with-query-params (panorama-id) 
    245248    (let ((panorama (find-store-object (parse-integer panorama-id)))) 
    246       (change-slot-values poi 'panoramas (remove panorama (poi-panoramas poi))) 
    247       (mapc #'delete-object panorama))) 
     249      (with-transaction ("delete poi-panorama") 
     250        (alexandria:deletef (poi-panoramas poi) panorama)) 
     251      (delete-object panorama))) 
    248252  (redirect (format nil "/edit-poi/~D" 
    249253                    (store-object-id poi)))) 
     
    293297      (if poi-image 
    294298          (blob-from-file poi-image uploaded-file) 
    295           (setq poi-image (import-image (upload-pathname uploaded-file) 
     299          (setq poi-image (import-image uploaded-file 
    296300                                        :class-name 'poi-image 
    297301                                        :initargs `(:poi ,poi)))) 
     
    315319                (:tr (:td "upload new image") 
    316320                     (:td ((:input :type "file" :name "image-file")) 
    317                           :br 
    318                           (submit-button "upload" "upload"))) 
     321                      :br 
     322                      (submit-button "upload" "upload"))) 
    319323                (:tr (:td "title") 
    320324                     (:td (text-field "title" 
     
    365369                         (reduce #'max last-paid-contracts 
    366370                                 :key (lambda (contract) (store-object-last-change contract 0)))))) 
    367     (hunchentoot:handle-if-modified-since timestamp)   
     371    (hunchentoot:handle-if-modified-since timestamp) 
    368372    (setf (hunchentoot:header-out :last-modified) 
    369373          (hunchentoot:rfc-1123-date timestamp)) 
    370     (with-http-response (:content-type "text/html; charset=UTF-8")     
     374    (with-http-response (:content-type "text/html; charset=UTF-8") 
    371375      (with-http-body () 
    372376        (html 
     
    410414               (with-element "image" 
    411415                 (attribute "id" (princ-to-string (store-object-id image))) 
    412                  (when (typep image 'poi-image)                    
     416                 (when (typep image 'poi-image) 
    413417                   (attribute "title" (slot-string image 'title language)) 
    414                    (attribute "subtitle" (slot-string image 'subtitle language))                    
     418                   (attribute "subtitle" (slot-string image 'subtitle language)) 
    415419                   (with-element "description" (text (slot-string image 'description language)))) 
    416420                 (with-element "url" (text (format nil "http://createrainforest.org/image/~D" 
    417                                                    (store-object-id image))))                  
     421                                                   (store-object-id image)))) 
    418422                 (with-element "width" (text (princ-to-string (store-image-width image)))) 
    419423                 (with-element "height" (text (princ-to-string (store-image-height image))))))) 
     
    481485             (with-element "tr" 
    482486               (dolist (image images) 
    483                  (img-td image)))                     
     487                 (img-td image))) 
    484488             ;; titles 
    485489             (with-element "tr" 
     
    488492    (handler-case 
    489493        (with-xml-output (make-string-sink) 
    490           (with-element "html"     
     494          (with-element "html" 
    491495            (with-element "head") 
    492496            (with-element "body" 
    493497              (with-element "table" 
    494498                (attribute "cellspacing" "0") (attribute "width" "500") (attribute "cellpadding" "5") (attribute "border" "0") 
    495                 (attribute "style" "background-color: rgb(186, 186, 186);")                 
     499                (attribute "style" "background-color: rgb(186, 186, 186);") 
    496500                (with-element "tbody" 
    497501                  (with-element "tr" 
     
    567571(defmethod handle-object ((handler poi-xml-handler) poi) 
    568572  (let ((timestamp (store-object-last-change poi 1))) 
    569     (hunchentoot:handle-if-modified-since timestamp)   
     573    (hunchentoot:handle-if-modified-since timestamp) 
    570574    (setf (hunchentoot:header-out :last-modified) 
    571575          (hunchentoot:rfc-1123-date timestamp)) 
     
    581585(defmethod handle-object ((handler poi-kml-handler) poi) 
    582586  (with-query-params ((lang "en")) 
    583     (with-xml-response ()       
     587    (with-xml-response () 
    584588      (with-namespace (nil "http://earth.google.com/kml/2.1") 
    585589        (with-element "kml" 
     
    611615              (kml-region (make-rectangle2 (list 0 0 +width+ +width+)) '(:min 600 :max -1)) 
    612616              (mapc #'(lambda (poi) (write-poi-kml poi lang)) relevant-pois)))))))) 
    613  
    614  
  • trunk/projects/bos/web/webserver.lisp

    r3644 r3653  
    226226                 :site-logo-url "/images/bos-logo.gif" 
    227227                 :style-sheet-urls '("/static/cms.css") 
    228                  :javascript-urls '("/static/cms.js" "/static/tiny_mce/tiny_mce.js")) 
     228                 :javascript-urls '("/static/cms.js" "/static/tiny_mce/tiny_mce.js" "/static/MochiKit/MochiKit.js")) 
    229229 
    230230  (publish-directory :prefix "/static/"