| 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 | 				array.forEach( value, lang.hitch( this, function( item ) { | 
            
              | 58 | 					this._addReferencingObjectLink(item); | 
            
              | 59 | 				})); | 
            
              | 60 | 			} else { | 
            
              | 61 | 				console.log('ReferencingObjects: not an object'); | 
            
              | 62 | 			}; | 
            
              | 63 | 		}, | 
            
              | 64 |  | 
            
              | 65 | 		_addReferencingObjectLink: function(item) { | 
            
              | 66 |  | 
            
              | 67 | 			//  make sure that the item has all necessary properties | 
            
              | 68 | 			if (!array.every(['module', 'id', 'objectType'], function(ikey) { | 
            
              | 69 | 				if (!(ikey in item)) { | 
            
              | 70 | 					console.log('ReferencingObjects: attribute module is missing'); | 
            
              | 71 | 					return false; | 
            
              | 72 | 				} | 
            
              | 73 | 				return true; | 
            
              | 74 | 			})) { | 
            
              | 75 | 				// item has not all necessary properties -> stop here | 
            
              | 76 | 				return false; | 
            
              | 77 | 			} | 
            
              | 78 |  | 
            
              | 79 | 			// perpare information to open the referenced UDM object | 
            
              | 80 | 			var moduleProps = { | 
            
              | 81 | 				flavor : item.flavor, | 
            
              | 82 | 				module : item.module, | 
            
              | 83 | 				openObject: { | 
            
              | 84 | 					objectDN : item.id, | 
            
              | 85 | 					objectType : item.objectType | 
            
              | 86 | 				} | 
            
              | 87 | 			}; | 
            
              | 88 |  | 
            
              | 89 | 			// create new button | 
            
              | 90 | 			var btn = new Button( { | 
            
              | 91 | 				name : 'close', | 
            
              | 92 | 				label : item.label, | 
            
              | 93 | 				iconClass: tools.getIconClass( item.icon, 20, null, "background-size: contain" ), | 
            
              | 94 | 				callback: function() { | 
            
              | 95 | 					// open referenced UDM object | 
            
              | 96 | 					if (app.getModule(moduleProps.module, moduleProps.flavor)) { | 
            
              | 97 | 						topic.publish("/umc/modules/open", moduleProps.module, moduleProps.flavor, moduleProps); | 
            
              | 98 | 					} else if (app.getModule(moduleProps.module, 'navigation')) {  // udm module | 
            
              | 99 | 						topic.publish("/umc/modules/open", moduleProps.module, 'navigation', moduleProps); | 
            
              | 100 | 					} else { | 
            
              | 101 | 						topic.publish("/umc/modules/open", moduleProps.module, moduleProps.flavor, moduleProps); | 
            
              | 102 | 					} | 
            
              | 103 | 				} | 
            
              | 104 | 			} ); | 
            
              | 105 |  | 
            
              | 106 | 			this.addChild( btn ); | 
            
              | 107 | 		}, | 
            
              | 108 |  | 
            
              | 109 | 		isValid: function() { | 
            
              | 110 | 			return true; | 
            
              | 111 | 		} | 
            
              | 112 | 	}); | 
            
              | 113 | }); |