|
23 | 23 |
|
24 | 24 | (def schdbmeta {:name "schematics" :url cm/default-sync})
|
25 | 25 |
|
| 26 | +(defonce modal-content (r/atom nil)) |
| 27 | + |
| 28 | +(defn modal [] |
| 29 | + [:div.modal |
| 30 | + {:class (if @modal-content "visible" "hidden")} |
| 31 | + @modal-content]) |
| 32 | + |
| 33 | +(defn prompt [text cb] |
| 34 | + (reset! modal-content |
| 35 | + [:form {:on-submit (fn [^js e] |
| 36 | + (js/console.log e) |
| 37 | + (.preventDefault e) |
| 38 | + (let [name (.. e -target -elements -valuefield -value)] |
| 39 | + (when (seq name) |
| 40 | + (cb name))) |
| 41 | + (reset! modal-content nil))} |
| 42 | + [:div text] |
| 43 | + [:input {:name "valuefield" :type "text"}] |
| 44 | + [:button {:on-click #(reset! modal-content nil)} "Cancel"] |
| 45 | + [:input {:type "submit" :value "Ok"}]])) |
| 46 | + |
26 | 47 | (defn get-dbatom [dbid]
|
27 | 48 | (if-let [pa (get @dbcache dbid)]
|
28 | 49 | pa
|
|
173 | 194 |
|
174 | 195 | (defn cell-view []
|
175 | 196 | (let [db (get-dbatom (or @seldb :schematics))
|
176 |
| - add-cell #(when-let [name (and @seldb (js/prompt "Enter the name of the new cell"))] |
177 |
| - (swap! db assoc (str "models" sep name) {:name name})) |
178 |
| - add-schem #(when-let [name (and @seldb @selcell (js/prompt "Enter the name of the new schematic"))] |
179 |
| - (swap! db assoc-in [@selcell :models (keyword name)] {:name name, :type "schematic"})) |
180 |
| - add-spice #(when-let [name (and @seldb @selcell (js/prompt "Enter the name of the new SPICE model"))] |
181 |
| - (swap! db assoc-in [@selcell :models (keyword name)] {:name name :type "spice"}))] |
| 197 | + add-cell #(prompt "Enter the name of the new cell" |
| 198 | + (fn [name] (swap! db assoc (str "models" sep name) {:name name}))) |
| 199 | + add-schem #(prompt "Enter the name of the new schematic" |
| 200 | + (fn [name] (swap! db assoc-in [@selcell :models (keyword name)] {:name name, :type "schematic"}))) |
| 201 | + add-spice #(prompt "Enter the name of the new SPICE model" |
| 202 | + (fn [name] (swap! db assoc-in [@selcell :models (keyword name)] {:name name :type "spice"})))] |
182 | 203 | [:<>
|
183 | 204 | [:div.schsel
|
184 | 205 | [:div.addbuttons
|
|
206 | 227 | [:div.libhead
|
207 | 228 | [:h1 "Library"]
|
208 | 229 | [:button.plus {:on-click
|
209 |
| - #(let [name (js/prompt "Enter the name of the new database")] |
210 |
| - (when (seq name) |
211 |
| - (swap! databases assoc (str "databases" sep name) {:name name})))} |
| 230 | + #(prompt "Enter the name of the new database" |
| 231 | + (fn [name] (swap! databases assoc (str "databases" sep name) {:name name})))} |
212 | 232 | "+"]]
|
213 | 233 | [database-selector]
|
214 | 234 | [db-properties]]
|
215 |
| - [cell-view]]) |
| 235 | + [cell-view] |
| 236 | + [modal]]) |
216 | 237 |
|
217 | 238 | (def shortcuts {})
|
218 | 239 |
|
|
0 commit comments