invite.php 38 KB
Newer Older
Raph El's avatar
Raph El committed
1
2
<?php
$cssJs = array(
3
	//'/assets/css/freelancer.css',
Raph El's avatar
Raph El committed
4
5
6
7
);
HtmlHelper::registerCssAndScriptsFiles($cssJs, Yii::app()->theme->baseUrl);


Raphael's avatar
Raphael committed
8

Raph El's avatar
Raph El committed
9
10
11
12
13
14
15
16
17
$cssJs = array(
	'/plugins/select2/select2.min.js' ,
	'/plugins/select2/select2.css',
);
HtmlHelper::registerCssAndScriptsFiles($cssJs, Yii::app()->getRequest()->getBaseUrl(true));

?>

<style>
Raph El's avatar
Raph El committed
18
#modal-invite .dropdown-menu{
Raphael's avatar
Raphael committed
19
20
	top:65%;
	left : 15px;
Raph El's avatar
Raph El committed
21
	position: relative;
Raphael's avatar
Raphael committed
22
23
24

}

Raph El's avatar
Raph El committed
25
#modal-invite .nav-tabs > li > a {
Raph El's avatar
Raph El committed
26
27
28
29
30
31
	border: 0 none;
	border-radius: 5px;
	color: #8E9AA2;
	min-width: 70px;
	padding: 5px !important;
	margin-bottom:10px;
Raphael's avatar
Raphael committed
32
}
Raph El's avatar
Raph El committed
33
#modal-invite .nav-tabs > li > a {
Raphael's avatar
Raphael committed
34
35
	background-color: transparent !important;
}
Raph El's avatar
Raph El committed
36
#modal-invite .nav-tabs > li > a > div:hover {
Raph El's avatar
Raph El committed
37
38
	background-color: #3C5665;
	color:white !important;
Raphael's avatar
Raphael committed
39
}
Raph El's avatar
Raph El committed
40
#modal-invite .nav-tabs > li > a > div:focus {
Raph El's avatar
Raph El committed
41
42
	background-color: #3C5665;
	color:white !important;
Raphael's avatar
Raphael committed
43
44
}

Raph El's avatar
Raph El committed
45
#modal-invite  #listEmailGrid{
Raphael's avatar
Raphael committed
46
47
48
49
50
51
52
53
	max-height:400px;
	min-height:250px;
	overflow-y:auto; 
	overflow-x:hidden; 
	padding-top:15px;
	border-left: 1px solid rgba(128, 128, 128, 0.26);
}

Raph El's avatar
Raph El committed
54
55
#modal-invite .btn-scroll-type{
	border:none!important;
Raph El's avatar
Raph El committed
56
57
58
	padding: 3px;
	text-align: left;
	/*width: 100%;*/
Raph El's avatar
Raph El committed
59
60
61
62
63
64
65
}
#modal-invite .btn-select-contact{
	min-width:70% !important;
}

#modal-invite .btn-scroll-type{
	border:none!important;
Raph El's avatar
Raph El committed
66
	padding: 2px;
Raph El's avatar
Raph El committed
67
68
69
70
71
	text-align: left;
	padding: 6px 4px 4px 8px;
	margin-bottom: 3px;
	background:transparent !important;
}
72
73
74
#dropdown-search-invite .listInviteElement{
	cursor: pointer;
}
Clément Damiens's avatar
   
Clément Damiens committed
75
#modal-invite .listInviteElement:hover,#modal-invite .not-find-inside:hover, .li-dropdown-invite-results a{
Raph El's avatar
Raph El committed
76
	background-color:rgba(0, 0, 0, 0.04) !important;
Clément Damiens's avatar
   
Clément Damiens committed
77
	cursor: pointer;
Raph El's avatar
Raph El committed
78
79
}

Raph El's avatar
Raph El committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93

.btn-is-admin{
	text-decoration: line-through;
	display:inline;
}
.divRoles{
	margin:5px;
}
.btn-is-admin.isAdmin {
	text-decoration: none;
}
.btn-is-admin.isAdmin a{
	color:#5cb85c!important;
}
Clément Damiens's avatar
Clément Damiens committed
94
.listInviteElement .thumb-send-to, .li-dropdown-invite-results .thumb-send-to{
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
	width: 40px;
    height: 40px;
    border-radius: 50%;
    padding: 3px;
    margin-top: 7px;
 }
 .listInviteElement span.name-invite{
 	margin-top: 7px;	
 }
 .listInviteElement span.follows{
 	font-style: italic;
 	color: gray;
 }
 .listInviteElement .remove-invite{
 	padding: 3px 8px;
    border-radius: 3px;
    margin-top: 19px;
 }
Clément Damiens's avatar
Clément Damiens committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
 .li-dropdown-invite-results{
 	list-style: none;
 }
 .li-dropdown-invite-results .success, .li-dropdown-invite-results .error{
 	border-radius:100%; 
    height: 40px;
    line-height: 40px;
    font-size: 25px;
    width: 40px;
    color: white;
 }
.li-dropdown-invite-results .msg-back{
 	font-style: italic;
 }
Raph El's avatar
Raph El committed
127

Raphael's avatar
Raphael committed
128
</style>
Raph El's avatar
Raph El committed
129
<div class="<?php if(empty($search) || $search == false){ ?> portfolio-modal modal fade <?php } ?>" id="modal-invite" tabindex="-1" role="dialog" aria-hidden="true">
Raph El's avatar
Raph El committed
130
	<div class="modal-content padding-top-15">
Raph El's avatar
Raph El committed
131
132
		<?php
		if(empty($search) || $search == false){ ?>
Raph El's avatar
Hotfix    
Raph El committed
133
134
135
136
137
138
		<div class="close-modal" data-dismiss="modal">
			<div class="lr">
				<div class="rl">
				</div>
			</div>
		</div>
Raph El's avatar
Raph El committed
139
		<?php } ?>
Raph El's avatar
Raph El committed
140
141
142
143
144
		<div class="container">
			<div class="row">
				<div class="col-lg-12">
					<h3 class="letter-red no-margin hidden-xs">
						<i class="fa fa-plus-circle"></i> 
Raph El's avatar
Raph El committed
145
146
147
148
						<span id="title-invite">
							<?php
								if($parentType == Person::COLLECTION)
									echo Yii::t("invite","Search or invite your contacts");
Raph El's avatar
Raph El committed
149
								else if ($parentType == Event::COLLECTION )
Clément Damiens's avatar
Clément Damiens committed
150
									echo Yii::t("common","Invite people on") ;			
Raph El's avatar
Raph El committed
151
								else if ($parentType == Project::COLLECTION )
Clément Damiens's avatar
Clément Damiens committed
152
									echo Yii::t("common",'Invite contributors on') ;
Raph El's avatar
Raph El committed
153
								else
Clément Damiens's avatar
Clément Damiens committed
154
									echo Yii::t("common","Invite members on");
Raph El's avatar
Raph El committed
155
							?>
Clément Damiens's avatar
Clément Damiens committed
156
							<br/><span class="name-parent bold"></span>
Raph El's avatar
Raph El committed
157
158
						</span>
						<br>
