classify.js 2.55 KB
define("portal/classify", ['utils','zepto', 'juicer'], function (_u) {
    var classify = {
        el: "#page-classify",
        tmpl: $("#classify-tmpl").html(),
        getApps: function() {
            return _u.ajax({action: "getAppsByUser"});
        },
        render: function(res) {
            var $el = $(this.el);
            var tmpl = juicer(this.tmpl, res);

            $el.find(".classifies").html(tmpl);
            this.bindEvent();
        },
        bindEvent: function() {
            var $el = $(this.el);

            require(["sortable"], function (Sortable) {
                var $apps = $el.find(".apps");

                $apps.on('click', '.app', function () {
                    var href = $(this).data('href');

                    window.open(href, "_self");
                });
                $apps.each(function () {
                    Sortable.create(this, {
                        delay: 300,
                        handle: '.app',
                        animation: 150,
                        forceFallback: true,
                        supportPointer: false,
                        scroll: false,
                        chosenClass: "app-chosen",
                        ghostClass: "app-ghost",
                        dragClass: "app-drag",
                        onEnd: function(e) {
                            var $apps = $(e.target), appids = [];
                            
                            if (e.newIndex === e.oldIndex) return;

                            $apps.find(".app").each(function(index, app) {
                                appids.push($(app).data("appid"));
                            });

                            _u.ajax({
                                action: "sort",
                                data: { appids: appids.join(",") },
                                type: "post"
                            });
                        }
                    });
                });
            });
        }
    };
    return {
        init: function () {
        	
        	var platform_parameters = "";
        	var portalUrl = window.location.href.split("#")[0];
            if(portalUrl.indexOf("?") > -1){//打开移动建模应用时,若缺失移动平台拼接的系统平台参数,会导致一些原生组件功能不能正常使用
            	platform_parameters = "&" + portalUrl.split("?")[1];
            }
            classify.tmpl = classify.tmpl.replace("&platform_parameters",platform_parameters);
            
            classify.getApps().then(classify.render.bind(classify));
        }
    };
});