/*
@copyright (c) Till Wehowski - All rights reserved
@license (Basic/EULA) http://look-up.webfan.de/webdof-license
@license (Source Code Re-Usage) http://look-up.webfan.de/bsd-license
Copyright (c) 2015, Till Wehowski All rights reserved.
@component https://github.com/frdl/-Flow/tree/master/components/webfan/marketplace
*/
(function(){
'use strict';
frdl_webfan_flow_advertising_external_linking(new frdl.Url(frdl.__FILE__()).getHost());
/*
var _TOK_ = '*[data-frdl-component$="webfan\/marketplace"]';
var __FILE__ = frdl.__FILE__();
var Url = new frdl.Url(__FILE__);
var __DIR__ = Url.getScheme() + '://' + Url.getHost() + '/' + Url.getDirectory();
frdl.UI.defer();
alert('Test: ' + new frdl.Url(frdl.__FILE__()).urlMakeNew()); */
frdl.ready(function(){
angular.module('webfan.marketplace',[])
.run([function( $scope, $element ) {
}])
.controller('MarketplaceCtrl', ['$scope', '$element', '$compile', '$http', function($scope, $element, $compile, $http) {
var __SHOPURL__ = 'http://interface.api.webfan.de/v1/public/software/marketplace/components.json';
$scope.AppData = frdl.UI.widgetAppData(frdl.__FILE__(frdl.UI.getWidget('webfan/marketplace').config.directory), 'webfan/marketplace');
$scope.caption='Widgets';
$scope.widgets = frdl.UI.widgets;
$scope.widgetsDesktop=[];
$scope.shopUrl_widgetdetail='http://shell.frdl.de/?test=component&component=';
$scope.shopUrl_downloadurl='http://webfan.de/cdn/frdl/flow/components/';
$scope.DBPFX = 'frdl/WebfanDesktop/';
setTimeout(function(){
$element.find('button[ng-bind="caption"]')
.trigger('click')
.hide()
;
},1);
$scope.browseComponent = function(url,title){
$('#webfanMarketplaceDialogDIV').wd_dialogs({loadUrl : url, title : title});
};
$scope.getDesktopUser = function(url,title){
try{
$scope.LOCAL_MACHINE_CURRENT_USER = frdl.UI.o.LOCAL_MACHINE_CURRENT_USER;
}catch(err){
$scope.LOCAL_MACHINE_CURRENT_USER='anonymous';
}
$scope.DB = $scope.DBPFX + $scope.LOCAL_MACHINE_CURRENT_USER + '/';
$scope.DB_WIDGETSKEY = $scope.DB + 'widgets/user/';
};
$scope.saveDesktopWidgets = function(){
$scope.getDesktopUser();
localStorage.setItem($scope.DB_WIDGETSKEY, base64_encode(JSON.stringify( $scope.widgetsDesktop )));
};
$scope.loadDesktopWidgets = function(){
$scope.getDesktopUser();
try{
$scope.widgetsDesktop = JSON.parse( base64_decode(localStorage.getItem($scope.DB_WIDGETSKEY)));
}catch(err){
$scope.widgetsDesktop=[];
}
if('undefined'=== typeof $scope.widgetsDesktop || null === $scope.widgetsDesktop || 'undefined'=== typeof $scope.widgetsDesktop.length)$scope.widgetsDesktop=[];
};
$scope.showApp = function(){
$http.get(__SHOPURL__)
.success(function(data, status, headers, config) {
$scope.loadDesktopWidgets();
$scope.shop = data.result.data;
$element.find('*[data-frdl-mod-marketplace]').css('display', 'inline-block');
/* $compile($element.contents())(angular.element($element).scope()); */
frdl.each($scope.shop, function(i,c){
if('undefined'===typeof $scope.shop[i].homepage)$scope.shop[i].homepage=$scope.shopUrl_widgetdetail + urlencode(c.name);
if('undefined'===typeof $scope.shop[i].download)$scope.shop[i].download=$scope.shopUrl_downloadurl + c.name;
});
})
.error(function(data, status, headers, config) {
console.error('cannot get components from server!');
});
};
$scope.removeDesktopWidget = function(ix){
$scope.widgetsDesktop.splice(ix,1);
$scope.saveDesktopWidgets();
$scope.loadDesktopWidgets();
};
$scope.addDesktopWidget = function(w){
if(true!==w.workspace){
alert('This widget ist not workspaceable, sorry!');
return;
}
var widget=w;
widget.$$hashKey=undefined;
$scope.widgetsDesktop.push(widget);
$scope.saveDesktopWidgets();
$('#desktop').append('<div data-frdl-desktop-widget="widget://components/'+widget.name+'"></div>');
if(frdl.Dom.isVisible('desktop'))frdl.wd().loadDesktopWidgets();
};
}])
;
});
}());
|