rule.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. ---
  2. layout: default
  3. # This is where most of the code for CommunityRule lives
  4. # Follow comments below in various sections for further explanation
  5. ---
  6. <script>
  7. // Enter JavaScript-land!
  8. // First, some functions, followed by initialization commands
  9. // toggleVisible(id)
  10. // Toggles the visibility of a given element by given ID
  11. function toggleVisible(id) {
  12. var x = document.getElementById(id);
  13. if (x.style.display === "none") {
  14. x.style.display = "block";
  15. } else {
  16. x.style.display = "none";
  17. }
  18. }
  19. // classDisplayAll(className, value)
  20. // Assigns given display value to all elements with a given className
  21. function classDisplayAll(className, value) {
  22. var elements = document.getElementsByClassName(className);
  23. for (var i = 0; i < elements.length; i++) {
  24. elements[i].style.display = value;
  25. }
  26. }
  27. // toggleEditMode()
  28. // Toggles whether editable fields are editable or not
  29. // and removes editing tools.
  30. function toggleEditMode() {
  31. if (editMode === true) {
  32. editMode = false;
  33. classDisplayAll("section","block");
  34. classDisplayAll("button","none");
  35. classDisplayAll("question","none");
  36. var editableFields = document.getElementsByClassName("editable");
  37. // de-editable-ize the editable fields
  38. for (var i = 0; i < editableFields.length; i++) {
  39. editableFields[i].contentEditable = "false";
  40. editableFields[i].style.borderStyle = "none";
  41. // Remove empty fields entirely
  42. var content = editableFields[i].innerHTML;
  43. content = content.replace(/(<([^>]+)>)/ig,''); // strips stray tags
  44. if (content === "") {
  45. editableFields[i].style.display = "none";
  46. }
  47. }
  48. // Remove headers of empty sections
  49. // Inefficient! Might be merged with the above iteration
  50. var sections = document.getElementsByClassName("section");
  51. for (var i = 0; i < sections.length; i++) {
  52. var sectionQuestions = sections[i].getElementsByClassName("editable");
  53. var blanks = 0;
  54. for (var x = 0; x < sectionQuestions.length; x++) {
  55. var content = sectionQuestions[x].innerHTML;
  56. content = content.replace(/(<([^>]+)>)/ig,''); // strips stray tags
  57. if (content == "") { blanks++; }
  58. if (blanks == sectionQuestions.length) {
  59. var headerID = "header-s" + (i + 1);
  60. document.getElementById(headerID).style.display = "none";
  61. }
  62. }
  63. }
  64. // Finally, change button name
  65. document.getElementById("editToggle").innerHTML = "Customize";
  66. } else {
  67. editMode = true;
  68. classDisplayAll("button","block");
  69. classDisplayAll("question","block");
  70. classDisplayAll("editable","block");
  71. classDisplayAll("header","block");
  72. classDisplayAll("section","none");
  73. var editableFields = document.getElementsByClassName("editable");
  74. for (var i = 0; i < editableFields.length; i++) {
  75. editableFields[i].style.borderStyle = "none none dashed none";
  76. editableFields[i].contentEditable = "true";
  77. }
  78. // Change button name
  79. document.getElementById("editToggle").innerHTML = "Preview";
  80. }
  81. }
  82. // toggleDisplayMode()
  83. // toggles full displayMode, the Rule-only display for a published Rule
  84. // first, initialize variable:
  85. var displayMode = false;
  86. function toggleDisplayMode() {
  87. if (displayMode == false) {
  88. editMode = true;
  89. toggleEditMode(); // turns off editMode
  90. classDisplayAll("site-nav","none");
  91. classDisplayAll("post-header","none");
  92. classDisplayAll("site-footer","none");
  93. document.getElementById("attribution").style.display = "block";
  94. document.getElementById("toggleDisplayMode").style.display = "inline-block";
  95. document.getElementById("publishRule").style.display = "none";
  96. document.getElementById("trash").style.display = "inline-block";
  97. document.getElementById("title").innerHTML =
  98. document.getElementById("communityname").innerHTML + " / CommunityRule";
  99. displayMode = true;
  100. } else {
  101. toggleEditMode() // turns on editMode
  102. classDisplayAll("site-nav","block");
  103. classDisplayAll("post-header","block");
  104. classDisplayAll("site-footer","block");
  105. document.getElementById("attribution").style.display = "none";
  106. document.getElementById("toggleDisplayMode").style.display = "none";
  107. document.getElementById("publishRule").style.display = "inline-block";
  108. document.getElementById("trash").style.display = "none";
  109. displayMode = false;
  110. }
  111. }
  112. // textOutput()
  113. // Produces Markdown rendition of Rule
  114. function textOutput() {
  115. var filename = 'CommunityRule.txt';
  116. var content = '# '+ document.getElementById('communityname').innerHTML + '\n\n';
  117. content = content.replace(/(<([^>]+)>)/ig,''); // strips stray tags
  118. var elements = document.getElementsByClassName('output');
  119. for (var i = 1; i < elements.length; i++) {
  120. var thisBit = elements[i].innerHTML;
  121. thisBit = thisBit.replace(/(<([^>]+)>)/ig,''); // strips stray tags
  122. if (thisBit != "") {
  123. if (elements[i].classList.contains("subhead")) {
  124. content += '## ';
  125. }
  126. content += elements[i].innerHTML + '\n\n';
  127. }
  128. }
  129. content += document.getElementById('attributionMD').innerHTML;
  130. // Starting here, see https://stackoverflow.com/a/33542499
  131. var blob = new Blob([content], {type: 'text/plain'});
  132. if(window.navigator.msSaveOrOpenBlob) {
  133. window.navigator.msSaveBlob(blob, filename);
  134. }
  135. else{
  136. var elem = window.document.createElement('a');
  137. elem.href = window.URL.createObjectURL(blob);
  138. elem.download = filename;
  139. document.body.appendChild(elem);
  140. elem.click();
  141. document.body.removeChild(elem);
  142. URL.revokeObjectURL(); // This needs an arg but I can't figure out what
  143. }
  144. var myFile = new Blob([fileContent], {type: 'text/plain'});
  145. window.URL = window.URL || window.webkitURL; document.getElementById('download').setAttribute('href',window.URL.createObjectURL(myFile));
  146. document.getElementById('download').setAttribute('download', fileName);
  147. }
  148. // BEGIN Publish tools, via SteinHQ.com
  149. // publishRule()
  150. // Publishes existing fields to new page, /create/?rule=[ruleID]
  151. // Opens new page in Display mode
  152. function publishRule() {
  153. var now = new Date();
  154. // Numerical ID for published Rule
  155. var timeID = now.getTime();
  156. // Readable UTC timestamp
  157. var dateTime = now.getUTCFullYear()+'.'+(now.getUTCMonth()+1)+'.'+now.getUTCDate()
  158. +' '+now.getUTCHours()+":"+ now.getUTCMinutes()+":"+now.getUTCSeconds()
  159. + ' UTC';
  160. // TKTK: Check if ruleID exists; while yes, replace and repeat
  161. var rule = [{
  162. ruleID: timeID,
  163. timestamp: dateTime,
  164. }];
  165. var fields = document.getElementsByClassName("editable");
  166. for (var i = 0; i < fields.length; i++) {
  167. var key = fields[i].id;
  168. var value = fields[i].innerHTML.replace(/(<([^>]+)>)/ig,"");
  169. rule[0][key] = value;
  170. }
  171. const store = new SteinStore(
  172. "https://api.steinhq.com/v1/storages/5e8b937ab88d3d04ae0816a5"
  173. );
  174. store.append("rules", rule).then(data => {
  175. window.open("/create/?r=" + timeID, "_self", false);
  176. });
  177. }
  178. // displayRule(ID)
  179. // Displays content based on ID
  180. function displayRule(ID) {
  181. const store = new SteinStore(
  182. "https://api.steinhq.com/v1/storages/5e8b937ab88d3d04ae0816a5"
  183. );
  184. store.read("rules", { search: { ruleID: ID } }).then(data => {
  185. // only runs when we have the data from Goog:
  186. var rule = data[0];
  187. var fields = document.getElementsByClassName("editable");
  188. for (var i = 0; i < fields.length; i++) {
  189. var key = fields[i].id;
  190. var value = rule[key];
  191. if (typeof value === "undefined") {
  192. value = "";
  193. }
  194. document.getElementById(key).innerHTML = value;
  195. }
  196. // Publish timestamp to Rule
  197. document.getElementById('dateTime').innerHTML = rule['timestamp'];
  198. // Finish
  199. displayMode = false;
  200. toggleDisplayMode();
  201. document.title = rule['communityname'] + " / CommunityRule";
  202. });
  203. }
  204. // deleteRule()
  205. // A temporary placeholder that sends an email requesting rule deletion
  206. function deleteRule() {
  207. var urlParamz = new URLSearchParams(window.location.search);
  208. var rID = urlParamz.get('r');
  209. window.open("mailto:medlab@colorado.edu?subject=Delete Rule request ("
  210. + rID + ")&body=Please explain your rationale:\n");
  211. }
  212. // END Publish tools
  213. // FINALLY, Page loading
  214. // First, grab the current URL
  215. var urlParams = new URLSearchParams(window.location.search);
  216. // Determine if it is a published Rule
  217. if (urlParams.has('r')) {
  218. // If so, grab the Rule from database and enter displayMode
  219. var rID = urlParams.get('r');
  220. displayRule(rID);
  221. } else {
  222. // Otherwise, open in editMode as default
  223. var editMode = true;
  224. // switch out of editMode in special cases
  225. window.onload = function() {
  226. if ((window.location.href.indexOf("/templates/") != -1) ||
  227. (window.location.href.indexOf("/about/") != -1)) {
  228. toggleEditMode();
  229. }
  230. }
  231. }
  232. </script>
  233. <article class="post">
  234. <header class="post-header">
  235. <h1 class="post-title" id="title">
  236. {{ page.title }}
  237. </h1>
  238. <button class="pushButton" id="editToggle" onclick="toggleEditMode()">
  239. Preview</button>
  240. <div class="post-content">
  241. {{ content }}
  242. </div>
  243. </header>
  244. <div id="rulebox">
  245. <span class="question">What is the community’s name?</span>
  246. <h1 contenteditable="true" class="editable output" id="communityname">{{ page.community-name }}</h1>
  247. <!-- SECTION S1: BASICS -->
  248. <h2 id="header-s1" class="header">
  249. <img src="{% link assets/tabler_icons/info-circle.svg %}"
  250. class="icons" />
  251. <span class="subhead output">Basics</span>
  252. <button onclick="toggleVisible('s1')" class="button plus"> + </button>
  253. </h2>
  254. <div class="section" id="s1" style="display:none">
  255. <span class="question">What is the basic structure of the community?</span>
  256. <div class="button">Modules
  257. <span class="tooltiptext"><a target="_blank" href="https://democraticmediums.info/mediums/federation/">federation</a>, <a target="_blank" href="https://democraticmediums.info/mediums/friendship/">friendship</a>, <a target="_blank" href="https://democraticmediums.info/mediums/membership/">membership</a>, <a target="_blank" href="https://democraticmediums.info/mediums/multicameralism/">multicameralism</a>, <a target="_blank" href="https://democraticmediums.info/mediums/ritual/">ritual</a>, <a target="_blank" href="https://democraticmediums.info/mediums/separation_of_powers/">separation of powers</a>, <a target="_blank" href="https://democraticmediums.info/mediums/stake_weight/">stake weight</a></span>
  258. </div>
  259. <p contenteditable="true" class="editable output" id="structure">{{ page.structure }}</p>
  260. <span class="question">What is the community’s mission?</span>
  261. <p contenteditable="true" class="editable output" id="mission">{{ page.mission }}</p>
  262. <span class="question">What core values does the community hold?</span>
  263. <div class="button">Modules
  264. <span class="tooltiptext"><a target="_blank" href="https://democraticmediums.info/mediums/secrecy/">secrecy</a>, <a target="_blank" href="https://democraticmediums.info/mediums/solidarity/">solidarity</a>, <a target="_blank" href="https://democraticmediums.info/mediums/transparency/">transparency</a></span>
  265. </div>
  266. <p contenteditable="true" class="editable output" id="values">{{ page.values }}</p>
  267. <span class="question">What is the legal status of the community’s assets and creations?</span>
  268. <div class="button">Modules
  269. <span class="tooltiptext"><a target="_blank" href="https://medlabboulder.gitlab.io/democraticmediums/mediums/ownership/">ownership</a></span>
  270. </div>
  271. <p contenteditable="true" class="editable output" id="legal">{{ page.legal }}</p>
  272. </div><!--hiding section s1-->
  273. <!-- SECTION s2: PARTICIPANTS -->
  274. <h2 id="header-s2" class="header">
  275. <img src="{% link assets/tabler_icons/user.svg %}"
  276. class="icons" />
  277. <span class="subhead output">Participants</span>
  278. <button onclick="toggleVisible('s2')" class="button plus"> + </button>
  279. </h2>
  280. <div class="section" id="s2" style="display:none">
  281. <span class="question">How does someone become a participant?</span>
  282. <div class="button">Modules
  283. <span class="tooltiptext"><a target="_blank" href="https://democraticmediums.info/mediums/do-ocracy/">do-ocracy</a>, <a target="_blank" href="https://democraticmediums.info/mediums/friendship/">friendship</a>, <a target="_blank" href="https://democraticmediums.info/mediums/membership/">membership</a>, <a target="_blank" href="https://democraticmediums.info/mediums/reputation/">reputation</a></span>
  284. </div>
  285. <p contenteditable="true" class="editable output" id="membership">{{ page.membership }}</p>
  286. <span class="question">How are participants suspended or removed?</span>
  287. <div class="button">Modules
  288. <span class="tooltiptext"><a target="_blank" href="https://democraticmediums.info/mediums/exclusion/">exclusion</a>, <a target="_blank" href="https://democraticmediums.info/mediums/friendship/">friendship</a>, <a target="_blank" href="https://democraticmediums.info/mediums/reputation/">reputation</a></span>
  289. </div>
  290. <p contenteditable="true" class="editable output" id="removal">{{ page.removal }}</p>
  291. <span class="question">What special roles can participants hold, and how are roles assigned?</span>
  292. <div class="button">Modules
  293. <span class="tooltiptext"><a target="_blank" href="https://democraticmediums.info/mediums/delegation/">delegation</a>, <a target="_blank" href="https://democraticmediums.info/mediums/representation/">representation</a>, <a target="_blank" href="https://democraticmediums.info/mediums/separation_of_powers/">separation of powers</a></span>
  294. </div>
  295. <p contenteditable="true" class="editable output" id="roles">{{ page.roles }}</p>
  296. <span class="question">Are there limits on the terms or powers of participant roles?</span>
  297. <div class="button">Modules
  298. <span class="tooltiptext"><a target="_blank" href="https://democraticmediums.info/mediums/fact_finding/">fact-finding</a>, <a target="_blank" href="https://democraticmediums.info/mediums/ranked_choice/">ranked choice</a>, <a target="_blank" href="https://democraticmediums.info/mediums/representation/">representation</a>, <a target="_blank" href="https://democraticmediums.info/mediums/reputation/">reputation</a>, <a target="_blank" href="https://democraticmediums.info/mediums/sortition/">sortition</a>, <a target="_blank" href="https://democraticmediums.info/mediums/term_limit/">term limits</a></span>
  299. </div>
  300. <p contenteditable="true" class="editable output" id="limits">{{ page.limits }}</p>
  301. </div><!--hiding section s2-->
  302. <!--SECTION s3: POLICY-->
  303. <h2 id="header-s3" class="header">
  304. <img src="{% link assets/tabler_icons/news.svg %}"
  305. class="icons" />
  306. <span class="subhead output">Policy</span>
  307. <button onclick="toggleVisible('s3')" class="button plus"> + </button>
  308. </h2>
  309. <div class="section" id="s3" style="display:none">
  310. <span class="question">What basic rights does this Rule guarantee?</span>
  311. <p contenteditable="true" class="editable output" id="rights">{{ page.rights }}</p>
  312. <span class="question">Who has the capacity to decide on policies, and how do they do so?</span>
  313. <div class="button">Modules
  314. <span class="tooltiptext"><a target="_blank" href="https://democraticmediums.info/mediums/disapproval_voting/">disapproval voting</a>, <a target="_blank" href="https://democraticmediums.info/mediums/do-ocracy/">do-ocracy</a>, <a target="_blank" href="https://democraticmediums.info/mediums/holographic_consensus/">holographic consensus</a>, <a target="_blank" href="https://democraticmediums.info/mediums/quadratic_voting/">quadratic voting</a>, <a target="_blank" href="https://democraticmediums.info/mediums/referendum/">referendum</a>, <a target="_blank" href="https://democraticmediums.info/mediums/representation/">representation</a>, <a target="_blank" href="https://democraticmediums.info/mediums/sortition/">sortition</a></span>
  315. </div>
  316. <p contenteditable="true" class="editable output" id="decision">{{ page.decision }}</p>
  317. <span class="question">How are policies implemented?</span>
  318. <div class="button">Modules
  319. <span class="tooltiptext"><a target="_blank" href="https://democraticmediums.info/mediums/exclusion/">exclusion</a>, <a target="_blank" href="https://democraticmediums.info/mediums/lazy_consensus/">lazy consensus</a>, <a target="_blank" href="https://democraticmediums.info/mediums/restorative_justice/">restorative justice</a></span>
  320. </div>
  321. <p contenteditable="true" class="editable output" id="implementation">{{ page.implementation }}</p>
  322. <span class="question">How does the community monitor and evaluate its policy implementation? </span>
  323. <div class="button">Modules
  324. <span class="tooltiptext"><a target="_blank" href="https://democraticmediums.info/mediums/board/">board</a>, <a target="_blank" href="https://democraticmediums.info/mediums/disapproval_voting/">disapproval voting</a>, <a target="_blank" href="https://democraticmediums.info/mediums/judiciary/">jury</a>, <a target="_blank" href="https://democraticmediums.info/mediums/precedent/">precedent</a>, <a target="_blank" href="https://democraticmediums.info/mediums/refusal/">refusal</a>, <a target="_blank" href="https://democraticmediums.info/mediums/rough_consensus/">rough consensus</a></span>
  325. </div>
  326. <p contenteditable="true" class="editable output" id="oversight">{{ page.oversight }}</p>
  327. </div><!--hiding section s3-->
  328. <!-- SECTION s4: PROCESS -->
  329. <h2 id="header-s4" class="header">
  330. <img src="{% link assets/tabler_icons/refresh.svg %}"
  331. class="icons" />
  332. <span class="subhead output">Process</span>
  333. <button onclick="toggleVisible('s4')" class="button plus"> + </button>
  334. </h2>
  335. <div class="section" id="s4" style="display:none">
  336. <span class="question">How does the community manage access to administrative accounts and other tools?</span>
  337. <p contenteditable="true" class="editable output" id="access">{{ page.access }}</p>
  338. <span class="question">How does the community manage funds and economic flows?</span>
  339. <p contenteditable="true" class="editable output" id="economics">{{ page.economics }}</p>
  340. <span class="question">Where does the community deliberate about policies and governance?</span>
  341. <div class="button">Modules
  342. <span class="tooltiptext"><a target="_blank" href="https://democraticmediums.info/mediums/caucus/">caucus</a>, <a target="_blank" href="https://democraticmediums.info/mediums/coalition/">coalition</a>, <a target="_blank" href="https://democraticmediums.info/mediums/board/">board</a>, <a target="_blank" href="https://democraticmediums.info/mediums/debate/">debate</a>, <a target="_blank" href="https://democraticmediums.info/mediums/lobbying/">lobbying</a>, <a target="_blank" href="https://democraticmediums.info/mediums/recess/">recess</a>, <a target="_blank" href="https://democraticmediums.info/mediums/secrecy/">secrecy</a>, <a target="_blank" href="https://democraticmediums.info/mediums/transparency/">transparency</a></span>
  343. </div>
  344. <p contenteditable="true" class="editable output" id="deliberation">{{ page.deliberation }}</p>
  345. <span class="question">How are grievances among participants addressed?</span>
  346. <div class="button">Modules
  347. <span class="tooltiptext"><a target="_blank" href="https://democraticmediums.info/mediums/audit/">audit</a>, <a target="_blank" href="https://democraticmediums.info/mediums/debate/">debate</a>, <a target="_blank" href="https://democraticmediums.info/mediums/friendship/">friendship</a>, <a target="_blank" href="https://democraticmediums.info/mediums/restorative_justice/">restorative justice</a>, <a target="_blank" href="https://democraticmediums.info/mediums/recess/">recess</a></span>
  348. </div>
  349. <p contenteditable="true" class="editable output" id="grievances">{{ page.grievances }}</p>
  350. </div><!--hiding section s4-->
  351. <!-- SECTION s5: EVOLUTION -->
  352. <h2 id="header-s5" class="header">
  353. <img src="{% link assets/tabler_icons/adjustments.svg %}"
  354. class="icons" />
  355. <span class="subhead output">Evolution</span>
  356. <button onclick="toggleVisible('s5')" class="button plus"> + </button>
  357. </h2>
  358. <div class="section" id="s5" style="display:none">
  359. <span class="question">Where are policies and records kept?</span>
  360. <p contenteditable="true" class="editable output" id="records">{{ page.records }}</p>
  361. <span class="question">How can this Rule be modified?</span>
  362. <p contenteditable="true" class="editable output" id="modification">{{ page.modification }}</p>
  363. </div><!--hiding section s5-->
  364. <div id="attribution" style="display:none;">
  365. <br />
  366. <p><a href="https://communityrule.info">
  367. <img src="https://communityrule.info{% link assets/CommunityRule-derived-000000.svg %}" alt="CommunityRule derived"></a></p>
  368. <p id="dateTime"></p>
  369. <p>Created with <a href="https://communityrule.info">CommunityRule</a><br />
  370. <a href="https://creativecommons.org/licenses/by-sa/4.0/">Creative Commons BY-SA</a></p>
  371. <p><strong>The Publish feature is experimental. Rules may be removed without notice</strong></p>
  372. </div>
  373. <div id="attributionMD" style="display:none;">
  374. ---
  375. [![CommunityRule derived](https://communityrule.info{% link assets/CommunityRule-derived-000000.svg %})](https://communityrule.info)
  376. Created with [CommunityRule](https://communityrule.info)
  377. [Creative Commons BY-SA](https://creativecommons.org/licenses/by-sa/4.0/)</div>
  378. </div><!--#rulebox-->
  379. <button class="pushButton" id="publishRule" onclick="publishRule()">Publish</button>
  380. <button class="pushButton" id="toggleDisplayMode" onclick="toggleDisplayMode()">Fork</button>
  381. <button class="pushButton" onclick="textOutput()">Markdown</button>
  382. <button class="pushButton" id="trash" onclick="deleteRule()">
  383. <img src="{% link assets/tabler_icons/trash.svg %}" title="Rule deletion request" />
  384. </button>
  385. </article>