Raph El's avatar
Raph El committed
159
160
161
162
163
					</h3>
				</div>
			</div>
			<div class="row">
				<div class="col-md-12 margin-top-15 text-dark menuInvite">
Raphael's avatar
Raphael committed
164
165
166
167
					<ul class="nav nav-tabs">
						<li role="presentation">
							<a href="javascript:" class="" id="menuInviteSomeone">
								<div id="titleInviteSomeone" class='radius-10 padding-10 text-yellow text-dark'>
Raph El's avatar
Raph El committed
168
									<i class="fa fa-search fa-2x"></i> 
Raph El's avatar
Raph El committed
169
									<?php echo Yii::t("common","Search"); ?> 
Raphael's avatar
Raphael committed
170
171
172
								</div>
							</a>
						</li>
Raph El's avatar
Raph El committed
173
						
Raph El's avatar
Raph El committed
174
175
176
						<?php
						if($parentType != Person::COLLECTION){
						?>
Raph El's avatar
Raph El committed
177
						<li role="presentation">
Raph El's avatar
Raph El committed
178
							<a href="javascript:" class="" id="menuMyContacts">
Raph El's avatar
Raph El committed
179
								<div id="titleWriteMails" class='radius-10 padding-10 text-grey text-dark'>
Raph El's avatar
Raph El committed
180
181
									<i class="fa fa-users fa-2x"></i> 
									<?php echo Yii::t("invite","My contacts"); ?>
Raphael's avatar
Raphael committed
182
								</div>
Raph El's avatar
Raph El committed
183
184
							</a>
						</li>
Raph El's avatar
Raph El committed
185
186
187
						<?php
						}
						?>
Raph El's avatar
Raph El committed
188
189
190
191
192
193
194
195
196
						<li role="presentation">
							<a href="javascript:" class="" id="menuImportFile">
								<div id="titleImportFile" class='radius-10 padding-10 text-grey text-dark'>
									<i class="fa fa-pencil fa-2x"></i> 
									<?php echo Yii::t("invite","Others");
									//echo Yii::t("invite","Import a file"); ?> 
								</div>
							</a>
						</li>
Raphael's avatar
Raphael committed
197
198
199
					</ul>
				</div>
			</div>
Raph El's avatar
Hotfix    
Raph El committed
200
			<div class="row " id="divSearchInvite">
Raph El's avatar
Modif    
Raph El committed
201
				<div id="step1-search" class="modal-body col-xs-6" >
Raph El's avatar
Raph El committed
202
					<div class="form-group">
Raph El's avatar
trad    
Raph El committed
203
						<input type="text" class="form-control text-left" placeholder='<?php echo Yii::t("invite", "A name, an e-mail..."); ?>' autocomplete = "off" id="inviteSearch" name="inviteSearch" value="">
204
205
						<div class="col-xs-12 no-padding" id="dropdown-search-invite" style="max-height: 400px; overflow: auto;"></div>
						<form id="form-invite" class="box-login col-xs-12 no-padding" style="padding:5px">
Raph El's avatar
Raph El committed
206
						<!-- <div class="col-xs-12" id="form-invite" style="padding:5px"> -->
207
208
							<div class="modal-body text-center no-padding">
								<h3 class="text-dark">
Raph El's avatar
Raph El committed
209
									<i class="fa fa-plus-circle padding-bottom-10"></i>
Raph El's avatar
Raph El committed
210
									<span class="font-light"> <?php echo Yii::t("person","Invite someone"); ?></span>
211
								</h3>
Raph El's avatar
Raph El committed
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233

								<div class="row margin-bottom-10">
									<div class="col-md-1 col-md-offset-1" id="iconUser">    
										<i class="fa fa-user fa-2x"></i>
									</div>
									<div class="col-md-9">
										<input class="invite-name form-control" placeholder="<?php echo Yii::t("common", "Name");?>" id="inviteName" name="inviteName" value="" />
									</div>
								</div>
								<div class="row margin-bottom-10">
									<div class="col-md-1 col-md-offset-1">  
										<i class="fa fa-envelope-o fa-2x"></i>
									</div>
									<div class="col-md-9">
										<input class="invite-email form-control" placeholder="<?php echo Yii::t("common", "Email");?>" id="inviteEmail" name="inviteEmail" value="" />
									</div>
								</div>
								<div class="row margin-bottom-10">
									<div class="col-md-1 col-md-offset-1">  
										<i class="fa fa-align-justify fa-2x"></i>
									</div>
									<div class="col-md-9">
Raph El's avatar
Raph El committed
234
										<textarea class="invite-text form-control" id="inviteText" name="inviteText" rows="4" placeholder="<?php echo Yii::t("invite","Custom message"); ?> "></textarea>
Raph El's avatar
Raph El committed
235
236
237
238
									</div>
								</div>

							</div>
Raph El's avatar
Raph El committed
239
							<div class="errorHandler alert alert-danger"></div>
Raph El's avatar
Raph El committed
240
241
							<div class="col-md-12 col-sm-12 col-xs-12 text-center">
								<hr>
242
								<button class="btn btn-success" id="btnInviteNew" ><i class="fa fa-add"></i> <?php echo Yii::t("invite","Add to the list"); ?> </button>
Raph El's avatar
Raph El committed
243
							</div>
Raph El's avatar
Raph El committed
244
						</form>
Raph El's avatar
Raph El committed
245
246
					</div>
				</div>
Raph El's avatar
Raph El committed
247
248
249
250
251
252
253
254
255
				<div id="step1-other" class="modal-body col-xs-6">
					<div class="form-group col-xs-12">
						<select id="typeOther" name="typeOther">
							<option value="-1"><?php echo Yii::t("common","Choose"); ?></option>
							<option value="import"><?php echo Yii::t("invite","Import a file"); ?></option>
							<option value="text"><?php echo Yii::t("invite","Write"); ?></option>
						</select>
					</div>
					<div class="form-group col-xs-12" id="step-import">
Raph El's avatar
Raph El committed
256
						<label for="fileEmail" > <?php echo Yii::t("invite","Files (CSV)"); ?> : <input type="file" id="fileEmail" name="fileEmail" accept=".csv"> </label>
Raph El's avatar
Raph El committed
257
					</div>
Raph El's avatar
Raph El committed
258
259
260
261
262
263
					<div class="form-group col-xs-12" id="step-text" >
						<textarea id="textarea-invite" rows="10" cols="50"></textarea></br>
						<button id="btnValiderTextarea" class="btn btn-success" >
							<?php echo Yii::t("invite","Check"); ?> 
						</button>
					</div>
Raph El's avatar
Raph El committed
264
					<span id="errorFile" class="col-xs-12 text-red" ></span>
Raph El's avatar
Raph El committed
265
266
267
268
269
				</div>
				<div id="step1-mycontacts" class="modal-body col-xs-6" >
					<div class="form-group">
						<div class="col-xs-12" id="dropdown-mycontacts-invite" style="max-height: 400px; overflow: auto;"></div>
					</div>
Raph El's avatar
Modif    
Raph El committed
270
				</div>
Raph El's avatar
Raph El committed
271
272
				<div id="step2" class="modal-body col-xs-6" >
					<div class="form-group">
