From 5c4c69d4654a5a4fe5dabb6c2f2027fb08496a14 Mon Sep 17 00:00:00 2001 From: Eddie Kohler Date: Wed, 28 Oct 2020 12:44:37 -0400 Subject: [PATCH] Script: Move scripts into a global `hotcrp` object. Preparing for modularization. --- assign.php | 2 +- autoassign.php | 97 ++------------------------ bulkassign.php | 11 +-- buzzer.php | 2 +- graph.php | 4 +- lib/tagger.php | 2 +- mail.php | 20 +++--- manualassign.php | 6 +- paper.php | 4 +- profile.php | 4 +- review.php | 2 +- reviewprefs.php | 4 +- scripts/buzzer.js | 2 +- scripts/graph.js | 2 +- scripts/script.js | 127 +++++++++++++++++++++++++++++++++- scripts/settings.js | 20 ++++-- search.php | 2 +- src/commentinfo.php | 2 +- src/conference.php | 10 +-- src/paperlist.php | 4 +- src/papertable.php | 26 +++---- src/partials/p_home.php | 2 +- src/partials/p_signin.php | 8 +-- src/review.php | 6 +- src/settings/s_options.php | 2 +- src/settings/s_responses.php | 2 +- src/settings/s_reviewform.php | 7 +- src/settings/s_reviews.php | 2 +- src/userstatus.php | 2 +- 29 files changed, 213 insertions(+), 171 deletions(-) diff --git a/assign.php b/assign.php index eec552073..ef97210f0 100644 --- a/assign.php +++ b/assign.php @@ -466,7 +466,7 @@ function pcAssignments($qreq) { '

PC assignments

', '
', Ht::form($Conf->hoturl_post("assign", "p=$prow->paperId"), array("id" => "ass", "class" => "need-unload-protection")); - Ht::stash_script('hiliter_children("#ass")'); + Ht::stash_script('hotcrp.highlight_form_children("#ass")'); if ($Conf->has_topics()) { echo "

Review preferences display as “P#”, topic scores as “T#”.

"; diff --git a/autoassign.php b/autoassign.php index d12fd9abb..88dd0084d 100644 --- a/autoassign.php +++ b/autoassign.php @@ -453,7 +453,7 @@ function progress($status) { } if (!$this->live) { $t = '

Preparing assignment

Status: ' . htmlspecialchars($status); - echo Ht::script('$$("propass").innerHTML=' . json_encode_browser($t) . ';'), "\n"; + echo Ht::script('document.getElementById("propass").innerHTML=' . json_encode_browser($t) . ';'), "\n"; flush(); while (@ob_end_flush()) { /* skip */ @@ -505,7 +505,7 @@ function run() { if ($this->live) { echo $w; } else { - echo Ht::unstash_script('$$("propass").innerHTML=' . json_encode($w)), "\n"; + echo Ht::unstash_script('document.getElementById("propass").innerHTML=' . json_encode($w)), "\n"; } return null; } else { @@ -602,7 +602,7 @@ function divClass($name, $classes = null) {

', review_type_icon(REVIEW_PC), ' Optional
May be declined
', review_type_icon(REVIEW_META), ' Metareview
Can view all other reviews before completing their own
', "\n"; -echo Ht::unstash_script("hiliter_children(\"#autoassignform\")"); +echo Ht::unstash_script("hotcrp.highlight_form_children(\"#autoassignform\")"); // paper selection echo divClass("pap"), "

Paper selection

"; @@ -730,75 +730,7 @@ function divClass($name, $classes = null) { $sep = ", "; } echo ")"; -Ht::stash_script('function make_pcsel_members(tag) { - if (tag === "__flip__") - return function () { return !this.checked; }; - else if (tag === "all") - return function () { return true; }; - else if (tag === "none") - return function () { return false; }; - else { - tag = " " + tag.toLowerCase() + "#"; - return function () { - var tlist = hotcrp_pc_tags[this.name.substr(3)] || ""; - return tlist.indexOf(tag) >= 0; - }; - } -} -function pcsel_tag(event) { - var $g = $(this).closest(".js-radio-focus"), e; - if (this.tagName === "A") { - $g.find("input[type=radio]").first().click(); - var tag = this.hash.substring(4), - f = make_pcsel_members(tag), - full = true; - if (tag !== "all" && tag !== "none" && tag !== "__flip__" - && !hasClass(this, "font-weight-bold")) { - $g.find("input").each(function () { - if (this.name.startsWith("pcc") && !this.checked) - return (full = false); - }); - } - $g.find("input").each(function () { - if (this.name.startsWith("pcc")) { - var on = f.call(this); - if (full || on) - this.checked = on; - } - }); - event.preventDefault(); - } - var tags = [], functions = {}, isall = true; - $g.find("a.js-pcsel-tag").each(function () { - var tag = this.hash.substring(4); - if (tag !== "none") { - tags.push(tag); - functions[tag] = make_pcsel_members(tag); - } - }); - $g.find("input").each(function () { - if (this.name.startsWith("pcc") && !this.checked) { - isall = false; - for (var i = 0; i < tags.length; ) { - if (functions[tags[i]].call(this)) - tags.splice(i, 1); - else - ++i; - } - return isall || tags.length !== 0; - } - }); - $g.find("a.js-pcsel-tag").each(function () { - var tag = this.hash.substring(4); - if ($.inArray(tag, tags) >= 0 && (tag === "all" || !isall)) - addClass(this, "font-weight-bold"); - else - removeClass(this, "font-weight-bold"); - }); -} -$(document).on("click", "a.js-pcsel-tag", pcsel_tag); -$(document).on("change", "input.js-pcsel-tag", pcsel_tag); -$(function(){$("input.js-pcsel-tag").first().trigger("change")})'); +Ht::stash_script('$(function(){$("input.js-pcsel-tag").first().trigger("change")});'); $summary = []; $nrev = AssignmentCountSet::load($Me, AssignmentCountSet::HAS_REVIEW); @@ -820,7 +752,7 @@ functions[tag] = make_pcsel_members(tag); function bpSelector($i, $which) { global $Qreq; return Ht::select("bp$which$i", [], 0, - ["class" => "need-pcselector badpairs", "data-pcselector-selected" => $Qreq["bp$which$i"], "data-pcselector-options" => "[\"(PC member)\",\"*\"]", "data-default-value" => $Qreq["bp$which$i"]]); + ["class" => "need-pcselector uich badpairs", "data-pcselector-selected" => $Qreq["bp$which$i"], "data-pcselector-options" => "[\"(PC member)\",\"*\"]", "data-default-value" => $Qreq["bp$which$i"]]); } echo '
', "\n"; @@ -842,25 +774,6 @@ function bpSelector($i, $which) { } echo "
\n"; $Conf->stash_hotcrp_pc($Me); -echo Ht::unstash_script('$("#bptable").on("change", "select.badpairs", function () { - if (this.value !== "none") { - var x = $$("badpairs"); - x.checked || x.click(); - } -}); -$("#bptable a.js-badpairs-row").on("click", function () { - var tbody = $("#bptable > tbody"), n = tbody.children().length; - if (hasClass(this, "more")) { - ++n; - tbody.append(\'or    and  \'); - var options = tbody.find("select").first().html(); - tbody.find("select[name=bpa" + n + "], select[name=bpb" + n + "]").html(options).val("none"); - } else if (n > 1) { - --n; - tbody.children().last().remove(); - } - return false; -});'); // Load balancing diff --git a/bulkassign.php b/bulkassign.php index 809ec4fe0..76bf789de 100644 --- a/bulkassign.php +++ b/bulkassign.php @@ -57,7 +57,7 @@ function keep_browser_alive($assignset, $lineno, $line) { } else { $text .= " " . htmlspecialchars(join(",", $line->as_array())) . ""; } - echo Ht::unstash_script("\$\$('mailcount').innerHTML=" . json_encode_browser($text) . ";"); + echo Ht::unstash_script("document.getElementById('mailcount').innerHTML=" . json_encode_browser($text) . ";"); flush(); while (@ob_end_flush()) { } @@ -66,8 +66,9 @@ function keep_browser_alive($assignset, $lineno, $line) { function finish_browser_alive() { global $csv_preparing; - if ($csv_preparing) - echo Ht::unstash_script("fold('mail',null)"); + if ($csv_preparing) { + echo Ht::unstash_script("hotcrp.fold('mail',null)"); + } } function complete_assignment($qreq, $callback) { @@ -229,8 +230,8 @@ function complete_assignment($qreq, $callback) { ''; Ht::stash_script('$(function(){ $("#tsel").on("change",function(){ -foldup.call(this,null,{f:this.value!=="review"}); -foldup.call(this,null,{f:!/^(?:primary|secondary|(?:pc|meta)?review)$/.test(this.value),n:2}); +hotcrp.foldup.call(this,null,{f:this.value!=="review"}); +hotcrp.foldup.call(this,null,{f:!/^(?:primary|secondary|(?:pc|meta)?review)$/.test(this.value),n:2}); }).trigger("change")})'); $rev_rounds = $Conf->round_selector_options(null); $expected_round = $Qreq->rev_round ? : $Conf->assignment_round_option(false); diff --git a/buzzer.php b/buzzer.php index 47ca49a10..bfff8d32c 100644 --- a/buzzer.php +++ b/buzzer.php @@ -131,7 +131,7 @@ function kiosk_lookup($key) { $buzzer_status["no_discussion"] = $no_discussion . ''; echo Ht::unstash(); echo $Conf->make_script_file("scripts/buzzer.js"); -echo Ht::unstash_script('start_buzzer_page(' . json_encode_browser($buzzer_status) . ')'); +echo Ht::unstash_script('hotcrp.start_buzzer_page(' . json_encode_browser($buzzer_status) . ')'); echo "\n"; $Conf->footer(); diff --git a/graph.php b/graph.php index 3d1a44851..865e8044b 100644 --- a/graph.php +++ b/graph.php @@ -60,7 +60,7 @@ function echo_graph($searchable, $fg, $h2) { if ($Graph == "procrastination") { echo_graph(false, null, "Procrastination"); $rt = new ReviewTimes($Me); - echo Ht::unstash_script('$(function () { hotcrp_graph("#hotgraph",' . json_encode_browser($rt->json()) . ') })'); + echo Ht::unstash_script('$(function () { hotcrp.graph("#hotgraph",' . json_encode_browser($rt->json()) . ') })'); } @@ -146,7 +146,7 @@ function formulas_qrow($i, $q, $s, $status) { } else if ($fg->type === FormulaGraph::BOXPLOT) { $gtype = "boxplot"; } - echo Ht::unstash_script("\$(function () { hotcrp_graph(\"#hotgraph\", " . json_encode_browser($fg->graph_json()) . ") });"), "\n"; + echo Ht::unstash_script("\$(function () { hotcrp.graph(\"#hotgraph\", " . json_encode_browser($fg->graph_json()) . ") });"), "\n"; } else { echo "

