rule.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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. // Module-related drag-and-drop functions
  10. // source: https://www.codecanal.com/html5-drag-and-copy/
  11. function allowDrop(ev) {
  12. ev.preventDefault();
  13. }
  14. function drag(ev) {
  15. ev.dataTransfer.setData("text", ev.target.id);
  16. }
  17. function drop(ev) {
  18. ev.preventDefault();
  19. var target = ev.target;
  20. // Prevents dropping into text field
  21. if (target.id == "drag-directions") {
  22. target = target.parentElement;
  23. }
  24. // Set up transfer
  25. var data = ev.dataTransfer.getData("text");
  26. // Iff module is from the menu clone it
  27. var module = document.getElementById(data).cloneNode(true);
  28. module.id += "-dropped";
  29. // display the deletion button
  30. module.children[2].style.display = "inline";
  31. // pop it in!
  32. target.appendChild(module);
  33. // be sure the dummy text is gone
  34. target.children[0].style.display = "none";
  35. }
  36. // toggleVisible(id)
  37. // Toggles the visibility of a given element by given ID
  38. function toggleVisible(id) {
  39. var x = document.getElementById(id);
  40. if (x.style.display === "none") {
  41. x.style.display = "block";
  42. } else {
  43. x.style.display = "none";
  44. }
  45. }
  46. // classDisplayAll(className, value)
  47. // Assigns given display value to all elements with a given className
  48. function classDisplayAll(className, value) {
  49. var elements = document.getElementsByClassName(className);
  50. for (var i = 0; i < elements.length; i++) {
  51. elements[i].style.display = value;
  52. }
  53. }
  54. // toggleEditMode()
  55. // Toggles whether editable fields are editable or not
  56. // and removes editing tools.
  57. function toggleEditMode() {
  58. if (editMode === true) { // switch to preview mode
  59. editMode = false;
  60. classDisplayAll("section","block");
  61. classDisplayAll("button","none");
  62. classDisplayAll("question","none");
  63. var editableFields = document.getElementsByClassName("editable");
  64. // de-editable-ize the editable fields
  65. for (var i = 0; i < editableFields.length; i++) {
  66. editableFields[i].contentEditable = "false";
  67. editableFields[i].style.borderStyle = "none";
  68. // Remove empty fields entirely
  69. var content = editableFields[i].innerHTML;
  70. content = content.replace(/(<([^>]+)>)/ig,''); // strips stray tags
  71. if (content === "") {
  72. editableFields[i].style.display = "none";
  73. }
  74. }
  75. // Remove headers of empty sections
  76. // Inefficient! Might be merged with the above iteration
  77. var sections = document.getElementsByClassName("section");
  78. for (var i = 0; i < sections.length; i++) {
  79. var sectionQuestions = sections[i].getElementsByClassName("editable");
  80. var blanks = 0;
  81. for (var x = 0; x < sectionQuestions.length; x++) {
  82. var content = sectionQuestions[x].innerHTML;
  83. content = content.replace(/(<([^>]+)>)/ig,''); // strips stray tags
  84. if (content == "") { blanks++; }
  85. if (blanks == sectionQuestions.length) {
  86. var headerID = "header-s" + (i + 1);
  87. document.getElementById(headerID).style.display = "none";
  88. }
  89. }
  90. }
  91. // Handle links
  92. // TKTK
  93. // Handle author link
  94. var authorName = document.getElementById("author-text").value;
  95. var authorURL = document.getElementById("author-url").value;
  96. if (authorName != "") {
  97. document.getElementById("authorship-words").style.display = "inline";
  98. if (authorURL != "") { // both author and URL present
  99. document.getElementById("authorship-result").innerHTML = "<a href='" + authorURL +"'>" + authorName + "</a>";
  100. document.getElementById("authorship-result").style.display = "inline";
  101. } else { // only authorName present
  102. document.getElementById("authorship-result").innerHTML = authorName;
  103. document.getElementById("authorship-result").style.display = "inline";
  104. }
  105. } else {
  106. document.getElementById("authorship").style.display = "none";
  107. }
  108. // Finally, change button name
  109. document.getElementById("editToggle").innerHTML = "Customize";
  110. } else { // Switch to editMode
  111. editMode = true;
  112. classDisplayAll("button","block");
  113. classDisplayAll("question","block");
  114. classDisplayAll("editable","block");
  115. classDisplayAll("header","block");
  116. classDisplayAll("section","none");
  117. classDisplayAll("link-text","inline");
  118. classDisplayAll("link-url","inline");
  119. // link handling TKTK
  120. // author handling
  121. document.getElementById("authorship-result").style.display = "none";
  122. document.getElementById("authorship-words").style.display = "none";
  123. document.getElementById("authorship").style.display = "block";
  124. // make all editable fields visible
  125. var editableFields = document.getElementsByClassName("editable");
  126. for (var i = 0; i < editableFields.length; i++) {
  127. editableFields[i].style.borderStyle = "none none dashed none";
  128. editableFields[i].contentEditable = "true";
  129. }
  130. // Change button name
  131. document.getElementById("editToggle").innerHTML = "Preview";
  132. }
  133. }
  134. // toggleDisplayMode()
  135. // toggles full displayMode, the Rule-only display for a published Rule
  136. // first, initialize variable:
  137. var displayMode = false;
  138. function toggleDisplayMode() {
  139. if (displayMode == false) {
  140. editMode = true;
  141. toggleEditMode(); // turns off editMode
  142. classDisplayAll("site-nav","none");
  143. classDisplayAll("post-header","none");
  144. classDisplayAll("site-footer","none");
  145. document.getElementById("attribution").style.display = "block";
  146. document.getElementById("toggleDisplayMode").style.display = "inline-block";
  147. document.getElementById("publishRule").style.display = "none";
  148. document.getElementById("trash").style.display = "inline-block";
  149. displayMode = true;
  150. } else {
  151. toggleEditMode() // turns on editMode
  152. classDisplayAll("site-nav","block");
  153. classDisplayAll("post-header","block");
  154. classDisplayAll("site-footer","block");
  155. document.getElementById("attribution").style.display = "none";
  156. document.getElementById("toggleDisplayMode").style.display = "none";
  157. document.getElementById("publishRule").style.display = "inline-block";
  158. document.getElementById("trash").style.display = "none";
  159. displayMode = false;
  160. }
  161. }
  162. // textOutput()
  163. // Produces Markdown rendition of Rule from Export button
  164. function textOutput() {
  165. var filename = 'GOVERNANCE.md';
  166. // First, add title, whether there is one or not
  167. var content = '# '+ document.getElementById('communityname').innerHTML + '\n\n';
  168. content = content.replace(/(<([^>]+)>)/ig,''); // strips stray tags
  169. // Now, begin adding other elements
  170. var elements = document.getElementsByClassName('output');
  171. for (var i = 1; i < elements.length; i++) {
  172. var thisBit = elements[i].innerHTML;
  173. thisBit = thisBit.replace(/(<([^>]+)>)/ig,''); // strips stray tags
  174. if (thisBit != "") {
  175. if (elements[i].classList.contains("subhead")) {
  176. // Before printing subhead, make sure it's not empty
  177. var i2 = i + 1;
  178. while ((i2 < elements.length) &&
  179. (!(elements[i2].classList.contains("subhead")))) {
  180. if (elements[i2].innerHTML != "") {
  181. // in this case, it's not empty, so print and move on
  182. content += '## ';
  183. content += thisBit + '\n\n';
  184. break;
  185. } else { i2++; }
  186. } // won't print anything if a subhead has only empty children
  187. } else {
  188. // Non-subhead elements can just go ahead and print
  189. content += thisBit + '\n\n';
  190. }
  191. }
  192. }
  193. // Add authorship block
  194. var authorName = document.getElementById("author-text").value;
  195. var authorURL = document.getElementById("author-url").value;
  196. var authorshipBlock = "---\n\nCreated by ";
  197. if (authorName != "") {
  198. if (authorURL != "") { // both author and URL present
  199. authorshipBlock += ("[" + authorName + "](" + authorURL + ")");
  200. } else { // only authorName present
  201. authorshipBlock += authorName;
  202. }
  203. content += (authorshipBlock + "\n");
  204. }
  205. // Add attribution block
  206. content += document.getElementById('attributionMD').innerHTML;
  207. // Starting here, see https://stackoverflow.com/a/33542499
  208. var blob = new Blob([content], {type: 'text/plain'});
  209. if(window.navigator.msSaveOrOpenBlob) {
  210. window.navigator.msSaveBlob(blob, filename);
  211. }
  212. else{
  213. var elem = window.document.createElement('a');
  214. elem.href = window.URL.createObjectURL(blob);
  215. elem.download = filename;
  216. document.body.appendChild(elem);
  217. elem.click();
  218. document.body.removeChild(elem);
  219. URL.revokeObjectURL(); // This needs an arg but I can't figure out what
  220. }
  221. var myFile = new Blob([fileContent], {type: 'text/plain'});
  222. window.URL = window.URL || window.webkitURL; document.getElementById('download').setAttribute('href',window.URL.createObjectURL(myFile));
  223. document.getElementById('download').setAttribute('download', fileName);
  224. }
  225. // BEGIN Publish tools, via SteinHQ.com
  226. // publishRule()
  227. // Publishes existing fields to new page, /create/?rule=[ruleID]
  228. // Opens new page in Display mode
  229. function publishRule() {
  230. // Confirm user knows what they're getting into
  231. var r = confirm("Publish to the public Library?");
  232. if (r == false) { return; }
  233. // Proceed with publication
  234. var now = new Date();
  235. // Numerical ID for published Rule
  236. var timeID = now.getTime();
  237. // Readable UTC timestamp
  238. var dateTime = now.getUTCFullYear()+'.'+(now.getUTCMonth()+1)+'.'+now.getUTCDate()
  239. +' '+now.getUTCHours()+":"+ now.getUTCMinutes()+":"+now.getUTCSeconds()
  240. + ' UTC';
  241. // TKTK: Check if ruleID exists; while yes, replace and repeat
  242. var rule = [{
  243. ruleID: timeID,
  244. timestamp: dateTime,
  245. }];
  246. var fields = document.getElementsByClassName("editable");
  247. for (var i = 0; i < fields.length; i++) {
  248. var key = fields[i].id;
  249. var value = "";
  250. if (fields[i].nodeName == "INPUT") { // for <input>
  251. value = fields[i].value.replace(/(<([^>]+)>)/ig,"");
  252. } else { // for other fields
  253. value = fields[i].innerHTML.replace(/(<([^>]+)>)/ig,"");
  254. }
  255. rule[0][key] = value;
  256. }
  257. const store = new SteinStore(
  258. "https://api.steinhq.com/v1/storages/5e8b937ab88d3d04ae0816a5"
  259. );
  260. store.append("rules", rule).then(data => {
  261. window.open("/create/?r=" + timeID, "_self", false);
  262. });
  263. }
  264. // displayRule(ID)
  265. // Displays content based on ID
  266. function displayRule(ID) {
  267. const store = new SteinStore(
  268. "https://api.steinhq.com/v1/storages/5e8b937ab88d3d04ae0816a5"
  269. );
  270. store.read("rules", { search: { ruleID: ID } }).then(data => {
  271. // only runs when we have the data from Goog:
  272. var rule = data[0];
  273. var fields = document.getElementsByClassName("editable");
  274. for (var i = 0; i < fields.length; i++) {
  275. var key = fields[i].id;
  276. var value = rule[key];
  277. if (typeof value === "undefined") {
  278. value = "";
  279. } else if (key.includes("-")) { // links
  280. document.getElementById(key).value = value;
  281. } else {
  282. document.getElementById(key).innerHTML = value;
  283. }
  284. }
  285. // Publish timestamp to Rule
  286. document.getElementById('dateTime').innerHTML = rule['timestamp'];
  287. // Finish
  288. displayMode = false;
  289. toggleDisplayMode();
  290. document.title = rule['communityname'] + " / CommunityRule";
  291. });
  292. }
  293. // deleteRule()
  294. // A temporary placeholder that sends an email requesting rule deletion
  295. function deleteRule() {
  296. var urlParamz = new URLSearchParams(window.location.search);
  297. var rID = urlParamz.get('r');
  298. window.open("mailto:medlab@colorado.edu?subject=Delete Rule request ("
  299. + rID + ")&body=Please explain your rationale:\n");
  300. }
  301. // END Publish tools
  302. // FINALLY, Page loading
  303. // First, grab the current URL
  304. var urlParams = new URLSearchParams(window.location.search);
  305. // Determine if it is a published Rule
  306. if (urlParams.has('r')) {
  307. // If so, grab the Rule from database and enter displayMode
  308. var rID = urlParams.get('r');
  309. displayRule(rID);
  310. } else {
  311. // Otherwise, open in editMode as default
  312. var editMode = true;
  313. // switch out of editMode in special cases
  314. window.onload = function() {
  315. if ((window.location.href.indexOf("/templates/") != -1) ||
  316. (window.location.href.indexOf("/about/") != -1)) {
  317. toggleEditMode();
  318. }
  319. }
  320. }
  321. </script>
  322. <article class="post">
  323. <header class="post-header">
  324. <h1 class="post-title" id="title">
  325. {{ page.title }}
  326. </h1>
  327. <button class="pushButton" id="editToggle" onclick="toggleEditMode()">
  328. Preview</button>
  329. <div class="post-content">
  330. {{ content }}
  331. </div>
  332. </header>
  333. <div id="rulebox">
  334. <span class="question">What is the community’s name?</span>
  335. <h1 contenteditable="true" class="editable output" id="communityname">{{ page.community-name }}</h1>
  336. <!-- Modules -->
  337. <div ondrop="drop(event)" ondragover="allowDrop(event)"
  338. class="modulebox" id="module-input">
  339. <span class="question" id="drag-directions">
  340. Drag modules from the icon at right</span>
  341. <div class="button">
  342. <img src="{% link assets/tabler_icons/tool.svg %}" title="Modules" />
  343. <div class="tooltiptext" id="module-menu">
  344. <!-- Customizable module -->
  345. <span class="module" id="module-custom"
  346. draggable="true" ondragstart="drag(event)">
  347. <input contenteditable="true" placeholder="Custom..." />
  348. <img src="{% link assets/tabler_icons/bulb.svg %}"
  349. draggable="false" />
  350. <a onclick="this.parentNode.remove()" id="delete-module"
  351. style="display:none">
  352. <img src="{% link assets/tabler_icons/x.svg %}" /></a>
  353. </span>
  354. <!-- Load preset modules from _data/modules.csv -->
  355. {% for module in site.data.modules %}
  356. <span class="module fixed" id="module-{{ module.id }}"
  357. draggable="true" ondragstart="drag(event)">
  358. <span>{{ module.name }}</span>
  359. <a target="_blank" href="{{ module.url }}">
  360. <img src="{% link assets/tabler_icons/link.svg %}"
  361. draggable="false" /></a>
  362. <a onclick="this.parentNode.remove()" id="delete-module"
  363. style="display:none">
  364. <img src="{% link assets/tabler_icons/x.svg %}" /></a>
  365. </span>
  366. {% endfor %}
  367. </div>
  368. </div>
  369. </div>
  370. <!-- SECTION S1: BASICS -->
  371. <h2 id="header-s1" class="header">
  372. <img src="{% link assets/tabler_icons/info-circle.svg %}"
  373. class="icons" />
  374. <span class="subhead output">Basics</span>
  375. <button onclick="toggleVisible('s1')" class="button plus"><img src="{% link assets/tabler_icons/plus.svg %}" title="Expand" /></button>
  376. </h2>
  377. <div class="section" id="s1" style="display:none">
  378. <span class="question">What is the basic structure of the community?</span>
  379. <p contenteditable="true" class="editable output" id="structure">{{ page.structure }}</p>
  380. <span class="question">What is the community’s mission?</span>
  381. <p contenteditable="true" class="editable output" id="mission">{{ page.mission }}</p>
  382. <span class="question">What core values does the community hold?</span>
  383. <p contenteditable="true" class="editable output" id="values">{{ page.values }}</p>
  384. <span class="question">What is the legal status of the community’s assets and creations?</span>
  385. <p contenteditable="true" class="editable output" id="legal">{{ page.legal }}</p>
  386. </div><!--hiding section s1-->
  387. <!-- SECTION s2: PARTICIPANTS -->
  388. <h2 id="header-s2" class="header">
  389. <img src="{% link assets/tabler_icons/user.svg %}"
  390. class="icons" />
  391. <span class="subhead output">Participants</span>
  392. <button onclick="toggleVisible('s2')" class="button plus"><img src="{% link assets/tabler_icons/plus.svg %}" title="Expand" /></button>
  393. </h2>
  394. <div class="section" id="s2" style="display:none">
  395. <span class="question">How does someone become a participant?</span>
  396. <p contenteditable="true" class="editable output" id="membership">{{ page.membership }}</p>
  397. <span class="question">How are participants suspended or removed?</span>
  398. <p contenteditable="true" class="editable output" id="removal">{{ page.removal }}</p>
  399. <span class="question">What special roles can participants hold, and how are roles assigned?</span>
  400. <p contenteditable="true" class="editable output" id="roles">{{ page.roles }}</p>
  401. <span class="question">Are there limits on the terms or powers of participant roles?</span>
  402. <p contenteditable="true" class="editable output" id="limits">{{ page.limits }}</p>
  403. </div><!--hiding section s2-->
  404. <!--SECTION s3: POLICY-->
  405. <h2 id="header-s3" class="header">
  406. <img src="{% link assets/tabler_icons/news.svg %}"
  407. class="icons" />
  408. <span class="subhead output">Policy</span>
  409. <button onclick="toggleVisible('s3')" class="button plus"><img src="{% link assets/tabler_icons/plus.svg %}" title="Expand" /></button>
  410. </h2>
  411. <div class="section" id="s3" style="display:none">
  412. <span class="question">What basic rights does this Rule guarantee?</span>
  413. <p contenteditable="true" class="editable output" id="rights">{{ page.rights }}</p>
  414. <span class="question">Who has the capacity to decide on policies, and how do they do so?</span>
  415. <p contenteditable="true" class="editable output" id="decision">{{ page.decision }}</p>
  416. <span class="question">How are policies implemented?</span>
  417. <p contenteditable="true" class="editable output" id="implementation">{{ page.implementation }}</p>
  418. <span class="question">How does the community monitor and evaluate its policy implementation? </span>
  419. <p contenteditable="true" class="editable output" id="oversight">{{ page.oversight }}</p>
  420. </div><!--hiding section s3-->
  421. <!-- SECTION s4: PROCESS -->
  422. <h2 id="header-s4" class="header">
  423. <img src="{% link assets/tabler_icons/refresh.svg %}"
  424. class="icons" />
  425. <span class="subhead output">Process</span>
  426. <button onclick="toggleVisible('s4')" class="button plus"><img src="{% link assets/tabler_icons/plus.svg %}" title="Expand" /></button>
  427. </h2>
  428. <div class="section" id="s4" style="display:none">
  429. <span class="question">Where does the community deliberate about policies and governance?</span>
  430. <p contenteditable="true" class="editable output" id="deliberation">{{ page.deliberation }}</p>
  431. <span class="question">How does the community manage access to administrative accounts and other tools?</span>
  432. <p contenteditable="true" class="editable output" id="access">{{ page.access }}</p>
  433. <span class="question">How does the community manage funds and economic flows?</span>
  434. <p contenteditable="true" class="editable output" id="economics">{{ page.economics }}</p>
  435. <span class="question">How are grievances among participants addressed?</span>
  436. <p contenteditable="true" class="editable output" id="grievances">{{ page.grievances }}</p>
  437. </div><!--hiding section s4-->
  438. <!-- SECTION s5: EVOLUTION -->
  439. <h2 id="header-s5" class="header">
  440. <img src="{% link assets/tabler_icons/adjustments.svg %}"
  441. class="icons" />
  442. <span class="subhead output">Evolution</span>
  443. <button onclick="toggleVisible('s5')" class="button plus"><img src="{% link assets/tabler_icons/plus.svg %}" title="Expand" /></button>
  444. </h2>
  445. <div class="section" id="s5" style="display:none">
  446. <span class="question">Where are policies and records kept?</span>
  447. <p contenteditable="true" class="editable output" id="records">{{ page.records }}</p>
  448. <span class="question">How can this Rule be modified?</span>
  449. <p contenteditable="true" class="editable output" id="modification">{{ page.modification }}</p>
  450. </div><!--hiding section s5-->
  451. <div id="authorship" class="linkbox">
  452. <span id="authorship-words">Created by</span>
  453. <input contenteditable="true" class="editable link-text" id="author-text" placeholder="Created by" />
  454. <span class="link-divider"><img src="{% link assets/tabler_icons/pencil.svg %}" title="Add link" /></span>
  455. <input contenteditable="true" class="editable link-url" id="author-url" placeholder="Creator URL (http://, https://)" type="url" pattern="http://.*|https://.*" />
  456. <span id="authorship-result"></span>
  457. </div>
  458. </div><!--#rulebox-->
  459. <div id="attribution" style="display:none;">
  460. <br />
  461. <p><a href="https://communityrule.info">
  462. <img src="https://communityrule.info{% link assets/CommunityRule-derived-000000.svg %}" alt="CommunityRule derived"></a></p>
  463. <p id="dateTime"></p>
  464. <p>Created with <a href="https://communityrule.info">CommunityRule</a><br />
  465. <a href="https://creativecommons.org/licenses/by-sa/4.0/">Creative Commons BY-SA</a></p>
  466. <p><strong>The Publish feature is experimental. Rules may be removed without notice</strong></p>
  467. </div>
  468. <div id="attributionMD" style="display:none;">
  469. ---
  470. [![CommunityRule derived](https://communityrule.info{% link assets/CommunityRule-derived-000000.svg %})](https://communityrule.info)
  471. [Creative Commons BY-SA](https://creativecommons.org/licenses/by-sa/4.0/)</div>
  472. <button class="pushButton" id="publishRule" onclick="publishRule()"
  473. title="Add to the public Library">Publish</button>
  474. <button class="pushButton" id="toggleDisplayMode" onclick="toggleDisplayMode()"
  475. title="Edit this Rule into a new one">Fork</button>
  476. <button class="pushButton" onclick="textOutput()"
  477. title="Download this Rule as a Markdown text file">Export</button>
  478. <button class="pushButton" id="trash" onclick="deleteRule()">
  479. <img src="{% link assets/tabler_icons/trash.svg %}" title="Rule deletion request" />
  480. </button>
  481. <button class="pushButton"
  482. onclick="javascript:location.href='https://www.colorado.edu/lab/medlab/content/communityrule-user-feedback'">
  483. Feedback
  484. </button>
  485. </article>