273
						<div class="col-xs-12 no-padding">
Raph El's avatar
Raph El committed
274
							<h4> <?php echo Yii::t("invite","List of persons invited"); ?></h4>
275
							<div class="col-xs-12 no-padding" id="dropdown-invite" style="max-height: 400px; overflow-y: auto;"></div>
Raph El's avatar
Raph El committed
276
277
						</div>
						<div class="col-xs-12" style="margin-top: 10px;">
Raph El's avatar
Raph El committed
278
							<button id="btnValider" class="btn btn-success" >
279
								<?php echo Yii::t("common","Launch invitations"); ?> 
Raph El's avatar
Raph El committed
280
281
							</button>
						</div>
Raph El's avatar
Raph El committed
282
283
284
					</div>
				</div>
			</div>
Raph El's avatar
Hotfix    
Raph El committed
285
286
287
288
			<div class="row" id="divResult">
				<div id="stepResult" class="modal-body col-xs-12" >
					<div class="form-group">
						<div class="col-xs-12">
Clément Damiens's avatar
Clément Damiens committed
289
							<h4> <?php echo Yii::t("invite", "Result of invitations sent") ;?> </h4>
Raph El's avatar
Raph El committed
290
							<div class="col-xs-12" id="dropdown-result"" style="max-height: 400px; overflow: auto;"></div>
Raph El's avatar
Hotfix    
Raph El committed
291
							<?php 
Raph El's avatar
Raph El committed
292
293
294
							if($parentType == Form::COLLECTION){ 

								?>
Raph El's avatar
Raph El committed
295
								<a href="<?php echo Yii::app()->getRequest()->getBaseUrl(true) ?>/survey/co/members/id/<?php echo $id; ?>/session/<?php echo $_GET["session"]; ?>" class="btn btn-success margin-top-20 col-xs-12 " id="btn-home" style="font-size:20px;"><i class="fa fa-home"></i> <?php echo Yii::t("invite","See the community") ?></a>
Raph El's avatar
Modif    
Raph El committed
296
297
298
							<?php } else if($parentType == Proposal::COLLECTION){?>
								<button class="btn btn-success margin-top-20 col-xs-12" data-dismiss="modal"><i class="fa fa-users" ></i> <?php echo Yii::t("invite","Close invite") ?></button>
							<?php }  else /*if($parentType != Person::COLLECTION) */ {?>
Clément Damiens's avatar
Clément Damiens committed
299
300
								<button class="btn btn-success margin-top-20 col-xs-12 link-to-community"><i class="fa fa-users"></i> <?php echo Yii::t("invite","See the community") ?></button>
							<?php } ?>
Raph El's avatar
Hotfix    
Raph El committed
301
302
303
304
						</div>
					</div>
				</div>
			</div>
Raph El's avatar
Raph El committed
305
306
		</div>
	</div>
Raphael's avatar
Raphael committed
307
308
309
310
</div>


<script type="text/javascript">
Raph El's avatar
Hotfix    
Raph El committed
311
312
	var parentType = "<?php echo $parentType; ?>";
	var parentId = "<?php echo $parentId; ?>";
Raph El's avatar
Raph El committed
313
	var parentLinks = <?php echo json_encode(@$parentLinks); ?>;
Raph El's avatar
Raph El committed
314
	// var members = <?php //echo json_encode( $members ); ?>;
Raph El's avatar
Hotfix    
Raph El committed
315
	var contactTypes = {
Clément Damiens's avatar
Clément Damiens committed
316
317
			citoyens : { color: "yellow", icon:"user", label: trad.People },
			organizations :	{ color: "green", icon:"group", label: trad.Organizations } 
Raph El's avatar
Hotfix    
Raph El committed
318
		};
Raph El's avatar
Raph El committed
319
	var rolesListCustom = <?php echo json_encode(@$roles); ?>;
Raph El's avatar
Raph El committed
320
	var isElementAdmin= "<?php echo Authorisation::isElementAdmin($parentId, $parentType, @Yii::app()->session["userId"]) ?>";
Raphael's avatar
Raphael committed
321

Raph El's avatar
Raph El committed
322
323
	var listInvite = { 
		citoyens : {},
Raph El's avatar
Raph El committed
324
325
		organizations : {},
		invites : {},
Raph El's avatar
Raph El committed
326
327
	};

Raph El's avatar
Raph El committed
328
	jQuery(document).ready(function() {
Raph El's avatar
Raph El committed
329
		// mylog.log("members", members);
Raph El's avatar
Raph El committed
330
		if(parentType != "citoyens" && typeof contextData != "undefined" && contextData != null)
Clément Damiens's avatar
Clément Damiens committed
331
			$("#title-invite .name-parent").text(contextData.name);
Raph El's avatar
Raph El committed
332
		initInvite();
Raph El's avatar
Raph El committed
333
		bindInvite();
Raph El's avatar
Raph El committed
334
		fadeInView("step1-search");
Raph El's avatar
Raph El committed
335
336
		if(rolesListCustom.length > 0)
			rolesList = rolesListCustom ;
Raphael's avatar
Raphael committed
337
338
	});

Raph El's avatar
Modif    
Raph El committed
339
340
	function fadeInView(inView){
		mylog.log("fadeInView", inView);
Raph El's avatar
Raph El committed
341
342
343
344
345
346
347
348

		if( Object.keys(listInvite.organizations).length == 0 &&
			Object.keys(listInvite.citoyens).length == 0 && 
			Object.keys(listInvite.invites).length == 0){
			initInvite();
			if(inView == "step1-search") {
				$("#modal-invite #divSearchInvite").show();
				$("#modal-invite #step1-search").show();
Raph El's avatar
Raph El committed
349
			} else if(inView == "step1-other") {
Raph El's avatar
Raph El committed
350
				$("#modal-invite #divSearchInvite").show();
Raph El's avatar
Raph El committed
351
				$("#modal-invite #step1-other").show();
Raph El's avatar
Raph El committed
352
353
354
355
356
357
358
			} else if(inView == "step1-mycontacts") {
				$("#modal-invite #divSearchInvite").show();
				$("#modal-invite #step1-mycontacts").show();
			}else if(inView == "result"){
				$("#modal-invite #divResult").show();
				$("#modal-invite #dropdown-result").show();
			}
Raph El's avatar
Modif    
Raph El committed
359

Raph El's avatar
Raph El committed
360
		} else {
Raph El's avatar
Raph El committed
361
			toastr.error(tradDynForm.pleaseValidateTheCurrentInvites);
Raph El's avatar
Modif    
Raph El committed
362
		}
Raph El's avatar
Raph El committed
363
364

		
Raph El's avatar
Modif    
Raph El committed
365
366
	}

Raph El's avatar
Raph El committed
367
368
369
370
371
372
373
374
	function initListInvite(){
		listInvite = { 
			citoyens : {},
			organizations : {},
			invites : {},
		};
	}

