Sha256: dc72bfd18c328244718f798ac20a65805976c6e2ac651fefcfbd5fb774286a98

Contents?: true

Size: 1.71 KB

Versions: 28

Compression:

Stored size: 1.71 KB

Contents

/**
 * Load topics
 */

var Topics = {};

/**
 * get topics as JSON and return the topics grouped by category
 *
 * [
 *   {
 *     title: <category>,
 *     topics: [
 *       <topic data from gbtopics>
 *     ]
 *   }
 * ]
 */
Topics.loadTopics = function(url, callback) {
  $.getJSON(url, function(data) {
    // sort by categorysort and categorytitle
    var gbtopics = data.gbtopics.sort(function(a, b) {
      var res = a.categorysort - b.categorysort;
      if (res === 0) {
        res = a.categorytitle.localeCompare(b.categorytitle);
      }
      else if (a.categorysort === null || b.categorysort === null) {
        // null values have lowest priority
        res = -res;
      }
      return res;
    });

    // group by category
    categories = {};
    for (var i=0;i<gbtopics.length; i++) {
      var topic = gbtopics[i];

      if (categories[topic.categorytitle] === undefined) {
        categories[topic.categorytitle] = [];
      }
      categories[topic.categorytitle].push(topic);
    }

    var sortedCategories = [];
    for (var key in categories) {
      if (categories.hasOwnProperty(key)) {
        // sort by categories_topics_sort and title
        var topics = categories[key].sort(function(a, b) {
          var res = a.categories_topics_sort - b.categories_topics_sort;
          if (res === 0) {
            res = a.title.localeCompare(b.title);
          }
          else if (a.categories_topics_sort === null || b.categories_topics_sort === null) {
            // null values have lowest priority
            res = -res;
          }
          return res;
        });
        sortedCategories.push({
          title: key,
          topics: topics
        });
      }
    }

    callback(sortedCategories);
  });
};

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
gb_mapfish_appserver-2.0.0 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-1.1.1 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-1.1.0 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-1.0.6 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-1.0.5 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-1.0.4 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-1.0.3 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-1.0.2 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-1.0.1 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-1.0.0 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-0.9.7 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-0.9.6 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-0.9.5 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-0.9.4 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-0.9.3 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-0.9.2 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-0.9.1 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-0.9.0 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-0.8.7 test/dummy/public/apps/myviewer/src/topics.js
gb_mapfish_appserver-0.8.6 test/dummy/public/apps/myviewer/src/topics.js