Skip to content

Commit acfe4de

Browse files
authored
Merge pull request #1231 from imachug/issue-1229
Sign & Publish in one button
2 parents 342f9f6 + bcc3b4d commit acfe4de

File tree

7 files changed

+338
-20
lines changed

7 files changed

+338
-20
lines changed

plugins/Sidebar/SidebarPlugin.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,10 @@ def sidebarRenderContents(self, body, site):
428428
body.append(_(u"""
429429
<div class='flex'>
430430
<input type='text' class='text' value="content.json" id='input-contents'/>
431-
<a href='#Sign' class='button' id='button-sign'>{_[Sign]}</a>
432-
<a href='#Publish' class='button' id='button-publish'>{_[Publish]}</a>
431+
<span id='wrapper-sign-publish' class='button'>
432+
<a href='#Sign-and-Publish' id='button-sign-publish'>{_[Sign and publish]}</a>
433+
<a href='#Sign-and-Publish' id='menu-sign-publish'>\u22EE</a>
434+
</span>
433435
</div>
434436
</li>
435437
"""))
@@ -468,6 +470,10 @@ def actionSidebarGetHtmlTag(self, to):
468470
body.append("</ul>")
469471
body.append("</div>")
470472

473+
body.append("<div class='menu template'>")
474+
body.append("<a href='#'' class='menu-item template'>Template</a>")
475+
body.append("</div>")
476+
471477
self.response(to, "".join(body))
472478

473479
def downloadGeoLiteDb(self, db_path):

plugins/Sidebar/media/Menu.coffee

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
class Menu
2+
constructor: (@button) ->
3+
@elem = $(".menu.template").clone().removeClass("template")
4+
@elem.appendTo("body")
5+
@items = []
6+
7+
show: ->
8+
if window.visible_menu and window.visible_menu.button[0] == @button[0] # Same menu visible then hide it
9+
window.visible_menu.hide()
10+
@hide()
11+
else
12+
button_pos = @button.offset()
13+
@elem.css({"top": button_pos.top+@button.outerHeight(), "left": button_pos.left})
14+
@button.addClass("menu-active")
15+
@elem.addClass("visible")
16+
if window.visible_menu then window.visible_menu.hide()
17+
window.visible_menu = @
18+
19+
20+
hide: ->
21+
@elem.removeClass("visible")
22+
@button.removeClass("menu-active")
23+
window.visible_menu = null
24+
25+
26+
addItem: (title, cb) ->
27+
item = $(".menu-item.template", @elem).clone().removeClass("template")
28+
item.html(title)
29+
item.on "click", =>
30+
if not cb(item)
31+
@hide()
32+
return false
33+
item.appendTo(@elem)
34+
@items.push item
35+
return item
36+
37+
38+
log: (args...) ->
39+
console.log "[Menu]", args...
40+
41+
window.Menu = Menu
42+
43+
# Hide menu on outside click
44+
$("body").on "click", (e) ->
45+
if window.visible_menu and e.target != window.visible_menu.button[0] and $(e.target).parent()[0] != window.visible_menu.elem[0]
46+
window.visible_menu.hide()

