Plugin Directory

Changeset 1996509


Ignore:
Timestamp:
12/17/2018 02:50:19 PM (7 years ago)
Author:
martindrapeau
Message:

Standings: allow filtering by sub-category

Location:
amilia-store/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • amilia-store/trunk/amilia-store.php

    r1995135 r1996509  
    66Author: Martin Drapeau <martin.drapeau@amilia.com>
    77Copyright: 2014-2018 Amilia
    8 Version: 2.9.2
     8Version: 2.9.3
    99Author URI: http://www.amilia.com/
    1010License: Apache License 2.0
     
    5151            "error-no-tags" => __("Oh no! You haven't set up tags yet. Checkout <a href='https://support.amilia.com/hc/en-us/articles/216528783-How-to-create-your-first-tag-' target='_blank'>this how to article</a>", 'amilia-store'),
    5252            "error-no-programs" => __("No programs found.", 'amilia-store'),
     53            "error-no-sub-categories" => __("No sub-categories found.", 'amilia-store'),
    5354            "help" => __("Help", 'amilia-store'),
    5455            "instructions" => __("Instructions", 'amilia-store'),
     
    105106            "game-schedule" => __("Game schedule", 'amilia-store'),
    106107            "standings-instructions-p1" => __("This is an experimental feature and works in conjunction with score and attendance tracking (https://lab.amilia.com/attendance).", 'amilia-store'),
    107             "standings-instructions-p2" => __("Choose the program in which you have activities representing teams (1 activity = 1 team).", 'amilia-store'),
     108            "standings-instructions-p2" => __("Choose the program and sub-category in which you have activities representing teams and the league (1 activity = 1 team, 1 sub-category = 1 league).", 'amilia-store'),
    108109            "standings-instructions-p3" => __("You can optionally filter activities shown by tags allowing you to exclude activities which are not teams.", 'amilia-store'),
    109110            "standings-instructions-p4" => __("The sport you choose determines how to count and display score and standings.", 'amilia-store'),
    110111            "select-program" => __("Select a program", 'amilia-store'),
     112            "select-sub-category" => __("Select a sub-category (optional)", 'amilia-store'),
    111113            "show-hidden-activities" => __("Show hidden activities", 'amilia-store'),
    112114            "show-staff" => __("Show staff", 'amilia-store'),
  • amilia-store/trunk/shortcodes/amilia-store-standings-client.js

    r1995041 r1996509  
    1414    var events = [];
    1515    var programId = options.program;
     16    var subCategoryId = options.subCategory;
    1617    var showHidden = options.showHidden;
    1718    var showStaff = options.showStaff;
     
    8586        for (var i = 0; i < events.length; i++) {
    8687            var event = events[i];
     88            if (subCategoryId && event.SubCategoryId != subCategoryId) continue;
    8789            if (tagIds.length) {
    8890                var found = false;
  • amilia-store/trunk/shortcodes/amilia-store-standings.js

    r1995041 r1996509  
    2222    '  <select name="program"></select>',
    2323    '  <div class="input-helper program"></div>',
     24    '</div>',
     25    '<div class="form-group">',
     26    '  <label>{select-sub-category} <a class="amilia-help" href="#">(?)</a></label>',
     27    '  <select name="sub-category"></select>',
     28    '  <div class="input-helper sub-category"></div>',
    2429    '</div>',
    2530    '<div class="form-group">',
     
    8489        programSelect = modal.querySelector('select[name="program"]'),
    8590        programSelectError = modal.querySelector('div.input-helper.program'),
     91        subCategorySelect = modal.querySelector('select[name="sub-category"]'),
     92        subCategorySelectError = modal.querySelector('div.input-helper.sub-category'),
    8693        tagsSelect = modal.querySelector('select[name="tags[]"]'),
    8794        tagsSelectError = modal.querySelector('div.input-helper.tags'),
     
    118125
    119126          programSelect.innerHTML = '';
    120           programSelectError.innerHTML == '';
     127          programSelectError.innerHTML = '';
    121128
    122129          if (orgPrograms.length > 0) {
     
    134141        },
    135142        function(xhr) {
    136           programSelectError.innerHTML == Amilia.lang('error-unexpected');
     143          programSelectError.innerHTML = Amilia.lang('error-unexpected');
     144        }
     145      );
     146    }
     147
     148    function getSelectedSubCategory() {
     149      var subCategoryId = parseInt(subCategorySelect.value, 10);
     150      return isNaN(subCategoryId) ? null : subCategoryId;
     151    }
     152
     153    function fetchSubCategoriesAndConstructSelect(selectedProgram, selectedSubCategory) {
     154      selectedProgram || (selectedProgram = getSelectedProgram());
     155      if (!selectedProgram) return;
     156
     157      selectedSubCategory || (selectedSubCategory = getSelectedSubCategory());
     158      subCategorySelectError.innerHTML = '';
     159
     160      var urlComponents = Amilia.getUrlComponents(storeUrl.value);
     161      if (urlComponents == null) return;
     162     
     163      subCategorySelectError.innerHTML = Amilia.lang('pleaseWait');
     164      Amilia.ajaxGetJson(urlComponents.apiUrl + 'Programs/' + selectedProgram + '/Activities?showHidden=true',
     165        function(xhr) {
     166          var response = JSON.parse(xhr.response) || {};
     167          var activities = response.Items;
     168
     169          subCategorySelect.innerHTML = '<option value=""></option>';
     170          subCategorySelectError.innerHTML = '';
     171
     172          if (activities.length > 0) {
     173            var usedIds = [];
     174            for (var i = 0; i < activities.length; i++) {
     175              var activity = activities[i];
     176              if (usedIds.indexOf(activity.SubCategoryId) >= 0) continue;
     177              var option = document.createElement('option');
     178              option.value = activity.SubCategoryId;
     179              option.innerText = activity.CategoryName + ' > ' + activity.SubCategoryName;
     180              if (selectedSubCategory == activity.SubCategoryId) option.selected = true;
     181              subCategorySelect.appendChild(option);
     182              usedIds.push(activity.SubCategoryId);
     183            }
     184          } else {
     185            subCategorySelectError.innerHTML = Amilia.lang('error-no-sub-categories');
     186          }
     187        },
     188        function(xhr) {
     189          subCategorySelectError.innerHTML = Amilia.lang('error-unexpected');
    137190        }
    138191      );
     
    182235    }
    183236
    184     function validateStoreUrlAndFetchProgramAndTags(selectedProgram, selectedTags) {
     237    function validateStoreUrlAndFetchProgramAndTags(selectedProgram, selectedSubCategory, selectedTags) {
    185238      Amilia.validateStoreUrl(storeUrl, storeUrlError,
    186239        function() {
    187240          fetchProgramsAndConstructSelect(selectedProgram);
    188241          fetchTagsAndConstructSelect(selectedTags);
     242          fetchSubCategoriesAndConstructSelect(selectedProgram, selectedSubCategory);
    189243        });
    190244    }
     
    194248    };
    195249
     250    programSelect.onchange = function() {
     251      fetchSubCategoriesAndConstructSelect(selectedSubCategory);
     252    }
     253
    196254    function generateShortCode() {
    197255      var urlComponents = Amilia.getUrlComponents(storeUrl.value);
    198256      var program = getSelectedProgram();
     257      var subCategory = getSelectedSubCategory();
    199258      var tags = getSelectedTags();
    200       return '[' + SHORTCODE + " url='{url}' sport='{sport}' program='{program}' tags='{tags}' showhidden='{show-hidden}' showstaff='{show-staff}' show='{show}' api='{api}']"
     259      return '[' + SHORTCODE + " url='{url}' sport='{sport}' program='{program}' subcategory='{sub-category}' tags='{tags}' showhidden='{show-hidden}' showstaff='{show-staff}' show='{show}' api='{api}']"
    201260        .replace('{url}', storeUrl.value)
    202261        .replace('{sport}', sportSelect.value)
    203262        .replace('{program}', program)
     263        .replace('{sub-category}', subCategory || '')
    204264        .replace('{tags}', tags.join(','))
    205265        .replace('{show-hidden}', showHidden.checked ? 1 : 0)
     
    253313
    254314        var program = activeShortcode.shortcode.attrs.named.program;
     315        var subCategory = activeShortcode.shortcode.attrs.named.subcategory;
    255316        var tags = (activeShortcode.shortcode.attrs.named.tags + '').split(',');
    256317        for (var i = 0; i < tags.length; i++) tags[i] = parseInt(tags[i], 10);
    257         validateStoreUrlAndFetchProgramAndTags(program, tags);
     318        validateStoreUrlAndFetchProgramAndTags(program, subCategory, tags);
    258319
    259320        showSelect.value = activeShortcode.shortcode.attrs.named.show || 'standings,schedule';
  • amilia-store/trunk/shortcodes/amilia-store-standings.php

    r1995041 r1996509  
    55        'sport' => 'soccer',
    66        'program' => '',
     7        'subcategory' => '',
    78        'tags' => '',
    89        'showhidden' => false,
     
    1819    $program = $a['program'];
    1920    if (!is_numeric($program)) $program = 'null';
     21    $subCategory = $a['subcategory'];
     22    if (!is_numeric($subCategory)) $subCategory = 'null';
    2023    $tags = $a['tags'];
    2124    $showHidden = $a['showhidden'] == 1 ? 1 : 0;
     
    7578            tags: [$tags],
    7679            program: $program,
     80            subCategory: $subCategory,
    7781            showHidden: $showHidden,
    7882            showStaff: $showStaff,
Note: See TracChangeset for help on using the changeset viewer.