Raph El's avatar
Raph El committed
375
376
377
378
	function initInvite(){
		$("#modal-invite #divSearchInvite").hide();
		$("#modal-invite #divResult").hide();
		$("#modal-invite #step1-search").hide();
Raph El's avatar
Raph El committed
379
		$("#modal-invite #step1-other").hide();
Raph El's avatar
Raph El committed
380
381
382
		$("#modal-invite #step1-mycontacts").hide();
		$("#modal-invite #step2").hide();
		$("#modal-invite #form-invite").hide();
Raph El's avatar
Raph El committed
383
		$("#modal-invite #errorFile").hide();
Raph El's avatar
Raph El committed
384
385
		$("#modal-invite #step-import").hide();
		$("#modal-invite #step-text").hide();
Raph El's avatar
Raph El committed
386
387
388
389

		$("#modal-invite #dropdown-invite").html("");
		$("#modal-invite #dropdown-search-invite").html("");
		$("#modal-invite #dropdown-result").html("");
Raph El's avatar
Raph El committed
390
		$("#modal-invite #errorFile").html("");
Raph El's avatar
Raph El committed
391
392
393
394

		$("#modal-invite #inviteSearch").val("");
		$("#modal-invite #inviteName").val("");
		$("#modal-invite #inviteEmail").val("");
Raph El's avatar
Raph El committed
395
		$("#fileEmail").val("");
Raph El's avatar
Raph El committed
396
397

		$("#modal-invite .errorHandler").hide();
Raph El's avatar
Raph El committed
398
399

		
Raph El's avatar
Raph El committed
400
401
402
		
	}

Raph El's avatar
Raph El committed
403
	function bindInvite(){
Raph El's avatar
Modif    
Raph El committed
404

Raph El's avatar
Raph El committed
405
406
407
408
409
		$("#modal-invite #menuMyContacts").click(function() {
			mylog.log("menuMyContacts");
			fadeInView("step1-mycontacts");
			myContactsToListInvites();
		});
Clément Damiens's avatar
Clément Damiens committed
410
411
412
413
		$(".link-to-community").click(function(){
			$(".close-modal").trigger("click");
			$(".load-data-community").trigger("click");
		});
Raph El's avatar
Raph El committed
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
		$("#modal-invite #typeOther").change(function(e) {
			mylog.log("typeOther");
			initInvite();
			fadeInView("step1-other");
			if( $(this).val() == "import" ){
				$("#modal-invite #step-import").show();
				$("#modal-invite #step-text").hide();
			} else if( $(this).val() == "text" ){
				$("#modal-invite #step-import").hide();
				$("#modal-invite #step-text").show();
			} else {
				$("#modal-invite #step-import").hide();
				$("#modal-invite #step-text").hide();
			}
		});

		$("#modal-invite #btnValiderTextarea").click(function() {
			var textarea = $("#modal-invite #textarea-invite").val();
			var mailsArray = [] ;
			if(textarea.indexOf("<") > -1)
				textarea = textarea.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi).join(';');
			mailsArray = textarea.split(/[\s\n;,]+/);
			checkAndGetMailsInvite(mailsArray);
		});

Raph El's avatar
Raph El committed
439

Raph El's avatar
Modif    
Raph El committed
440
		$("#modal-invite #menuImportFile").click(function() {
Raph El's avatar
Raph El committed
441
			mylog.log("menuImportFile");
Raph El's avatar
Raph El committed
442
			fadeInView("step1-other");
Raph El's avatar
Modif    
Raph El committed
443
444
445
446
447
448
		});

		$("#modal-invite #menuInviteSomeone").click(function() {
			fadeInView("step1-search");
		});

Raph El's avatar
Raph El committed
449
450
451
		$("#modal-invite #fileEmail").change(function(e) {
			mylog.log("fileEmail");
			$.blockUI({
Clément Damiens's avatar
Clément Damiens committed
452
				message : '<span class="homestead"><i class="fa fa-spin fa-circle-o-noch"></i> '+trad.currentlyloading+'...</span>'
Raph El's avatar
Raph El committed
453
454
455
456
457
			});
			//$("#listEmailGrid").html("");
			var ext = $("#modal-invite input#fileEmail").val().split(".").pop().toLowerCase();
			mylog.log("ext", ext);
			if($.inArray(ext, ["csv"]) == -1) {
Raph El's avatar
Raph El committed
458
				toastr.error(tradDynForm.youMustUseACSVFormat);
Raph El's avatar
Raph El committed
459
460
461
462
				return false;
			} 

			if (e.target.files != undefined) {
Raph El's avatar
Raph El committed
463
				initListInvite();
Raph El's avatar
Raph El committed
464
465
466
467
468
469
470
				var reader = new FileReader();
				mylog.log("reader", reader);
				reader.onload = function(e) {
					var csvval = e.target.result.split("\n");
					checkAndGetMailsInvite(csvval);
				};
				reader.readAsText(e.target.files.item(0));
Raph El's avatar
Raph El committed
471

Raph El's avatar
Raph El committed
472
			}else{
Raph El's avatar
Raph El committed
473
				toastr.error(tradDynForm.weWereUnableToReadYourFile);
Raph El's avatar
Raph El committed
474
475
476
477
			}
			return false;
		});

Raph El's avatar
Raph El committed
478
479
480
481
482
483
484
		$('#modal-invite #inviteSearch').keyup(function(e){
			var search = $('#modal-invite #inviteSearch').val();
			mylog.log("#modal-invite #inviteSearch", search);
			if(search.length>2){
				clearTimeout(timeout);
				timeout = setTimeout('autoCompleteInvite("'+encodeURI(search)+'")', 500); 
			}else{
Raph El's avatar
Hotfix    
Raph El committed
485
486
				$("#modal-invite #dropdown-search-invite").hide();
				$("#modal-invite #form-invite").hide();
Raph El's avatar
Raph El committed
487
			}
Raphael's avatar
Raphael committed
488
		});
Raph El's avatar
Raph El committed
489
490

		$('#modal-invite #btnInviteNew').click(function(e){
Raph El's avatar
Raph El committed
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
			var form = $('#form-invite');
			var loginBtn = null;
			form.submit(function(e){ e.preventDefault() });

			var errorHandler = $('.errorHandler', form);

			form.validate({
				rules : {
					inviteEmail : {
						minlength : 2,
						required : true,
						email: true
					},
					inviteName : {
						minlength : 2,
						required : true,
					},
					inviteText : {
						maxlength : 500,
					}
				},
				submitHandler : function(form) {
					errorHandler.hide();
					var mail = $('#modal-invite #inviteEmail').val();
					var msg = $('#modal-invite #inviteText').val();
					var name = $('#modal-invite #inviteName').val();

					if(typeof listInvite.invites[mail] == "undefined"){
Raph El's avatar
Raph El committed
519
						var keyUnique = keyUniqueByMail(mail);
Raph El's avatar
Raph El committed
520
						listInvite.invites[keyUniqueByMail(mail)] = {
Raph El's avatar
Raph El committed
521
							name : name,
Raph El's avatar
Raph El committed
522
							mail : mail,
Raph El's avatar
Raph El committed
523
524
							msg : msg
						} ;
Raph El's avatar
Raph El committed
525
526
527
528

						if(parentType != "citoyens")
							listInvite.invites[keyUnique].isAdmin = "";

Raph El's avatar
Raph El committed
529
530
531
532
533
534
535
536
537
538
539
540
541
542
						$('#modal-invite #inviteEmail').val("");
						$('#modal-invite #inviteText').val("");
						$('#modal-invite #inviteName').val("");
						$("#modal-invite #form-invite").hide();
					} else {
						toastr.error(tradDynForm.alreadyInTheList);
					}

					showElementInvite(listInvite, true);
					bindRemove();
				} 
			});
			
			
Raph El's avatar
Hotfix    
Raph El committed
543
		});
