<commit_before>/*
 * e-additives.web
 * Copyright (C) 2013 VEXELON.NET Services
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

"use strict"; // jshint ;_;

require.config({
    //By default load any module IDs from js
    baseUrl: 'js',
    //enforceDefine: true,
    paths: {
        vendor: 'vendor',
        plugin: 'vendor/plugins',
        // libs
        jquery: ["//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min", "vendor/jquery-1.10.1.min"],
        bootstrap: 'vendor/bootstrap.min',
        sammy: 'vendor/sammy-0.7.4.min',
        underscore: 'vendor/underscore-min',
        moment: 'vendor/moment_langs.min',
        mustache: 'vendor/mustache',
        // plugins
        typeahead: 'vendor/plugins/typeahead.min'
    },
    shim: {
        'bootstrap': ['jquery', 'typeahead'],
        'underscore': {
            exports: '_'
        },
        'jquery': {
            exports: '$'
        },
        'sammy': ['jquery'],
        'typeahead': ['jquery']
    },
    waitSeconds: 10,
    urlArgs: "bust=" +  (new Date()).getTime() // TODO: use build num
});
    
require(['sammy', 'api', 'config', 'mustache', 'bootstrap', 'plugin/sammy.mustache', 'plugin/domReady!'], function(Sammy, API, Config, Mustache) {

    API.initialize(Config.serverUrl, Config.serverKey);

    var app = Sammy('div[role="pane"]', function() {
        this.use(Sammy.Mustache, 'ms');

        // TODO: if dev?!
        this.templateCache = function() {};

        var load_anim = '<p class="text-center"><img src="img/ajax-loader.gif"/></p>';

        // default
        this.get('#/', function() {
            this.redirect('#home');
        });
        // Main/Search page
        this.get('#home', function() {
            var self = this;
            self.swap(load_anim);

            this.partial('partials/home.ms', {}, function() {
                console.log('loaded');
                // single dataset
                $('.typeahead').typeahead({
                    name: 'accounts',
                    local: [
                        {'value': '101', 'code': '101', 'name': 'test'}
                    ],
                    template: '<p>{{value}} </p>',                                                    
                    engine: Mustache,
                    // template: function (datum) {
                    //     return datum.code;
                    // }                        
                });  
            });
        });
        // Additives browse page
        this.get('#additives', function() {
            var self = this;
            self.swap(load_anim);

            API.getAdditives(function(err, data) {
                if (err) {
                    console.log(err);
                    return;
                }
                self.partial('partials/additives.ms', {data: data});
            });            

            //this.partials = {name: 'opa', code: '101', info: 'text info'};
            //this.render('partials/single-additive.ms', {name: 'quirkey', code: '101'}).appendTo($('body'));<commit_msg>Typeahead now shows data fetched from server.<commit_after>/*
 * e-additives.web
 * Copyright (C) 2013 VEXELON.NET Services
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

"use strict"; // jshint ;_;

require.config({
    //By default load any module IDs from js
    baseUrl: 'js',
    //enforceDefine: true,
    paths: {
        vendor: 'vendor',
        plugin: 'vendor/plugins',
        // libs
        jquery: ["//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min", "vendor/jquery-1.10.1.min"],
        bootstrap: 'vendor/bootstrap.min',
        sammy: 'vendor/sammy-0.7.4.min',
        underscore: 'vendor/underscore-min',
        moment: 'vendor/moment_langs.min',
        mustache: 'vendor/mustache',
        // plugins
        typeahead: 'vendor/plugins/typeahead.min'
    },
    shim: {
        'bootstrap': ['jquery', 'typeahead'],
        'underscore': {
            exports: '_'
        },
        'jquery': {
            exports: '$'
        },
        'sammy': ['jquery'],
        'typeahead': ['jquery']
    },
    waitSeconds: 10,
    urlArgs: "bust=" +  (new Date()).getTime() // TODO: use build num
});
    
require(['sammy', 'config', 'api', 'mustache', 'bootstrap', 'plugin/sammy.mustache', 'plugin/domReady!'], 
    function(Sammy, Config, API, Mustache) {

    API.initialize(Config.serverUrl, Config.serverKey);

    var app = Sammy('div[role="pane"]', function() {
        this.use(Sammy.Mustache, 'ms');

        // TODO: if dev?!
        this.templateCache = function() {};

        var load_anim = '<p class="text-center"><img src="img/ajax-loader.gif"/></p>';
        var searchTemplateCode = Mustache.compile('<h4><span class="label label-default">{{code}}</span> {{name}}</h4>');
        var searchTemplateName = Mustache.compile('<h4>{{name}} <span class="label label-default">{{code}}</span></h4>');

        // default
        this.get('#/', function() {
            this.redirect('#home');
        });
        // Main/Search page
        this.get('#home', function() {
            var self = this;
            self.swap(load_anim);

            this.partial('partials/home.ms', {}, function() {
                API.getAdditives(function(err, data) {
                    if (err) {
                        console.log(err);
                        return;
                    }
                    $('.typeahead').typeahead([
                        {
                            name: 'additives-codes',
                            valueKey: 'code',
                            limit: 7,
                            local: data,
                            template: searchTemplateCode,
                            engine: Mustache,
                        },
                        {
                            name: 'additives-names',
                            valueKey: 'name',
                            limit: 7,
                            local: data,
                            template: searchTemplateName,
                            engine: Mustache,
                        }
                    ]);                     
                }); //eof-API
            }); //eof-this.partial
        });
        // Additives browse page
        this.get('#additives', function() {
            var self = this;
            self.swap(load_anim);

            API.getAdditives(function(err, data) {
                if (err) {
                    console.log(err);
                    return;
                }
                self.partial('partials/additives.ms', {data: data});
            });            

            //this.partials = {name: 'opa', code: '101', info: 'text info'};
            //this.render('partials/single-additive.ms', {name: 'quirkey', code: '101'}).appendTo($('body'));
{'fraction_non_alphanumeric': 0.14255556935303615, 'fraction_numerical': 0.0074506395132248856, 'mean_word_length': 1.6251629726205998, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '697748', 'n_tokens_mistral': 2279, 'n_tokens_neox': 2141, 'n_words': 559}