|
Line 0
Link Here
|
|
|
1 |
/* |
| 2 |
* Copyright 2011-2016 Univention GmbH |
| 3 |
* |
| 4 |
* http://www.univention.de/ |
| 5 |
* |
| 6 |
* All rights reserved. |
| 7 |
* |
| 8 |
* The source code of this program is made available |
| 9 |
* under the terms of the GNU Affero General Public License version 3 |
| 10 |
* (GNU AGPL V3) as published by the Free Software Foundation. |
| 11 |
* |
| 12 |
* Binary versions of this program provided by Univention to you as |
| 13 |
* well as other copyrighted, protected or trademarked materials like |
| 14 |
* Logos, graphics, fonts, specific documentations and configurations, |
| 15 |
* cryptographic keys etc. are subject to a license agreement between |
| 16 |
* you and Univention and not subject to the GNU AGPL V3. |
| 17 |
* |
| 18 |
* In the case you use this program under the terms of the GNU AGPL V3, |
| 19 |
* the program is provided in the hope that it will be useful, |
| 20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
* GNU Affero General Public License for more details. |
| 23 |
* |
| 24 |
* You should have received a copy of the GNU Affero General Public |
| 25 |
* License with the Debian GNU/Linux or Univention distribution in file |
| 26 |
* /usr/share/common-licenses/AGPL-3; if not, see |
| 27 |
* <http://www.gnu.org/licenses/>. |
| 28 |
*/ |
| 29 |
/*global define console*/ |
| 30 |
|
| 31 |
define([ |
| 32 |
"dojo/_base/declare", |
| 33 |
"dojo/_base/lang", |
| 34 |
"dojo/_base/array", |
| 35 |
"dojo/on", |
| 36 |
"dojo/topic", |
| 37 |
"umc/widgets/Button", |
| 38 |
"umc/tools", |
| 39 |
"umc/app", |
| 40 |
"umc/widgets/ContainerWidget", |
| 41 |
], function(declare, lang, array, on, topic, Button, tools, app, ContainerWidget) { |
| 42 |
return declare("umc.modules.udm.ReferencingObjects", [ ContainerWidget, ], { |
| 43 |
// summary: |
| 44 |
// Provides a list of buttons opening a given object |
| 45 |
|
| 46 |
name: '', |
| 47 |
|
| 48 |
value: null, |
| 49 |
|
| 50 |
disabled: false, |
| 51 |
|
| 52 |
// the widget's class name as CSS class |
| 53 |
baseClass: 'umcLinkList', |
| 54 |
|
| 55 |
_setValueAttr: function(value) { |
| 56 |
if (value instanceof Object) { |
| 57 |
this._set('value', value); |
| 58 |
this.destroyDescendants(); |
| 59 |
array.forEach( value, lang.hitch( this, function( item ) { |
| 60 |
this._addReferencingObjectLink(item); |
| 61 |
})); |
| 62 |
} else { |
| 63 |
console.log('ReferencingObjects: not an object'); |
| 64 |
}; |
| 65 |
}, |
| 66 |
|
| 67 |
_addReferencingObjectLink: function(item) { |
| 68 |
|
| 69 |
// make sure that the item has all necessary properties |
| 70 |
if (!array.every(['module', 'id', 'objectType'], function(ikey) { |
| 71 |
if (!(ikey in item)) { |
| 72 |
console.log('ReferencingObjects: attribute module is missing'); |
| 73 |
return false; |
| 74 |
} |
| 75 |
return true; |
| 76 |
})) { |
| 77 |
// item has not all necessary properties -> stop here |
| 78 |
return false; |
| 79 |
} |
| 80 |
|
| 81 |
// perpare information to open the referenced UDM object |
| 82 |
var moduleProps = { |
| 83 |
flavor : item.flavor, |
| 84 |
module : item.module, |
| 85 |
openObject: { |
| 86 |
objectDN : item.id, |
| 87 |
objectType : item.objectType |
| 88 |
} |
| 89 |
}; |
| 90 |
|
| 91 |
// create new button |
| 92 |
var btn = new Button( { |
| 93 |
name : 'close', |
| 94 |
label : item.label, |
| 95 |
iconClass: tools.getIconClass( item.icon, 20, null, "background-size: contain" ), |
| 96 |
callback: function() { |
| 97 |
// open referenced UDM object |
| 98 |
if (app.getModule(moduleProps.module, moduleProps.flavor)) { |
| 99 |
topic.publish("/umc/modules/open", moduleProps.module, moduleProps.flavor, moduleProps); |
| 100 |
} else if (app.getModule(moduleProps.module, 'navigation')) { // udm module |
| 101 |
topic.publish("/umc/modules/open", moduleProps.module, 'navigation', moduleProps); |
| 102 |
} else { |
| 103 |
topic.publish("/umc/modules/open", moduleProps.module, moduleProps.flavor, moduleProps); |
| 104 |
} |
| 105 |
} |
| 106 |
} ); |
| 107 |
|
| 108 |
this.addChild( btn ); |
| 109 |
}, |
| 110 |
|
| 111 |
isValid: function() { |
| 112 |
return true; |
| 113 |
} |
| 114 |
}); |
| 115 |
}); |