Raph El's avatar
Raph El committed
544
545

		$('#modal-invite #btnValider').click(function(e){
Raph El's avatar
Raph El committed
546
			$('#modal-invite #btnValider').prop("disabled", true);
Raph El's avatar
Raph El committed
547
			mylog.log("#modal-invite #btnValider", Object.keys(listInvite.organizations).length, Object.keys(listInvite.citoyens).length);
Raph El's avatar
Hotfix    
Raph El committed
548
549
550
			if( Object.keys(listInvite.organizations).length > 0 || 
				Object.keys(listInvite.citoyens).length > 0 || 
				Object.keys(listInvite.invites).length > 0 ) {
Raph El's avatar
Raph El committed
551
				mylog.log("#modal-invite #btnValider");
Raph El's avatar
Raph El committed
552
553
				// $('#modal-invite #btnValider').prop("disabled", true);
				// $('#modal-invite #btnValider').html("<i class='fa fa-spin fa-circle-o-notch'></i> ");
Raph El's avatar
Modif    
Raph El committed
554

Raph El's avatar
Raph El committed
555
556
557
558
				// $( ".divRoles" ).each(function(key, value) {
				// 	mylog.log("divRoles", $(this).data("id"), $(this).data("type"));
				// 	listInvite[$(this).data("type")][$(this).data("id")]["roles"] = $("#tagsRoles"+$(this).data("id")).val().split(",");
				// });
Raph El's avatar
Modif    
Raph El committed
559

Raph El's avatar
Hotfix    
Raph El committed
560
561
562
563
564
565
566
567
568
569
570
571
				var params = {
					parentId : parentId,
					parentType : parentType,
					listInvite : listInvite
				};

				$.ajax({
					type: "POST",
					url: baseUrl+'/'+moduleId+"/link/multiconnect",
					data: params,
					dataType: "json",
					success: function(data){
Raph El's avatar
Raph El committed
572

Raph El's avatar
Hotfix    
Raph El committed
573

Clément Damiens's avatar
Clément Damiens committed
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
						if(parentType == "actions"){
							toastr.info(trad["processing"]);
							// var idProposal = $(this).data("id-action");
							// uiCoop.getCoopData(parentType, parentId, "action", null, idProposal, 
							// 	function(){
							// 		uiCoop.minimizeMenuRoom(true);
							// 		uiCoop.showAmendement(false);
							// 		toastr.success(trad["processing ok"]);
							// 	}, false);
							// $(".close-modal").trigger("click");
							// $(".load-data-community").trigger("click");
						} else {
							mylog.log("link/multiconnect success", data);
							var nbInvites = data.length;
							var str = "";
							if(typeof data.citoyens != "undefined"){
								$.each(data.citoyens, function(key, value){
									if(value.result){
										mylog.log("contactsList.invites key, value", key, value);
										var newElement=(typeof value.newElement != "undefined") ? value.newElement : value.parent;
										var newElementType = (typeof newElementType != "undefined") ? newElementType : "citoyens";
										var profilThumbImageUrl = (typeof newElement.profilThumbImageUrl != "undefined" && newElement.profilThumbImageUrl != "") ? baseUrl + newElement.profilThumbImageUrl : parentModuleUrl + "/images/thumb/default_"+newElementType+".png";		
										var bgThumb=(newElementType=="citoyens") ? "yellow" : "green";
										str += "<li class='li-dropdown-invite-results col-xs-12'>"+
												'<a href="#page.type.'+newElementType+'.id.'+newElement._id.$id+'" target="_blank" class="lbh col-xs-12">'+
													"<div class='success pull-left text-green'><i class='fa fa-check'></i></div>"+
													"<div class='btn-scroll-type pull-left col-xs-10' >"+
														'<img src="'+ profilThumbImageUrl+'" class="thumb-send-to col-xs-3 bg-'+bgThumb+' no-margin" height="35" width="35"> '+
													 	'<span class="text-dark text-bold margin-left-5">'+
															newElement.name + 
														'</span><br/>'+
														'<span class="text-dark text-bold margin-left-5 text-green msg-back">' + value.msg + '</span>'+
											 		"</div>"+
												'</a>'+
											"</li>";
									}
								});
							}

							if(typeof data.invites != "undefined"){
								$.each(data.invites, function(key, value){
									if(value.result){
										mylog.log("contactsList.invites key, value", key, value);
										var newElement=(typeof value.newElement != "undefined") ? value.newElement : value.parent;
										var newElementType = (typeof newElementType != "undefined") ? newElementType : "citoyens";
										var profilThumbImageUrl = (typeof newElement.profilThumbImageUrl != "undefined" && newElement.profilThumbImageUrl != "") ? baseUrl + newElement.profilThumbImageUrl : parentModuleUrl + "/images/thumb/default_"+newElementType+".png";		
										var bgThumb=(newElementType=="citoyens") ? "yellow" : "green";
										str += "<li class='li-dropdown-invite-results col-xs-12'>"+
												'<a href="#page.type.'+newElementType+'.id.'+newElement._id.$id+'" target="_blank" class="lbh col-xs-12">'+
													"<div class='success pull-left text-green'><i class='fa fa-check'></i></div>"+
													"<div class='btn-scroll-type pull-left col-xs-10' >"+
														'<img src="'+ profilThumbImageUrl+'" class="thumb-send-to col-xs-3 bg-'+bgThumb+' no-margin" height="35" width="35"> '+
														'<span class="text-dark text-bold margin-left-5">'+
															newElement.name +
														'</span><br/>'+
														'<span class="text-dark text-bold text-green margin-left-5 msg-back">'+
															'<i class="fa fa-arrow-right"></i> '+trad.invitationsenttojoinco+'</br>'+
															'<i class="fa fa-arrow-right"></i> '+value.msg +
														'</span>'+
													"</div>"+
												'</a>'+
											"</li>";
									}
																
								});
							}

							if(typeof data.organizations != "undefined"){
								$.each(data.organizations, function(key, value){
									if(value.result){
										mylog.log("contactsList.invites key, value", key, value);
										var profilThumbImageUrl = (typeof value.newElement.profilThumbImageUrl != "undefined" && value.newElement.profilThumbImageUrl != "") ? baseUrl + value.newElement.profilThumbImageUrl : parentModuleUrl + "/images/thumb/default_"+value.newElementType+".png";		
										var bgThumb=(value.newElementType=="citoyens") ? "yellow" : "green";	
										str += "<li class='li-dropdown-invite-results col-xs-12'>"+
												'<a href="#page.type.'+value.newElementType+'.id.'+value.newElement._id.$id+'" target="_blank" class="lbh col-xs-12">'+
													"<div class='success pull-left text-green'><i class='fa fa-check'></i></div>"+
													"<div class='btn-scroll-type pull-left col-xs-10' >"+
														'<img src="'+ profilThumbImageUrl+'" class="thumb-send-to col-xs-3 bg-'+bgThumb+' no-margin" height="35" width="35"> '+
														'<span class="text-dark text-bold margin-left-5">'+
														 	value.newElement.name + 
														'</span><br/>'+
														'<span class="text-dark text-bold text-green msg-back margin-left-5">' + value.msg + '</span>'+
													"</div>"+
												"</a>"+
											"</li>";
									}
								});
							}
							$('#modal-invite #btnValider').prop("disabled", false);
							$('#modal-invite #btnValider').html(tradDynForm.launchInvitations);
							initListInvite();
							fadeInView("result");
							$("#modal-invite #dropdown-result").html(str);
Raph El's avatar
Raph El committed
667
						}
Clément Damiens's avatar
Clément Damiens committed
668
669

						
Raph El's avatar
Hotfix    
Raph El committed
670
671
672
				 	}
				});
				
Raph El's avatar
Raph El committed
673
674
675
676
			}
		});
	}