Formulas

\n"; } diff --git a/lib/tagger.php b/lib/tagger.php index 0825b0901..2ecb8b7f6 100644 --- a/lib/tagger.php +++ b/lib/tagger.php @@ -679,7 +679,7 @@ function styles($tags, $match = 0, $no_pattern_fill = false) { static function mark_pattern_fill($classes) { $key = is_array($classes) ? join(" ", $classes) : $classes; if (!isset(self::$multicolor_map[$key]) && strpos($key, " ") !== false) { - Ht::stash_script("make_pattern_fill(" . json_encode_browser($key) . ")"); + Ht::stash_script("hotcrp.make_pattern_fill(" . json_encode_browser($key) . ")"); self::$multicolor_map[$key] = true; } } diff --git a/mail.php b/mail.php index 930ae8c4a..56d391e81 100644 --- a/mail.php +++ b/mail.php @@ -313,7 +313,7 @@ private function echo_prologue() { echo '
Scroll down to send the prepared mail once the page finishes loading.
', "\n"; } - echo Ht::unstash_script("fold('mail',0,2)"); + echo Ht::unstash_script("hotcrp.fold('mail',0,2)"); $this->started = true; } @@ -321,7 +321,7 @@ private function echo_mailinfo($nrows_done, $nrows_total) { if (!$this->started) { $this->echo_prologue(); } - $s = "\$\$('mailcount').innerHTML=\""; + $s = "document.getElementById('mailcount').innerHTML=\""; if ($nrows_done >= $nrows_total) { $s .= "100"; } else { @@ -330,7 +330,7 @@ private function echo_mailinfo($nrows_done, $nrows_total) { $s .= "% done.\";"; $m = plural($this->mcount, "mail") . ", " . plural($this->mrecipients, "recipient"); - $s .= "\$\$('mailinfo').innerHTML=\"·" . $m . "\";"; + $s .= "document.getElementById('mailinfo').innerHTML=\"·" . $m . "\";"; if (!$this->sending && $this->groupable) { $s .= "\$('.mail_groupable').show();"; } @@ -533,7 +533,7 @@ private function run() { $this->echo_prologue(); $nwarnings = $mailer->warning_count(); echo "
", join("
", $mailer->warning_htmls()), "
"; - echo Ht::unstash_script("\$\$('mailwarnings').innerHTML = \$\$('foldmailwarn$nwarnings').innerHTML;"); + echo Ht::unstash_script("document.getElementById('mailwarnings').innerHTML = document.getElementById('foldmailwarn$nwarnings').innerHTML;"); } if ($this->sending && $revinform !== null && $prow) { @@ -548,7 +548,7 @@ private function run() { if (empty($preperrors)) { Conf::msg_error("No users match “" . $this->recip->unparse() . "” for that search."); } - echo Ht::unstash_script("addClass(document.getElementById('foldmail'),'hidden');document.getElementById('mailform').action=" . json_encode_browser($this->conf->hoturl("mail", "check=1", Conf::HOTURL_RAW | Conf::HOTURL_POST))); + echo Ht::unstash_script("\$(\"#foldmail\").addClass('hidden');document.getElementById('mailform').action=" . json_encode_browser($this->conf->hoturl("mail", "check=1", Conf::HOTURL_RAW | Conf::HOTURL_POST))); return false; } @@ -561,7 +561,7 @@ private function run() { } } echo ""; - echo Ht::unstash_script("fold('mail', null);"); + echo Ht::unstash_script("hotcrp.fold('mail', null);"); $this->conf->footer(); exit; } @@ -693,11 +693,11 @@ private function run() { echo '
'; Ht::stash_script('function mail_recipients_fold(event) { - var plimit = $$("plimit"); - foldup.call(this, null, {f: !!plimit && !plimit.checked, n: 8}); + var plimit = document.getElementById("plimit"); + hotcrp.foldup.call(this, null, {f: !!plimit && !plimit.checked, n: 8}); var sopt = $(this).find("option[value=\'" + this.value + "\']"); - foldup.call(this, null, {f: sopt.hasClass("mail-want-no-papers"), n: 9}); - foldup.call(this, null, {f: !sopt.hasClass("mail-want-since"), n: 10}); + hotcrp.foldup.call(this, null, {f: sopt.hasClass("mail-want-no-papers"), n: 9}); + hotcrp.foldup.call(this, null, {f: !sopt.hasClass("mail-want-since"), n: 10}); } $("#to, #plimit").on("change", mail_recipients_fold); $(function () { $("#to").trigger("change"); })'); diff --git a/manualassign.php b/manualassign.php index 9ce2d5099..e888b9f04 100644 --- a/manualassign.php +++ b/manualassign.php @@ -153,7 +153,7 @@ function saveAssignments($qreq, $reviewer) { // Change PC member echo "'); + var options = tbody.find("select").first().html(); + tbody.find("select[name=bpa" + n + "], select[name=bpb" + n + "]").html(options).val("none"); + } else if (n > 1) { + --n; + tbody.children().last().remove(); + } + return false; +}); + +})(); + // author entry var row_order_ui = (function ($) { @@ -9731,3 +9824,33 @@ $.fn.unautogrow = function () { })(jQuery); $(function () { $(".need-autogrow").autogrow(); }); + + +var hotcrp = { + add_comment: papercomment.add, + add_review: review_form.add_review, + add_preference_ajax: add_revpref_ajax, + check_version: check_version, + demand_load: demand_load, + edit_comment: papercomment.edit, + focus_within: focus_within, + fold: fold, + fold_storage: fold_storage, + foldup: foldup, + highlight_form_children: hiliter_children, + init_deadlines: hotcrp_deadlines.init, + load_editable_paper: edit_paper_ui.load, + load_editable_review: edit_paper_ui.load_review, + make_pattern_fill: make_pattern_fill, + onload: hotcrp_load, + paper_edit_conditions: edit_paper_ui.edit_condition, + prepare_editable_paper: edit_paper_ui.prepare, + profile_ui: profile_ui, + render_list: plinfo.render_needed, + render_text_page: render_text.on_page, + scorechart: scorechart, + set_default_format: render_text.set_default_format, + set_response_round: papercomment.set_resp_round, + set_review_form: review_form.set_form, + shortcut: shortcut +}; diff --git a/scripts/settings.js b/scripts/settings.js index ee073fc98..0d4f9e681 100644 --- a/scripts/settings.js +++ b/scripts/settings.js @@ -50,7 +50,7 @@ handle_ui.on("js-settings-option-move", function (event) { $odiv.append('
This field will be deleted from the submission form.
'); } } - settings_option_move_enable(); + settings_option_positions(); }); handle_ui.on("js-settings-option-new", function (event) { @@ -63,10 +63,10 @@ handle_ui.on("js-settings-option-new", function (event) { odiv.find(".need-autogrow").autogrow(); odiv.find(".need-tooltip").each(tooltip); $("#optn_" + next)[0].focus(); - settings_option_move_enable(); + settings_option_positions(); }); -function settings_option_move_enable() { +function settings_option_positions() { $(".settings-opt .moveup, .settings-opt .movedown").prop("disabled", false); $(".settings-opt:first-child .moveup").prop("disabled", true); $(".settings-opt:last-child .movedown").prop("disabled", true); @@ -612,9 +612,8 @@ function add_dialog(fid, focus) { create(); } -rfs.add = function (has_options, fid) { - if (fid) - return add_field(fid); +handle_ui.on("js-settings-add-review-field", function () { + var has_options = hasClass(this, "score"), fid; // prefer recently removed fields var i = 0, x = []; for (var $n = $("#reviewform_removedcontainer")[0].firstChild; @@ -642,7 +641,7 @@ rfs.add = function (has_options, fid) { } original[fid] = has_options ? stemplate : ttemplate; return add_dialog(fid); -}; +}); return rfs; })(); @@ -659,3 +658,10 @@ handle_ui.on("js-settings-resp-round-new", function () { j.find(".need-suggest").each(suggest); return false; }); + + +hotcrp.settings = { + option_positions: settings_option_positions, + review_form: review_form_settings, + review_round: review_round_settings +}; diff --git a/search.php b/search.php index 2a7df81d6..c2d5ad8a1 100644 --- a/search.php +++ b/search.php @@ -491,7 +491,7 @@ function echo_request_as_hidden_inputs($specialscore) { } echo "
", Ht::form(hoturl("manualassign"), array("method" => "get", "id" => "selectreviewerform")); -Ht::stash_script('hiliter_children("#selectreviewerform")'); +Ht::stash_script('hotcrp.highlight_form_children("#selectreviewerform")'); $result = $Conf->qe_raw("select ContactInfo.contactId, count(reviewId) from ContactInfo @@ -310,8 +310,8 @@ function show_ass_elements($pl) { echo '
', Ht::submit("update", "Save assignments", ["class" => "btn-primary"]), "
\n"; - Ht::stash_script('hiliter_children("form.assignpc");$("#assrevimmediate").trigger("change");' - . "$(\"#showau\").on(\"change\", function () { foldup.call(this, null, {n:10}) })"); + Ht::stash_script('hotcrp.highlight_form_children("form.assignpc");$("#assrevimmediate").trigger("change");' + . "$(\"#showau\").on(\"change\", function () { hotcrp.foldup.call(this, null, {n:10}) })"); } echo '
'; diff --git a/paper.php b/paper.php index 07f7627a1..9c3fae749 100644 --- a/paper.php +++ b/paper.php @@ -65,7 +65,7 @@ function errorMsgExit($msg) { json_exit(["ok" => false]); } else { confHeader(); - Ht::stash_script("shortcut().add()"); + Ht::stash_script("hotcrp.shortcut().add()"); $msg && Conf::msg_error($msg); Conf::$main->footer(); exit; @@ -541,7 +541,7 @@ function update_paper(Qrequest $qreq, $action) { $j->blind = !!$Qreq->blind; $j->draft = !!$Qreq->draft; } - Ht::stash_script("papercomment.edit(" . json_encode_browser($j) . ")"); + Ht::stash_script("hotcrp.edit_comment(" . json_encode_browser($j) . ")"); } } diff --git a/profile.php b/profile.php index 10f33e2ff..e19422778 100644 --- a/profile.php +++ b/profile.php @@ -97,7 +97,7 @@ function change_email_by_capability($Qreq) { Ht::submit("go", "Change email", ["class" => "btn-primary", "value" => 1]), Ht::submit("cancel", "Cancel", ["formnovalidate" => true]), '
'; - Ht::stash_script("focus_within(\$(\"#changeemailform\"));window.scroll(0,0)"); + Ht::stash_script("hotcrp.focus_within(\$(\"#changeemailform\"));window.scroll(0,0)"); $Conf->footer(); exit; } @@ -728,6 +728,6 @@ function parseBulkFile($text, $filename) { echo ""; if (!$newProfile) { - Ht::stash_script('hiliter_children("#form-profile")'); + Ht::stash_script('hotcrp.highlight_form_children("#form-profile")'); } $Conf->footer(); diff --git a/review.php b/review.php index 8bbea82f2..1f19ff729 100644 --- a/review.php +++ b/review.php @@ -18,7 +18,7 @@ function review_header() { function review_error($msg) { global $Conf; review_header(); - Ht::stash_script("shortcut().add()"); + Ht::stash_script("hotcrp.shortcut().add()"); $msg && Conf::msg_error($msg); Conf::$main->footer(); exit; diff --git a/reviewprefs.php b/reviewprefs.php index d9a1a0197..415bc7a16 100644 --- a/reviewprefs.php +++ b/reviewprefs.php @@ -266,7 +266,7 @@ function parseUploadedPreferences($text, $filename, $apply) { } echo Ht::select("reviewer", $sel, $reviewer->email, ["id" => "htctl-prefs-user"]), ''; - Ht::stash_script('$("#searchform select[name=reviewer]").on("change", function () { $$("searchform").submit() })'); + Ht::stash_script('$("#searchform select[name=reviewer]").on("change", function () { $("#searchform")[0].submit() })'); } echo '
', @@ -305,7 +305,7 @@ function show_pref_element($pl, $name, $text, $extra = []) { '
    ', join('', $show_data), '
