Selamat Datang Di duealdi.blogspot.com Blog Karya ALDI XI TKJ SMKMUHHHAMADIYAH BOBOTSARI

Halaman

Universitas Sanata Dharma Blog Competition

Universitas Sanata Dharma Blog Competition

Jumat, 04 Desember 2015

Ini Sript UNtuk Membuat website local host tanpa reload

/**
 * Created by MacBookPro on 6/3/15.
 * By Pamungkas Jayuda
 * yulius.jayuda@gmail.com / +628119003077
 */

Template.masterBibits.created = function () {
    Session.set('limit', 5);
    Session.set('textSearch', "");
    Session.set('isCommentsMasterBibit', false);
    Session.set('idCommentsMasterBibit', "");

    Deps.autorun(function () {
        Meteor.subscribe('masterBibits', Session.get('limit'));
    });
}

Template.masterBibits.rendered = function () {
    $(window).scroll(function () {
        if ($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
            incrementLimit();
        }
    });
}

Template.masterBibits.helpers({
    isCommentsMasterBibit: function () {
        return Session.get('isCommentsMasterBibit');
    },
    isCreatingMasterBibit: function () {
        return Session.get('isCreatingMasterBibit');
    },
    isEditingMasterBibit: function () {
        return Session.get('editedMasterBibitId') === this._id;
    },
    masterBibits: function () {
        var textSearch = Session.get('textSearch').replace("#", "").trim();
        return MasterBibits.find(
            {
                $or: [
                    {nama: {$regex: ".*" + textSearch + ".*"}},
                    {harga: {$regex: ".*" + textSearch + ".*"}}
                ]
            },
            {
                sort: {createAt: 1},
                reactive: true,
                limit: Session.get('limit')
            }).fetch().reverse();
    },

    searchAssign: function() {
        var UserList = Meteor.users;
        return {
            limit: 10,
            rules: [
                {
                    collection: UserList,
                    field: 'username',
                    matchAll: true,
                    template: Template.searchAssign
                }
            ]
        };
    },

    searchMasterBibits: function() {
        return {
            limit: 10,
            rules: [
                {
                    token: '#',
                    collection: MasterBibits,
                    field: 'judul',
                    matchAll: true,
                    template: Template.searchMasterBibits
                }
            ]
        };
    }
});


Template.masterBibits.events({
    'keyup input#searchBox': function (e, tpl) {
        var textSearch = tpl.$('input[name="search"]').val().replace("#", "").trim();
        Session.set('textSearch', textSearch);
    },

    'click a.create': function (e, tpl) {
        e.preventDefault();
        Session.set('isCreatingMasterBibit', true);
    },

    "click a.addComments": function (e, tpl) {
        e.preventDefault();
        Session.set('isCommentsMasterBibit', true);
        Session.set('idCommentsMasterBibit', this._id);
    },

    'click a.remove': function (e, tpl) {
        e.preventDefault();
        FlashMasterBibits.sendInfo("Warning ! <BR> " + username() + ",<BR>MasterBibits " + this.judul + ", Telah Anda delete.");
        addActivityLogs("DELETE", username() + " Mendelete data MasterBibits : `" + this.judul + "` dengan ID : `" + this._id + "`", "masterBibits", this._id);
        MasterBibits.remove(this._id);
    },

    'click a.cancel': function (e, tpl) {
        e.preventDefault();
        Session.set('isCreatingMasterBibit', false);
        Session.set('isCommentsMasterBibit', false);
    },

    'click a.loadmore': function (e, tpl) {
        e.preventDefault();
        incrementLimit();
    },

    "submit form.form-search": function (e, tpl) {
        e.preventDefault();
        var textSearch = tpl.$('input[name="search"]').val();
        Session.set('textSearch', textSearch);
    },

    'submit form.create-masterBibit': function (e, tpl) {
        e.preventDefault();

        var masterBibitNama = tpl.$('input[name=nama]').val();
        var masterBibitHarga = tpl.$('input[name=harga]').val();


        if(masterBibitNama == ""){
            FlashMasterBibits.sendWarning("Mohon input Nama MasterBibits");
            return;
        }
        if(masterBibitHarga == ""){
            FlashMasterBibits.sendWarning("Mohon input Harga MasterBibits");
            return;
        }

        MasterBibits.insert({
            nama: masterBibitNama,
            harga: masterBibitHarga,
            createdAt: new Date(),
            createBy: username(),
            createByID: Meteor.userId(),
            comment: []
        }, function (error, _id) {
            if (error) {
                alert(error);
                Session.set('isCreatingMasterBibit', true);
            }
        });
        Session.set('isCreatingMasterBibit', false);
    },


    "submit form.form-comments": function (e, tpl) {
        e.preventDefault();
        var textComments = tpl.$('input[name="comments"]').val();
        Session.set('isCommentsMasterBibit', false);
        if (textComments.length) {
            addComments(Session.get('idCommentsMasterBibit'), textComments, MasterBibits);
        }
    }
});