Raph El's avatar
Raph El committed
677
678
	

Raph El's avatar
Raph El committed
679
680
	function showListInvite(){
		if(Object.keys(listInvite.organizations).length > 0 || Object.keys(listInvite.citoyens).length > 0|| Object.keys(listInvite.invites).length > 0 ){
Raph El's avatar
Raph El committed
681
			$("#modal-invite #step2").show();
Raph El's avatar
Raph El committed
682
		}else{
Raph El's avatar
Raph El committed
683
			$("#modal-invite #step2").hide();
Raph El's avatar
Raph El committed
684
		}
Raph El's avatar
Raph El committed
685
	}
Raphael's avatar
Raphael committed
686

Raph El's avatar
Raph El committed
687
688
689
690
691
	function bindRoles(){
		$('.tagsRoles').change(function(e) {
			var tag = $(this).val().split(",");
			var parent = $(this).parent() ;
			var id = parent.data("id");
Raph El's avatar
Raph El committed
692
			var type = parent.data("type-list");
Raph El's avatar
Raph El committed
693
			mylog.log("ID : ", id, type, tag);
Raph El's avatar
Raph El committed
694
695
			mylog.log("ID : ", listInvite[type]);
			mylog.log("ID : ", listInvite[type][id]);
Raph El's avatar
Raph El committed
696
697
			listInvite[type][id]["roles"] = tag;
		});
Raph El's avatar
Raph El committed
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713

		$(".btn-is-admin").click(function(){
			mylog.log(".btn-is-admin");
			var id = $(this).data("id");
			var type = $(this).data("type-list");
			mylog.log(".btn-is-admin : ", id, type);
			if($(this).hasClass("isAdmin")){
				$(this).removeClass("isAdmin");
				listInvite[type][id].isAdmin = "";
			}
			else{
				$(this).addClass("isAdmin");
				listInvite[type][id].isAdmin = "admin";
			}
			
		});
Raph El's avatar
Raph El committed
714
715
	}

Raph El's avatar
Raph El committed
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
	function inMyLinks(type,id){
		var inMyC = false ;
		if(parentType == "citoyens")
			inMyC = inMyContacts(type,id) ;
		else{
			var typeLink = "members";
			if(parentType == "events")
				typeLink = "attendees";
			else if(parentType == "projects")
				typeLink = "contributors";


			if(	notNull(parentLinks) && 
				notNull(parentLinks[typeLink]) && 
				notNull(parentLinks[typeLink][id]) && 
				notNull(parentLinks[typeLink][id].type) &&
				parentLinks[typeLink][id].type == type  )
				inMyC = true ;
		}

		return inMyC;
	}

Raph El's avatar
Raph El committed
739
740
	function bindAdd(){
		$('#modal-invite .add-invite').click(function(e){
Raph El's avatar
Raph El committed
741

Raph El's avatar
Raph El committed
742
743
744
			var id = $(this).data("id");
			var type = $(this).data("type");
			var name = $(this).data("name");
Raph El's avatar
Hotfix    
Raph El committed
745
			var profilThumbImageUrl = $(this).data("profilthumbimageurl");
Raph El's avatar
Raph El committed
746
			mylog.log(".add-invite", id, type, name, profilThumbImageUrl);
Raph El's avatar
Raph El committed
747

Raph El's avatar
Raph El committed
748
749
750
751
			var inMyC = inMyLinks(type,id);
			// if(parentType == "citoyens")
			// 	inMyC = inMyContacts(type,id) ;

Raph El's avatar
Raph El committed
752
753
754
755
756
757
758
759

			if(inMyC == false){
				if(type == "citoyens"){
					if(typeof listInvite.citoyens[id] == "undefined"){
						listInvite.citoyens[id] = { 
							name : name,
							profilThumbImageUrl : profilThumbImageUrl
						} ;
Raph El's avatar
Raph El committed
760
761
762
763

						if(parentType != "citoyens")
							listInvite.citoyens[id].isAdmin = "";

Raph El's avatar
Raph El committed
764
					}else{
Clément Damiens's avatar
Clément Damiens committed
765
						//tradMsg=(parentType!="citoyens") ? tradDynForm[alreadyInTheList+parentType] : tradDynForm[alreadyInTheList];
Raph El's avatar
Raph El committed
766
767
768
769
770
771
772
773
774
						toastr.error(tradDynForm.alreadyInTheList);
					}
				}else if(type == "organizations"){
					if(typeof listInvite.organizations[id] == "undefined"){
						listInvite.organizations[id] = { 
							name : name,
							profilThumbImageUrl : profilThumbImageUrl
						} ;
					}else{
Clément Damiens's avatar
Clément Damiens committed
775
						//tradMsg=(parentType!="citoyens") ? tradDynForm[alreadyInTheList+parentType] : tradDynForm[alreadyInTheList];
Raph El's avatar
Raph El committed
776
777
						toastr.error(tradDynForm.alreadyInTheList);
					}
Raph El's avatar
Raph El committed
778
				}
Raph El's avatar
Raph El committed
779
780
781
				showElementInvite(listInvite, true);
				bindRemove();
			}else{
Clément Damiens's avatar
Clément Damiens committed
782
783
				tradMsg=(parentType!="citoyens") ? tradDynForm["alreadyInTheList"+parentType] : tradDynForm.thisPersonIsAlreadyOnYourContacts;
				toastr.error(tradMsg);
Raph El's avatar
Raph El committed
784
			}
Raph El's avatar
Raph El committed
785
			
Raph El's avatar
Raph El committed
786
787
		});
	}
Raph El's avatar
Raph El committed
788

