rule.html 21 KB

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