plugins/Sidebar/media/Menu.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.menu {
2+
background-color: white; padding: 10px 0px; position: absolute; top: 0px; left: 0px; max-height: 0px; overflow: hidden; transform: translate(0px, -30px); pointer-events: none;
3+
box-shadow: 0px 2px 8px rgba(0,0,0,0.3); border-radius: 2px; opacity: 0; transition: opacity 0.2s ease-out, transform 1s ease-out, max-height 0.2s ease-in-out;
4+
}
5+
.menu.visible { opacity: 1; max-height: 350px; transform: translate(0px, 0px); transition: opacity 0.1s ease-out, transform 0.3s ease-out, max-height 0.3s ease-in-out; pointer-events: all }
6+
7+
.menu-item { display: block; text-decoration: none; color: black; padding: 6px 24px; transition: all 0.2s; border-bottom: none; font-weight: normal; padding-left: 30px; }
8+
.menu-item-separator { margin-top: 5px; border-top: 1px solid #eee }
9+
10+
.menu-item:hover { background-color: #F6F6F6; transition: none; color: inherit; border: none }
11+
.menu-item:active, .menu-item:focus { background-color: #AF3BFF; color: white; transition: none }
12+
.menu-item.selected:before {
13+
content: "L"; display: inline-block; transform: rotateZ(45deg) scaleX(-1);
14+
font-weight: bold; position: absolute; margin-left: -17px; font-size: 12px; margin-top: 2px;
15+
}
16+
17+
@media only screen and (max-width: 800px) {
18+
.menu, .menu.visible { position: absolute; left: unset !important; right: 20px; }
19+
}

plugins/Sidebar/media/Sidebar.coffee

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,13 @@ class Sidebar extends Class
354354
@updateHtmlTag()
355355
return false
356356

357-
# Sign content.json
358-
@tag.find("#button-sign").off("click touchend").on "click touchend", =>
357+
# Sign and publish content.json
358+
$(document).on "click touchend", =>
359+
@tag.find("#button-sign-publish-menu").removeClass("visible")
360+
@tag.find(".contents + .flex").removeClass("sign-publish-flex")
361+
362+
menu = new Menu(@tag.find("#wrapper-sign-publish"))
363+
menu.addItem "Sign", =>
359364
inner_path = @tag.find("#input-contents").val()
360365

361366
wrapper.ws.cmd "fileRules", {inner_path: inner_path}, (res) =>
@@ -372,14 +377,47 @@ class Sidebar extends Class
372377
if res == "ok"
373378
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
374379

380+
@tag.find(".contents + .flex").removeClass "active"
381+
menu.hide()
382+
383+
menu.addItem "Publish", =>
384+
inner_path = @tag.find("#input-contents").val()
385+
wrapper.ws.cmd "sitePublish", {"inner_path": inner_path, "sign": false}
386+
387+
@tag.find(".contents + .flex").removeClass "active"
388+
menu.hide()
389+
390+
@tag.find("#menu-sign-publish").off("click touchend").on "click touchend", =>
391+
if window.visible_menu == menu
392+
@tag.find(".contents + .flex").removeClass "active"
393+
menu.hide()
394+
else
395+
@tag.find(".contents + .flex").addClass "active"
396+
@tag.find(".content-wrapper").prop "scrollTop", 10000
397+
menu.show()
375398
return false
376399

377-
# Publish content.json
378-
@tag.find("#button-publish").off("click touchend").on "click touchend", =>
400+
$("body").on "click", =>
401+
@tag.find(".contents + .flex").removeClass "active"
402+
403+
@tag.find("#button-sign-publish").off("click touchend").on "click touchend", =>
379404
inner_path = @tag.find("#input-contents").val()
380-
@tag.find("#button-publish").addClass "loading"
381-
wrapper.ws.cmd "sitePublish", {"inner_path": inner_path, "sign": false}, =>
382-
@tag.find("#button-publish").removeClass "loading"
405+
406+
wrapper.ws.cmd "fileRules", {inner_path: inner_path}, (res) =>
407+
if wrapper.site_info.privatekey or wrapper.site_info.auth_address in res.signers
408+
# Privatekey stored in users.json
409+
wrapper.ws.cmd "sitePublish", {privatekey: "stored", inner_path: inner_path, sign: true}, (res) =>
410+
if res == "ok"
411+
wrapper.notifications.add "sign", "done", "#{inner_path} Signed and published!", 5000
412+
413+
else
414+
# Ask the user for privatekey
415+
wrapper.displayPrompt "Enter your private key:", "password", "Sign", "", (privatekey) => # Prompt the private key
416+
wrapper.ws.cmd "sitePublish", {privatekey: privatekey, inner_path: inner_path, sign: true}, (res) =>
417+
if res == "ok"
418+
wrapper.notifications.add "sign", "done", "#{inner_path} Signed and published!", 5000
419+
420+
return false
383421

384422
# Close
385423
@tag.find(".close").off("click touchend").on "click touchend", (e) =>

plugins/Sidebar/media/Sidebar.css

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.menu {
2+
font-family: Roboto, 'Segoe UI', 'Helvetica Neue';
3+
}
4+
15
.drag-bg { width: 100%; height: 100%; position: fixed; }
26
.fixbutton.dragging { cursor: -webkit-grabbing; }
37
.fixbutton-bg:active { cursor: -webkit-grabbing; }
@@ -112,7 +116,7 @@
112116
#checkbox-owned { margin-bottom: 25px; margin-top: 26px; margin-left: 11px; }
113117
.settings-owned { clear: both }
114118
#checkbox-owned ~ .settings-owned { opacity: 0; max-height: 0px; transition: all 0.3s linear; overflow: hidden }
115-
#checkbox-owned:checked ~ .settings-owned { opacity: 1; max-height: 400px }
119+
#checkbox-owned:checked ~ .settings-owned { opacity: 1; max-height: 420px }
116120

117121
/* Globe */
118122
.globe { width: 360px; height: 360px }
@@ -124,6 +128,25 @@
124128
.contents a { color: white }
125129
.contents a:active { background-color: #6B6B6B }
126130

131+
.contents + .flex.active {
132+
padding-bottom: 100px;
133+
}
134+
#wrapper-sign-publish {
135+
padding: 0;
136+
}
137+
#button-sign-publish, #menu-sign-publish {
138+
display: inline-block;
139+
margin: 5px 10px;
140+
141+
text-decoration: none;
142+
}
143+
#button-sign-publish {
144+
margin-right: 5px;
145+
}
146+
#menu-sign-publish {
147+
margin-left: 5px;
148+
}
149+
127150
/* Small screen */
128151
@media screen and (max-width: 600px) {
129152
.sidebar .close { display: block }

plugins/Sidebar/media/all.css

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11

22

3+
/* ---- plugins/Sidebar/media/Menu.css ---- */
4+
5+
6+
.menu {
7+
background-color: white; padding: 10px 0px; position: absolute; top: 0px; left: 0px; max-height: 0px; overflow: hidden; -webkit-transform: translate(0px, -30px); -moz-transform: translate(0px, -30px); -o-transform: translate(0px, -30px); -ms-transform: translate(0px, -30px); transform: translate(0px, -30px) ; pointer-events: none;
8+
-webkit-box-shadow: 0px 2px 8px rgba(0,0,0,0.3); -moz-box-shadow: 0px 2px 8px rgba(0,0,0,0.3); -o-box-shadow: 0px 2px 8px rgba(0,0,0,0.3); -ms-box-shadow: 0px 2px 8px rgba(0,0,0,0.3); box-shadow: 0px 2px 8px rgba(0,0,0,0.3) ; -webkit-border-radius: 2px; -moz-border-radius: 2px; -o-border-radius: 2px; -ms-border-radius: 2px; border-radius: 2px ; opacity: 0; -webkit-transition: opacity 0.2s ease-out, transform 1s ease-out, max-height 0.2s ease-in-out; -moz-transition: opacity 0.2s ease-out, transform 1s ease-out, max-height 0.2s ease-in-out; -o-transition: opacity 0.2s ease-out, transform 1s ease-out, max-height 0.2s ease-in-out; -ms-transition: opacity 0.2s ease-out, transform 1s ease-out, max-height 0.2s ease-in-out; transition: opacity 0.2s ease-out, transform 1s ease-out, max-height 0.2s ease-in-out ;
9+
}
10+
.menu.visible { opacity: 1; max-height: 350px; -webkit-transform: translate(0px, 0px); -moz-transform: translate(0px, 0px); -o-transform: translate(0px, 0px); -ms-transform: translate(0px, 0px); transform: translate(0px, 0px) ; -webkit-transition: opacity 0.1s ease-out, transform 0.3s ease-out, max-height 0.3s ease-in-out; -moz-transition: opacity 0.1s ease-out, transform 0.3s ease-out, max-height 0.3s ease-in-out; -o-transition: opacity 0.1s ease-out, transform 0.3s ease-out, max-height 0.3s ease-in-out; -ms-transition: opacity 0.1s ease-out, transform 0.3s ease-out, max-height 0.3s ease-in-out; transition: opacity 0.1s ease-out, transform 0.3s ease-out, max-height 0.3s ease-in-out ; pointer-events: all }
11+
12+
.menu-item { display: block; text-decoration: none; color: black; padding: 6px 24px; -webkit-transition: all 0.2s; -moz-transition: all 0.2s; -o-transition: all 0.2s; -ms-transition: all 0.2s; transition: all 0.2s ; border-bottom: none; font-weight: normal; padding-left: 30px; }
13+
.menu-item-separator { margin-top: 5px; border-top: 1px solid #eee }
14+
15+
.menu-item:hover { background-color: #F6F6F6; -webkit-transition: none; -moz-transition: none; -o-transition: none; -ms-transition: none; transition: none ; color: inherit; border: none }
16+
.menu-item:active, .menu-item:focus { background-color: #AF3BFF; color: white; -webkit-transition: none ; -moz-transition: none ; -o-transition: none ; -ms-transition: none ; transition: none }
17+
.menu-item.selected:before {
18+
content: "L"; display: inline-block; -webkit-transform: rotateZ(45deg) scaleX(-1); -moz-transform: rotateZ(45deg) scaleX(-1); -o-transform: rotateZ(45deg) scaleX(-1); -ms-transform: rotateZ(45deg) scaleX(-1); transform: rotateZ(45deg) scaleX(-1) ;
19+
font-weight: bold; position: absolute; margin-left: -17px; font-size: 12px; margin-top: 2px;
20+
}
21+
22+
@media only screen and (max-width: 800px) {
23+
.menu, .menu.visible { position: absolute; left: unset !important; right: 20px; }
24+
}
25+
26+
327
/* ---- plugins/Sidebar/media/Scrollbable.css ---- */
428

529

@@ -52,6 +76,10 @@
5276
/* ---- plugins/Sidebar/media/Sidebar.css ---- */
5377

5478

79+
.menu {
80+
font-family: Roboto, 'Segoe UI', 'Helvetica Neue';
81+
}
82+
5583
.drag-bg { width: 100%; height: 100%; position: fixed; }
5684
.fixbutton.dragging { cursor: -webkit-grabbing; }
5785
.fixbutton-bg:active { cursor: -webkit-grabbing; }
@@ -166,7 +194,7 @@
166194
#checkbox-owned { margin-bottom: 25px; margin-top: 26px; margin-left: 11px; }
167195
.settings-owned { clear: both }
168196
#checkbox-owned ~ .settings-owned { opacity: 0; max-height: 0px; -webkit-transition: all 0.3s linear; -moz-transition: all 0.3s linear; -o-transition: all 0.3s linear; -ms-transition: all 0.3s linear; transition: all 0.3s linear ; overflow: hidden }
169-
#checkbox-owned:checked ~ .settings-owned { opacity: 1; max-height: 400px }
197+
#checkbox-owned:checked ~ .settings-owned { opacity: 1; max-height: 420px }
170198

171199
/* Globe */
172200
.globe { width: 360px; height: 360px }
@@ -178,6 +206,25 @@
178206
.contents a { color: white }
179207
.contents a:active { background-color: #6B6B6B }
180208

209+
.contents + .flex.active {
210+
padding-bottom: 100px;
211+
}
212+
#wrapper-sign-publish {
213+
padding: 0;
214+
}
215+
#button-sign-publish, #menu-sign-publish {
216+
display: inline-block;
217+
margin: 5px 10px;
218+
219+
text-decoration: none;
220+
}
221+
#button-sign-publish {
222+
margin-right: 5px;
223+
}
224+
#menu-sign-publish {
225+
margin-left: 5px;
226+
}
227+
181228
/* Small screen */
182229
@media screen and (max-width: 600px) {
183230
.sidebar .close { display: block }

0 commit comments

Comments
 (0)