Raph El's avatar
Raph El committed
789
790
791
792
	function bindRemove(){
		$('#modal-invite .remove-invite').click(function(e){
			var id = $(this).data("id");
			var type = $(this).data("type");
Raph El's avatar
Hotfix    
Raph El committed
793
794

			mylog.log(".remove-invite", id , type);
Raph El's avatar
Raph El committed
795
796
797
798
799

			if(type == "citoyens"){

				if(typeof id != "undefined" && typeof listInvite.citoyens[id] != "undefined"){
					delete listInvite.citoyens[id] ;
Raph El's avatar
Hotfix    
Raph El committed
800
801
				}else if(typeof id != "undefined" && typeof listInvite.invites[id] != "undefined"){
					delete listInvite.invites[id] ;
Raph El's avatar
Raph El committed
802
803
804
805
806
807
808
809
810
				}
				
			}else if(type == "organizations"){
				if(typeof listInvite.organizations[id] != "undefined"){
					delete listInvite.organizations[id] ;
				}
			}
			showElementInvite(listInvite, true);
			bindRemove();
Raph El's avatar
Raph El committed
811
812
813
814
		});

	}

Raphael's avatar
Raphael committed
815

Raph El's avatar
Raph El committed
816
817
818
819
820
	function autoCompleteInvite(search){
		mylog.log("autoCompleteInvite", search);
		if (search.length < 3) { return }
		tabObject = [];

Raph El's avatar
Hotfix    
Raph El committed
821
		var searchMode = "personOnly";
Raph El's avatar
Hotfix    
Raph El committed
822
		if(parentType != "citoyens" && parentType != "person"){
Raph El's avatar
Hotfix    
Raph El committed
823
824
825
			searchMode = "mixte";
		}

Raph El's avatar
Raph El committed
826
827
		var data = { 
			"search" : search,
Raph El's avatar
Hotfix    
Raph El committed
828
			"searchMode" : searchMode
Raph El's avatar
Raph El committed
829
		};
Raph El's avatar
Hotfix    
Raph El committed
830

Raph El's avatar
Raph El committed
831
832
833
		mylog.log("url", baseUrl+'/'+moduleId+"/search/searchmemberautocomplete");
		$.ajax({
			type: "POST",
Raph El's avatar
Hotfix    
Raph El committed
834
835
836
837
838
839
840
841
			url: baseUrl+'/'+moduleId+"/search/searchmemberautocomplete",
			data: data,
			dataType: "json",
			success: function(data){
				mylog.log("autoCompleteInvite success", data);
				showElementInvite(data);
				bindAdd();
			}
Raph El's avatar
Raph El committed
842
		});
Raphael's avatar
Raphael committed
843
844
	}

Raph El's avatar
Raph El committed
845
	function showElementInvite(contactsList, invite=false, dropdown = "#dropdown-search-invite"){
Raph El's avatar
Raph El committed
846
		mylog.log("showElementInvite", contactsList, invite);
Raph El's avatar
Raph El committed
847
		mylog.log("showElementInvite length", Object.keys(contactsList.citoyens).length);
Raph El's avatar
Raph El committed
848
		//var dropdown = "#dropdown-search-invite";
Raph El's avatar
Raph El committed
849
		var listNotExits = true;
Raph El's avatar
Raph El committed
850
		var addRoles = {};
851
		var searchInContactsList=(dropdown=="#dropdown-mycontacts-invite") ? true : false;
Clément Damiens's avatar
Clément Damiens committed
852
		var str = "";
Raph El's avatar
Raph El committed
853
854
		if(invite == true){
			dropdown = "#dropdown-invite";
855
		}else if(!searchInContactsList){
Clément Damiens's avatar
Clément Damiens committed
856
			var str = "<div class='col-xs-12 no-padding'><div class='btn-scroll-type col-xs-12 not-find-inside padding-20'><a href='javascript:;' onclick='newInvitation()' class='col-xs-12 text-center'>"+trad.notfoundlaunchinvite+" !</a></div></div>";
Raph El's avatar
Raph El committed
857
		}
Raph El's avatar
Raph El committed
858
		if(notNull(contactsList.citoyens) && Object.keys(contactsList.citoyens).length ){
859
			str += '<div class="col-xs-12 no-padding">'+
Raph El's avatar
Hotfix    
Raph El committed
860
						'<h5 class="padding-10 text-'+contactTypes.citoyens.color+'"><i class="fa fa-'+contactTypes.citoyens.icon+'"></i> '+contactTypes.citoyens.label+'<hr></h5>'+			
Raph El's avatar
Raph El committed
861
					'</div>';
Raph El's avatar
Raph El committed
862
			$.each(contactsList.citoyens, function(key, value){
Raph El's avatar
Hotfix    
Raph El committed
863
				mylog.log("contactsList.citoyens key, value", key, value);
864
				str += htmlListInvite(key, value, invite, "citoyens", invite, searchInContactsList);
Raph El's avatar
Raph El committed
865
866
867
868
869
870

				if(typeof value.roles != "undefined" || typeof value.roles == null){
					var tagRolesList = [] ;
					$.each(value.roles, function(i,k) { tagRolesList.push( {id:k,text:k} ); });
					addRoles[key] = tagRolesList;
				}
Raph El's avatar
Raph El committed
871
			});
Raph El's avatar
Raph El committed
872

Raph El's avatar
Raph El committed
873
			listNotExits = false;
Raph El's avatar
Raph El committed
874
		}
Raph El's avatar
Raph El committed
875
876
877

		if(notNull(contactsList.invites) && Object.keys(contactsList.invites).length ){
			$.each(contactsList.invites, function(key, value){
Raph El's avatar
Hotfix    
Raph El committed
878
				mylog.log("contactsList.invites key, value", key, value);
879
				str += htmlListInvite(key, value, invite, "invites", searchInContactsList);
Raph El's avatar
Raph El committed
880
881
882
883
884
885

				if(typeof value.roles != "undefined" || typeof value.roles == null){
					var tagRolesList = [] ;
					$.each(value.roles, function(i,k) { tagRolesList.push( {id:k,text:k} ); });
					addRoles[key] = tagRolesList;
				}
Raph El's avatar
Hotfix    
Raph El committed
886
887
888
889
890
			});
			listNotExits = false;
		}

		if(notNull(contactsList.organizations) && Object.keys(contactsList.organizations).length ){
891
			str += '<div class="col-xs-12 no-padding">'+
Raph El's avatar
Hotfix    
Raph El committed
892
						'<h5 class="padding-10 text-'+contactTypes.organizations.color+'"><i class="fa fa-'+contactTypes.organizations.icon+'"></i> '+contactTypes.organizations.label+'<hr></h5>'+			
Raph El's avatar
Raph El committed
893
					'</div>';
Raph El's avatar
Hotfix    
Raph El committed
894
895
			$.each(contactsList.organizations, function(key, value){
				mylog.log("contactsList.organizations key, value", key, value);
896
				str += htmlListInvite(key, value, invite, "organizations", searchInContactsList);
Raph El's avatar
Raph El committed
897
898
899
900
901
902

				if(typeof value.roles != "undefined" || typeof value.roles == null){
					var tagRolesList = [] ;
					$.each(value.roles, function(i,k) { tagRolesList.push( {id:k,text:k} ); });
					addRoles[key] = tagRolesList;
				}
Raph El's avatar
Raph El committed
903
904
905
			});
			listNotExits = false;
		}
Raph El's avatar
Hotfix    
Raph El committed
906
907

		mylog.log("showElementInvite", dropdown);
Raph El's avatar
Raph El committed
908
		$("#modal-invite "+dropdown).html(str);
Raph El's avatar
Raph El committed
909

Raph El's avatar
Raph El committed
910
		$('#modal-invite .tagsRoles').select2({tags:rolesList});
Raph El's avatar
Raph El committed
911
912
913
914
915
916
917
918
919
920
921

		mylog.log("addRoles", addRoles);
		$.each(addRoles, function(key, value){
			$('#tagsRoles'+key).select2("data",value);
		});
		
		bindRoles();

		$("#modal-invite "+dropdown).show();


Raph El's avatar
Raph El committed
922
923
		if(listNotExits)
			newInvitation();
Raph El's avatar
Hotfix    
Raph El committed
924
925
926
		else
			$("#modal-invite #form-invite").hide();

Raph El's avatar
Raph El committed
927
		showListInvite();
Raphael's avatar
Raphael committed
928
929
	}

