Skip to content

Commit bcc3b4d

Browse files
committed
Add sign/publish code
1 parent 5ff8d6b commit bcc3b4d

File tree

2 files changed

+71
-82
lines changed

2 files changed

+71
-82
lines changed

plugins/Sidebar/media/Sidebar.coffee

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,32 @@ class Sidebar extends Class
360360
@tag.find(".contents + .flex").removeClass("sign-publish-flex")
361361

362362
menu = new Menu(@tag.find("#wrapper-sign-publish"))
363-
menu.addItem "Sign"
364-
menu.addItem "Publush"
363+
menu.addItem "Sign", =>
364+
inner_path = @tag.find("#input-contents").val()
365+
366+
wrapper.ws.cmd "fileRules", {inner_path: inner_path}, (res) =>
367+
if wrapper.site_info.privatekey or wrapper.site_info.auth_address in res.signers
368+
# Privatekey stored in users.json
369+
wrapper.ws.cmd "siteSign", {privatekey: "stored", inner_path: inner_path, update_changed_files: true}, (res) =>
370+
if res == "ok"
371+
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
372+
373+
else
374+
# Ask the user for privatekey
375+
wrapper.displayPrompt "Enter your private key:", "password", "Sign", "", (privatekey) => # Prompt the private key
376+
wrapper.ws.cmd "siteSign", {privatekey: privatekey, inner_path: inner_path, update_changed_files: true}, (res) =>
377+
if res == "ok"
378+
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
379+
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()
365389

366390
@tag.find("#menu-sign-publish").off("click touchend").on "click touchend", =>
367391
if window.visible_menu == menu
@@ -393,36 +417,6 @@ class Sidebar extends Class
393417
if res == "ok"
394418
wrapper.notifications.add "sign", "done", "#{inner_path} Signed and published!", 5000
395419

396-
@tag.find("#button-sign-publish-menu").removeClass("visible")
397-
return false
398-
399-
# Sign content.json
400-
@tag.find("#button-sign").off("click touchend").on "click touchend", =>
401-
inner_path = @tag.find("#input-contents").val()
402-
403-
wrapper.ws.cmd "fileRules", {inner_path: inner_path}, (res) =>
404-
if wrapper.site_info.privatekey or wrapper.site_info.auth_address in res.signers
405-
# Privatekey stored in users.json
406-
wrapper.ws.cmd "siteSign", {privatekey: "stored", inner_path: inner_path, update_changed_files: true}, (res) =>
407-
if res == "ok"
408-
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
409-
410-
else
411-
# Ask the user for privatekey
412-
wrapper.displayPrompt "Enter your private key:", "password", "Sign", "", (privatekey) => # Prompt the private key
413-
wrapper.ws.cmd "siteSign", {privatekey: privatekey, inner_path: inner_path, update_changed_files: true}, (res) =>
414-
if res == "ok"
415-
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
416-
417-
@tag.find("#button-sign-publish-menu").removeClass("visible")
418-
return false
419-
420-
# Publish content.json
421-
@tag.find("#button-publish").off("click touchend").on "click touchend", =>
422-
inner_path = @tag.find("#input-contents").val()
423-
@tag.find("#button-publish").addClass "loading"
424-
wrapper.ws.cmd "sitePublish", {"inner_path": inner_path, "sign": false}, =>
425-
@tag.find("#button-publish").removeClass "loading"
426420
return false
427421

428422
# Close

