unique id per instance with generated code

This commit is contained in:
David Botton 2022-01-26 18:43:52 -05:00
parent e78864a6af
commit 83fa7e7f00
2 changed files with 18 additions and 8 deletions

View file

@ -40,7 +40,7 @@ clog[] but is not in the DOM. If HTML-ID is nil one is generated.
(private)" (private)"
(let ((web-id (if html-id (let ((web-id (if html-id
html-id html-id
(clog-connection:generate-id)))) (format nil "CLOG~A" (clog-connection:generate-id)))))
(clog-connection:execute (clog-connection:execute
connection-id connection-id
(format nil (format nil
@ -86,15 +86,24 @@ CLOG-OBJ. If HTML-ID is nil one will be generated."))
;; attach-as-child ;; ;; attach-as-child ;;
;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;
(defgeneric attach-as-child (clog-obj html-id &key clog-type) (defgeneric attach-as-child (clog-obj html-id &key clog-type new-id)
(:documentation "Create a new CLOG-Element or sub-type of CLOG-TYPE and (:documentation "Create a new CLOG-ELEMENT or sub-type of CLOG-TYPE and
attach an existing element with HTML-ID. The HTML-ID must be unique and attach an existing element with HTML-ID. The HTML-ID must be unique and
must be in DOM, ie placed or auto-placed.")) must be in DOM, ie placed or auto-placed. If new-id is true the HTML-ID
after attachment is changed to one unique to this session."))
(defmethod attach-as-child ((obj clog-obj) html-id (defmethod attach-as-child ((obj clog-obj) html-id
&key (clog-type 'clog-element)) &key (clog-type 'clog-element)
(clog-connection:execute (connection-id obj) (new-id nil))
(format nil "clog['~A']=$('#~A').get(0)" html-id html-id)) (if new-id
(let ((id (format nil "CLOG~A" (clog-connection:generate-id))))
(clog-connection:execute (connection-id obj)
(format nil "$('#~A').attr('id','~A');clog['~A']=$('#~A').get(0)"
html-id id id id))
(setf html-id id))
(clog-connection:execute (connection-id obj)
(format nil "clog['~A']=$('#~A').get(0)"
html-id html-id)))
(make-clog-element (connection-id obj) html-id :clog-type clog-type)) (make-clog-element (connection-id obj) html-id :clog-type clog-type))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View file

@ -778,7 +778,8 @@ of controls and double click to select control."
vname) vname)
cmembers) cmembers)
(push (format nil (push (format nil
"\(setf (slot-value panel '~A\) \(attach-as-child clog-obj \"~A\" :clog-type \'~A\)\)~%" "\(setf (slot-value panel '~A\) ~
\(attach-as-child clog-obj \"~A\" :clog-type \'~A\ :new-id t)\)~%"
vname vname
html-id html-id
(format nil "CLOG:~A" (type-of control))) (format nil "CLOG:~A" (type-of control)))