930
	function htmlListInvite(id, elem, invite, type, searchInContactsList){
Raph El's avatar
Hotfix    
Raph El committed
931
		//( typeof elem.id != "undefined" ? elem.id : elem.email )
932
		mylog.log("htmlListInvite", id, elem, invite, type, searchInContactsList);
Raph El's avatar
Raph El committed
933
934
935
		var typeList = type ;
		if(type ==  "invites" )
			type = "citoyens";
936
		var inMyContact = (!searchInContactsList) ? inMyContacts(type,id) : false;
Raph El's avatar
Hotfix    
Raph El committed
937
		var profilThumbImageUrl = (typeof elem.profilThumbImageUrl != "undefined" && elem.profilThumbImageUrl != "") ?  elem.profilThumbImageUrl : parentModuleUrl + "/images/thumb/default_"+type+".png";		
938
939
		var str = "<div class='col-xs-12 listInviteElement no-padding'>";
			var classStr = "col-xs-10";
Raph El's avatar
Raph El committed
940
			if(invite == true){
941
				str+='<div class="col-xs-2"><button class="btn bg-red btn-link text-red tooltips pull-left remove-invite" '+
Raph El's avatar
Hotfix    
Raph El committed
942
943
						'id="'+id+'Remove" '+
						'name="'+id+'Remove" '+
Raph El's avatar
Raph El committed
944
						'data-toggle="tooltip" data-placement="top" '+
Raph El's avatar
Raph El committed
945
						'data-type="'+type+'" ' +
Raph El's avatar
Raph El committed
946
						'data-type-list="'+typeList+'" ' +
Raph El's avatar
Hotfix    
Raph El committed
947
						'data-id="'+id+'" ' + 
Clément Damiens's avatar
Clément Damiens committed
948
						'data-toggle="tooltip" data-placement="bottom" title="'+trad.clear+'" >'+
Raph El's avatar
Raph El committed
949
						'<i class="fa fa-remove"></i>'+
950
						'</button></div>';
Raph El's avatar
Modif    
Raph El committed
951
			} else {
952
				classStr = "col-xs-12 add-invite";
Raph El's avatar
Raph El committed
953
			}
Raphael's avatar
Raphael committed
954

Raph El's avatar
Raph El committed
955
			str +="<div class='btn-scroll-type "+classStr+"'"+
Raph El's avatar
Hotfix    
Raph El committed
956
957
958
					" data-id='"+id+"' "+
					'id="'+id+'AddList" '+
					'name="'+id+'AddList"'+
Raph El's avatar
Raph El committed
959
960
					" data-name='"+elem.name+"' "+
					" data-profilThumbImageUrl='"+profilThumbImageUrl+"' "+
Raph El's avatar
Raph El committed
961
					'data-type-list="'+typeList+'" ' +
Raph El's avatar
Raph El committed
962
					" data-type='"+type+"' >";
963
				bgThumb=(type=="citoyens") ? "yellow" : "green";
Raph El's avatar
Hotfix    
Raph El committed
964
					str += '<img src="'+ baseUrl + profilThumbImageUrl+'" class="thumb-send-to col-xs-3 bg-'+bgThumb+'" height="35" width="35"> ';
Clément Damiens's avatar
Clément Damiens committed
965
				/*else {
Raph El's avatar
Raph El committed
966
967
968
969
					if(type == "citoyens")
						str += '<i class="fa fa-user "></i> ';
					else if(type == "organizations")
						str += '<i class="fa fa-users "></i> ';
Clément Damiens's avatar
Clément Damiens committed
970
971
972
				}*/
				marginName= (!inMyContact) ? "margin-top-15" : "";
				str += '<span class="text-dark text-bold name-invite col-xs-9 elipsis '+marginName+'">' + elem.name ; 
Raph El's avatar
Raph El committed
973
974
975
976
977
978
979
				mylog.log("mailalal", typeList, elem.mail, (typeList == "invites" && typeof elem.mail != "undefined"));
				if(typeList == "invites" && typeof elem.mail != "undefined"){
					mylog.log("mailalal", typeList, elem.mail);
					str += ' <'+ elem.mail +'> </span>';
				}
				str += '</span>';

Clément Damiens's avatar
Clément Damiens committed
980
				if(inMyContact == true && parentType=="citoyens")
981
982
					str += ' <span class="text-bold col-xs-9 follows tooltips"> '+
								'<i class="fa fa-link" data-toggle="tooltip" data-placement="top" title="'+trad.follows+'" alt="" data-original-title="'+trad.follows+'"></i> In my contacts'+
Raph El's avatar
Raph El committed
983
							'</span>';
Raph El's avatar
Raph El committed
984

Raph El's avatar
Modif    
Raph El committed
985
				if (invite == true && parentType != "citoyens" && type == "citoyens" && parentType != "proposals") {
Raph El's avatar
Raph El committed
986
987

					var isAdmin = ( (typeof elem.isAdmin != "undefined" && elem.isAdmin == "admin") ? "isAdmin" : "" );
988
					str += '<small id="isAdmin'+id+'" class="btn-is-admin pull-right text-grey margin-top-20 '+isAdmin+'" data-id="'+id+'" data-type="'+type+'" data-type-list="'+typeList+'" >'+
Raph El's avatar
Raph El committed
989
990
991
								'<a href="javascript:">admin <i class="fa fa-user-secret"></i></a>'+
							'</small>';
				}
Raph El's avatar
Raph El committed
992
				
Raph El's avatar
Modif    
Raph El committed
993
				if(invite == true && parentType != "citoyens" && parentType != "proposals"){
Raph El's avatar
Raph El committed
994
					str += '<div class="divRoles col-md-12 col-sm-12 col-xs-12" data-id="'+id+'" data-type="'+type+'" data-type-list="'+typeList+'" >'+
Clément Damiens's avatar
Clément Damiens committed
995
								'<input id="tagsRoles'+id+'" class="tagsRoles" type="text" data-type="select2" name="roles" placeholder="'+tradDynForm.addroles+'" style="width:100%;">'+
Raph El's avatar
Modif    
Raph El committed
996
997
							'</div>';	
				}
Raph El's avatar
Raph El committed
998
			str += "</div>";
Raph El's avatar
Raph El committed
999
		str += "</div>";
Raph El's avatar
Raph El committed
1000
		return str ;