plugins/Sidebar/media/all.js

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -693,27 +693,7 @@ window.initScrollable = function () {
693693
};
694694
})(this));
695695
menu = new Menu(this.tag.find("#wrapper-sign-publish"));
696-
menu.addItem("Sign");
697-
menu.addItem("Publush");
698-
this.tag.find("#menu-sign-publish").off("click touchend").on("click touchend", (function(_this) {
699-
return function() {
700-
if (window.visible_menu === menu) {
701-
_this.tag.find(".contents + .flex").removeClass("active");
702-
menu.hide();
703-
} else {
704-
_this.tag.find(".contents + .flex").addClass("active");
705-
_this.tag.find(".content-wrapper").prop("scrollTop", 10000);
706-
menu.show();
707-
}
708-
return false;
709-
};
710-
})(this));
711-
$("body").on("click", (function(_this) {
712-
return function() {
713-
return _this.tag.find(".contents + .flex").removeClass("active");
714-
};
715-
})(this));
716-
this.tag.find("#button-sign-publish").off("click touchend").on("click touchend", (function(_this) {
696+
menu.addItem("Sign", (function(_this) {
717697
return function() {
718698
var inner_path;
719699
inner_path = _this.tag.find("#input-contents").val();
@@ -722,34 +702,64 @@ window.initScrollable = function () {
722702
}, function(res) {
723703
var ref;
724704
if (wrapper.site_info.privatekey || (ref = wrapper.site_info.auth_address, indexOf.call(res.signers, ref) >= 0)) {
725-
return wrapper.ws.cmd("sitePublish", {
705+
return wrapper.ws.cmd("siteSign", {
726706
privatekey: "stored",
727707
inner_path: inner_path,
728-
sign: true
708+
update_changed_files: true
729709
}, function(res) {
730710
if (res === "ok") {
731-
return wrapper.notifications.add("sign", "done", inner_path + " Signed and published!", 5000);
711+
return wrapper.notifications.add("sign", "done", inner_path + " Signed!", 5000);
732712
}
733713
});
734714
} else {
735715
return wrapper.displayPrompt("Enter your private key:", "password", "Sign", "", function(privatekey) {
736-
return wrapper.ws.cmd("sitePublish", {
716+
return wrapper.ws.cmd("siteSign", {
737717
privatekey: privatekey,
738718
inner_path: inner_path,
739-
sign: true
719+
update_changed_files: true
740720
}, function(res) {
741721
if (res === "ok") {
742-
return wrapper.notifications.add("sign", "done", inner_path + " Signed and published!", 5000);
722+
return wrapper.notifications.add("sign", "done", inner_path + " Signed!", 5000);
743723
}
744724
});
745725
});
746726
}
747727
});
748-
_this.tag.find("#button-sign-publish-menu").removeClass("visible");
728+
_this.tag.find(".contents + .flex").removeClass("active");
729+
return menu.hide();
730+
};
731+
})(this));
732+
menu.addItem("Publish", (function(_this) {
733+
return function() {
734+
var inner_path;
735+
inner_path = _this.tag.find("#input-contents").val();
736+
wrapper.ws.cmd("sitePublish", {
737+
"inner_path": inner_path,
738+
"sign": false
739+
});
740+
_this.tag.find(".contents + .flex").removeClass("active");
741+
return menu.hide();
742+
};
743+
})(this));
744+
this.tag.find("#menu-sign-publish").off("click touchend").on("click touchend", (function(_this) {
745+
return function() {
746+
if (window.visible_menu === menu) {
747+
_this.tag.find(".contents + .flex").removeClass("active");
748+
menu.hide();
749+
} else {
750+
_this.tag.find(".contents + .flex").addClass("active");
751+
_this.tag.find(".content-wrapper").prop("scrollTop", 10000);
752+
menu.show();
753+
}
749754
return false;
750755
};
751756
})(this));
752-
this.tag.find("#button-sign").off("click touchend").on("click touchend", (function(_this) {
757+
$("body").on("click", (function(_this) {
758+
return function() {
759+
return _this.tag.find(".contents + .flex").removeClass("active");
760+
};
761+
})(this));
762+
this.tag.find("#button-sign-publish").off("click touchend").on("click touchend", (function(_this) {
753763
return function() {
754764
var inner_path;
755765
inner_path = _this.tag.find("#input-contents").val();
@@ -758,44 +768,29 @@ window.initScrollable = function () {
758768
}, function(res) {
759769
var ref;
760770
if (wrapper.site_info.privatekey || (ref = wrapper.site_info.auth_address, indexOf.call(res.signers, ref) >= 0)) {
761-
return wrapper.ws.cmd("siteSign", {
771+
return wrapper.ws.cmd("sitePublish", {
762772
privatekey: "stored",
763773
inner_path: inner_path,
764-
update_changed_files: true
774+
sign: true
765775
}, function(res) {
766776
if (res === "ok") {
767-
return wrapper.notifications.add("sign", "done", inner_path + " Signed!", 5000);
777+
return wrapper.notifications.add("sign", "done", inner_path + " Signed and published!", 5000);
768778
}
769779
});
770780
} else {
771781
return wrapper.displayPrompt("Enter your private key:", "password", "Sign", "", function(privatekey) {
772-
return wrapper.ws.cmd("siteSign", {
782+
return wrapper.ws.cmd("sitePublish", {
773783
privatekey: privatekey,
774784
inner_path: inner_path,
775-
update_changed_files: true
785+
sign: true
776786
}, function(res) {
777787
if (res === "ok") {
778-
return wrapper.notifications.add("sign", "done", inner_path + " Signed!", 5000);
788+
return wrapper.notifications.add("sign", "done", inner_path + " Signed and published!", 5000);
779789
}
780790
});
781791
});
782792
}
783793
});
784-
_this.tag.find("#button-sign-publish-menu").removeClass("visible");
785-
return false;
786-
};
787-
})(this));
788-
this.tag.find("#button-publish").off("click touchend").on("click touchend", (function(_this) {
789-
return function() {
790-
var inner_path;
791-
inner_path = _this.tag.find("#input-contents").val();
792-
_this.tag.find("#button-publish").addClass("loading");
793-
wrapper.ws.cmd("sitePublish", {
794-
"inner_path": inner_path,
795-
"sign": false
796-
}, function() {
797-
return _this.tag.find("#button-publish").removeClass("loading");
798-
});
799794
return false;
800795
};
801796
})(this));

0 commit comments

Comments
 (0)