'; } echo ""; -Ht::stash_script("$(\"#showau\").on(\"change\", function () { foldup.call(this, null, {n:10}) })"); +Ht::stash_script("$(\"#showau\").on(\"change\", function () { hotcrp.foldup.call(this, null, {n:10}) })"); // main form diff --git a/scripts/buzzer.js b/scripts/buzzer.js index 22ad75e35..f3004ac0a 100644 --- a/scripts/buzzer.js +++ b/scripts/buzzer.js @@ -1,4 +1,4 @@ -var start_buzzer_page = (function ($) { +hotcrp.start_buzzer_page = (function ($) { var info, has_format, muted, show_papers, initial = true, last_html = {}; function render_pc(pc) { diff --git a/scripts/graph.js b/scripts/graph.js index 1b9aa3da1..e24fe8970 100644 --- a/scripts/graph.js +++ b/scripts/graph.js @@ -1,7 +1,7 @@ // graph.js -- HotCRP JavaScript library for graph drawing // Copyright (c) 2006-2020 Eddie Kohler; see LICENSE. -var hotcrp_graph = (function ($, d3) { +hotcrp.graph = (function ($, d3) { var BOTTOM_MARGIN = 30; var PATHSEG_ARGMAP = { m: 2, M: 2, z: 0, Z: 0, l: 2, L: 2, h: 1, H: 1, v: 1, V: 1, c: 6, C: 6, diff --git a/scripts/script.js b/scripts/script.js index 9b97f9a60..2ba3a248e 100644 --- a/scripts/script.js +++ b/scripts/script.js @@ -1,7 +1,7 @@ // script.js -- HotCRP JavaScript library // Copyright (c) 2006-2020 Eddie Kohler; see LICENSE. -var siteurl, siteurl_base_path, +var siteurl, siteurl_base_path, hotcrp, siteurl_postvalue, siteurl_suffix, siteurl_defaults, siteurl_absolute_base, siteurl_cookie_params, assetsurl, hotcrp_paperid, hotcrp_status, hotcrp_user, @@ -2855,7 +2855,7 @@ var hotcrp_load = (function ($) { function fold_storage() { - if (!this || this === window) { + if (!this || this === window || this === hotcrp) { $(".need-fold-storage").each(fold_storage); } else { removeClass(this, "need-fold-storage"); @@ -3461,6 +3461,99 @@ handle_ui.on("js-request-review-preview-email", function (event) { event.stopPropagation(); }); +// autoassignment +(function () { +function make_pcsel_members(tag) { + if (tag === "__flip__") + return function () { return !this.checked; }; + else if (tag === "all") + return function () { return true; }; + else if (tag === "none") + return function () { return false; }; + else { + tag = " " + tag.toLowerCase() + "#"; + return function () { + var tlist = hotcrp_pc_tags[this.name.substr(3)] || ""; + return tlist.indexOf(tag) >= 0; + }; + } +} +function pcsel_tag(event) { + var $g = $(this).closest(".js-radio-focus"), e; + if (this.tagName === "A") { + $g.find("input[type=radio]").first().click(); + var tag = this.hash.substring(4), + f = make_pcsel_members(tag), + full = true; + if (tag !== "all" && tag !== "none" && tag !== "__flip__" + && !hasClass(this, "font-weight-bold")) { + $g.find("input").each(function () { + if (this.name.startsWith("pcc") && !this.checked) + return (full = false); + }); + } + $g.find("input").each(function () { + if (this.name.startsWith("pcc")) { + var on = f.call(this); + if (full || on) + this.checked = on; + } + }); + event.preventDefault(); + } + var tags = [], functions = {}, isall = true; + $g.find("a.js-pcsel-tag").each(function () { + var tag = this.hash.substring(4); + if (tag !== "none") { + tags.push(tag); + functions[tag] = make_pcsel_members(tag); + } + }); + $g.find("input").each(function () { + if (this.name.startsWith("pcc") && !this.checked) { + isall = false; + for (var i = 0; i < tags.length; ) { + if (functions[tags[i]].call(this)) + tags.splice(i, 1); + else + ++i; + } + return isall || tags.length !== 0; + } + }); + $g.find("a.js-pcsel-tag").each(function () { + var tag = this.hash.substring(4); + if ($.inArray(tag, tags) >= 0 && (tag === "all" || !isall)) + addClass(this, "font-weight-bold"); + else + removeClass(this, "font-weight-bold"); + }); +} +handle_ui.on("js-pcsel-tag", pcsel_tag); + +handle_ui.on("badpairs", function () { + if (this.value !== "none") { + var x = $$("badpairs"); + x.checked || x.click(); + } +}); + +handle_ui.on(".js-badpairs-row", function () { + var tbody = $("#bptable > tbody"), n = tbody.children().length; + if (hasClass(this, "more")) { + ++n; + tbody.append('
or    and 
\n\n"; if ($pl->count == 0) { - Ht::stash_script("addClass(document.body,\"want-hash-focus\")"); + Ht::stash_script("\$(document.body).addClass(\"want-hash-focus\")"); } echo Ht::unstash(); diff --git a/src/commentinfo.php b/src/commentinfo.php index eba61d258..1baf11d14 100644 --- a/src/commentinfo.php +++ b/src/commentinfo.php @@ -111,7 +111,7 @@ static function echo_script($prow) { $j["done"] = $rrd->done; } } - $t[] = "papercomment.set_resp_round(" . json_encode($rrd->name) . "," . json_encode($j) . ")"; + $t[] = "hotcrp.set_response_round(" . json_encode($rrd->name) . "," . json_encode($j) . ")"; } echo Ht::unstash_script(join(";", $t)); Icons::stash_licon("ui_tag"); diff --git a/src/conference.php b/src/conference.php index 39d19a8e4..b43ceb218 100644 --- a/src/conference.php +++ b/src/conference.php @@ -4087,16 +4087,16 @@ function header_body($title, $id, $extra = []) { echo "\">\n"; // initial load (JS's timezone offsets are negative of PHP's) - Ht::stash_script("hotcrp_load.time(" . (-(int) date("Z", Conf::$now) / 60) . "," . ($this->opt("time24hour") ? 1 : 0) . ")"); + Ht::stash_script("hotcrp.onload.time(" . (-(int) date("Z", Conf::$now) / 60) . "," . ($this->opt("time24hour") ? 1 : 0) . ")"); // deadlines settings $my_deadlines = null; if ($Me) { $my_deadlines = $Me->my_deadlines($this->paper ? [$this->paper] : []); - Ht::stash_script("hotcrp_deadlines.init(" . json_encode_browser($my_deadlines) . ")"); + Ht::stash_script("hotcrp.init_deadlines(" . json_encode_browser($my_deadlines) . ")"); } if ($this->default_format) { - Ht::stash_script("render_text.set_default_format(" . $this->default_format . ")"); + Ht::stash_script("hotcrp.set_default_format(" . $this->default_format . ")"); } echo '
'; @@ -4260,7 +4260,7 @@ function header_body($title, $id, $extra = []) { $v .= " " . $args[1]; } } - Ht::stash_script("check_version(\"$m\",\"$v\")"); + Ht::stash_script("hotcrp.check_version(\"$m\",\"$v\")"); $_SESSION["updatecheck"] = Conf::$now; } } @@ -4390,7 +4390,7 @@ function hotcrp_pc_json(Contact $viewer) { function stash_hotcrp_pc(Contact $viewer, $always = false) { if (($always || !$this->opt("largePC")) && Ht::mark_stash("hotcrp_pc")) { - Ht::stash_script("demand_load.pc(" . json_encode_browser($this->hotcrp_pc_json($viewer)) . ");"); + Ht::stash_script("hotcrp.demand_load.pc(" . json_encode_browser($this->hotcrp_pc_json($viewer)) . ");"); } } diff --git a/src/paperlist.php b/src/paperlist.php index cc33729ca..c3b1b5053 100644 --- a/src/paperlist.php +++ b/src/paperlist.php @@ -1824,11 +1824,11 @@ private function _table_render($options) { } $body[] = $this->_row_html($rstate, $row); if ($this->need_render && !$need_render) { - Ht::stash_script('$(plinfo.render_needed)', 'plist_render_needed'); + Ht::stash_script('$(hotcrp.render_list)', 'plist_render_needed'); $need_render = true; } if ($this->need_render && $this->count % 16 == 15) { - $body[count($body) - 1] .= " " . Ht::script('plinfo.render_needed()') . "\n"; + $body[count($body) - 1] .= " " . Ht::script('hotcrp.render_list()') . "\n"; $this->need_render = false; } } diff --git a/src/papertable.php b/src/papertable.php index f70822426..3f867bba2 100644 --- a/src/papertable.php +++ b/src/papertable.php @@ -210,7 +210,7 @@ static function do_header($paperTable, $id, $action_mode, $qreq) { "paperId" => $qreq->paperId ]); if ($format) { - echo Ht::unstash_script("render_text.on_page()"); + echo Ht::unstash_script("hotcrp.render_text_page()"); } } @@ -387,7 +387,7 @@ private function echoDivEnter() { echo (empty($folders) ? "" : " "), 'need-fold-storage" data-fold-storage-prefix="p." data-fold-storage="', htmlspecialchars(json_encode_browser($foldstorage)), '">'; - Ht::stash_script("fold_storage()"); + Ht::stash_script("hotcrp.fold_storage()"); } } @@ -428,7 +428,7 @@ function echo_editable_option_papt(PaperOption $opt, $heading = null, $rest = [] echo ' hidden'; } echo '" data-edit-condition="', htmlspecialchars(json_encode($opt->exists_script_expression($this->prow))); - Ht::stash_script('$(edit_paper_ui.edit_condition)', 'edit_condition'); + Ht::stash_script('$(hotcrp.paper_edit_conditions)', 'edit_condition'); } echo '">

value .= '
' . '' - . Ht::unstash_script("render_text.on_page()"); + . Ht::unstash_script("hotcrp.render_text_page()"); } } @@ -1349,7 +1349,7 @@ private function papstripTags() { echo ""; } if ($unfolded) { - echo Ht::unstash_script('fold("tags",0)'); + echo Ht::unstash_script('hotcrp.fold("tags",0)'); } echo "

\n"; } @@ -1378,7 +1378,7 @@ function papstripReviewPreference() { echo "prow->paperId, "\" size=\"4\" value=\"$rp\" class=\"revpref want-focus want-select\">", "\n"; - Ht::stash_script("add_revpref_ajax(\"#revprefform_d\",true);shortcut(\"revprefform_d\").add()"); + Ht::stash_script("hotcrp.add_preference_ajax(\"#revprefform_d\",true);hotcrp.shortcut(\"revprefform_d\").add()"); } private function papstrip_tag_entry($id) { @@ -1920,7 +1920,7 @@ private function _echo_editable_form() { $form_js["class"] .= " alert"; } echo Ht::form($this->conf->hoturl_post("paper", $form_url), $form_js); - Ht::stash_script('$(edit_paper_ui.load)'); + Ht::stash_script('$(hotcrp.load_editable_paper)'); } private function _echo_editable_body() { @@ -1967,7 +1967,7 @@ function paptabBegin() { $this->_papstrip(); } if ($this->npapstrip) { - Ht::stash_script("edit_paper_ui.prepare()"); + Ht::stash_script("hotcrp.prepare_editable_paper()"); echo '