illustration.js 3.9 KB
define(['app'], function (app) {
    'use strict';

    app.factory('$illustration', function ($http, $rootScope) {
        // data format: {'id_cate1': {name: '', list: [item1,item2]}, ...}
        // item format: {name: '', path: ''}
        var DATA = {
            'cate1': {
                name: 'category #1',
                list: [
                    {
                        name: 'item 1',
                        path: 'images/illustrations/item1.svg'
                    },
                    {
                        name: 'item 2',
                        path: 'images/illustrations/item2.svg'
                    },
                    {
                        name: 'item 3',
                        path: 'images/illustrations/item3.svg'
                    },
                    {
                        name: 'item 4',
                        path: 'images/illustrations/item4.svg'
                    },
                    {
                        name: 'item 1',
                        path: 'images/illustrations/item3.svg'
                    },
                    {
                        name: 'item 2',
                        path: 'images/illustrations/item1.svg'
                    },
                    {
                        name: 'item 3',
                        path: 'images/illustrations/item4.svg'
                    },
                    {
                        name: 'item 4',
                        path: 'images/illustrations/item2.svg'
                    }
                ]
            },
            'cate2': {
                name: 'category #2',
                list: [
                    {
                        name: 'item 1',
                        path: 'images/illustrations/item3.svg'
                    },
                    {
                        name: 'item 2',
                        path: 'images/illustrations/item1.svg'
                    },
                    {
                        name: 'item 3',
                        path: 'images/illustrations/item4.svg'
                    },
                    {
                        name: 'item 4',
                        path: 'images/illustrations/item2.svg'
                    },
                    {
                        name: 'item 1',
                        path: 'images/illustrations/item1.svg'
                    },
                    {
                        name: 'item 2',
                        path: 'images/illustrations/item2.svg'
                    },
                    {
                        name: 'item 3',
                        path: 'images/illustrations/item3.svg'
                    },
                    {
                        name: 'item 4',
                        path: 'images/illustrations/item4.svg'
                    }
                ]
            }
        };

        return {
            loadFromRemote: function (params,successHandle,errorHandle) {
                // return format: { status:0|1 , data:{} }
                var httpObj = $http({
                    url: $rootScope+'/apiv1/illustration',
                    method: 'GET',
                    params: params || []
                });
                if (typeof successHandle == 'undefined'){
                    successHandle = function(response){
                        if (response.status==1){
                            DATA = response.data;
                        }
                    }
                }
                httpObj.success(successHandle);
                
                if (typeof errorHandle != 'undefined'){
                    httpObj.error(errorHandle);
                }
            },
            getAll: function(){
                return DATA;
            },
            getList: function(category){
                if (typeof DATA[category] == 'undefined'){
                    return [];
                }
                return DATA[category];
            }
        };
    });
});