@@ -223,91 +223,89 @@ <h2>
223223 < p > Activities must contain at one supporting child link; you can enter additional links after the initial record is created on the edit screen.</ p >
224224 </ div >
225225
226- < div class ="item ">
227- < div class ="item_name ">
228- < paper-dropdown-menu
229- selected-item-label ="{{detail.detail_type}} "
230- label ="Link source "
231- on-iron-select ="_activityLinkSelected ">
232- < paper-listbox
233- selected ="{{initial_detail_type}} "
234- class ="dropdown-content ">
235- < template is ="dom-repeat " items ="{{activityLinks}} " as ="link ">
236- < paper-item
237- data-link ="{{link}} "
238- label ="{{link.label}} ">
239- {{link.label}}
240- </ paper-item >
241- </ template >
242- </ paper-listbox >
243- </ paper-dropdown-menu >
244- </ div >
245- </ div >
246-
247-
248- < template is ="dom-if " if ="{{_chosenActivityLink}} ">
249- < div class ="item ">
250- < paper-input
251- auto-validate
252- pattern ="https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*) "
253- error-message ="Must be a valid URL. "
254- name ="url "
255- id ="inputUrl "
256- label ="URL "
257- type ="text "
258- value ="{{detail.url}} "
259- invalid ="{{_urlInvalid}} "
260- required > </ paper-input >
261- </ div >
262- < div class ="item ">
263- < div class ="item_name "> Activity metrics</ div >
264- < template is ="dom-if " if ="{{_chosenActivityLink.metrics.direct}} ">
265- < div class ="item_value metric ">
266- < paper-input
267- id ="metric_reached "
268- type ="number "
269- label ="How many people directly reached? "
270- value ="{{ detail.metric_reached }} "
271- min ="0 ">
272- </ paper-input >
273- </ div >
274- </ template >
275- < template is ="dom-if " if ="{{_chosenActivityLink.metrics.trained}} ">
276- < div class ="item_value metric ">
277- < paper-input
278- id ="metric_reached "
279- type ="number "
280- label ="How many people trained? "
281- value ="{{ detail.metric_trained }} "
282- min ="0 ">
283- </ paper-input >
284- </ div >
285- </ template >
286- < template is ="dom-if " if ="{{_chosenActivityLink.metrics.indirect}} ">
287- < div class ="item_value metric ">
288- < paper-input
289- id ="metric_reached "
290- type ="number "
291- label ="How many people indirectly reached? "
292- value ="{{ detail.metric_indirect }} "
293- min ="0 ">
294- </ paper-input >
295- </ div >
296- </ template >
226+ < div class ="item ">
227+ < div class ="item_name ">
228+ < paper-dropdown-menu
229+ selected-item-label ="{{detail.detail_type}} "
230+ label ="Link source "
231+ on-iron-select ="_activityLinkSelected ">
232+ < paper-listbox
233+ selected ="{{initial_detail_type}} "
234+ class ="dropdown-content ">
235+ < template is ="dom-repeat " items ="{{activityLinks}} " as ="link ">
236+ < paper-item
237+ data-link ="{{link}} "
238+ label ="{{link.label}} ">
239+ {{link.label}}
240+ </ paper-item >
241+ </ template >
242+ </ paper-listbox >
243+ </ paper-dropdown-menu >
244+ </ div >
245+ </ div >
246+
247+ < div hidden$ ="{{!_activateMetrics}} ">
248+ < div class ="item ">
249+ < paper-input
250+ auto-validate
251+ pattern ="https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*) "
252+ error-message ="Must be a valid URL. "
253+ name ="url "
254+ id ="inputUrl "
255+ label ="URL "
256+ type ="text "
257+ value ="{{detail.url}} "
258+ invalid ="{{_urlInvalid}} "
259+ required > </ paper-input >
260+ </ div >
261+ < div class ="item ">
262+ < div class ="item_name "> Activity metrics</ div >
263+ < template is ="dom-if " if ="{{_chosenActivityLink.metrics.direct}} ">
264+ < div class ="item_value metric ">
265+ < paper-input
266+ id ="metric_reached "
267+ type ="number "
268+ label ="How many people directly reached? "
269+ value ="{{ detail.metric_reached }} "
270+ min ="0 ">
271+ </ paper-input >
297272 </ div >
298273 </ template >
299-
274+ < template is ="dom-if " if ="{{_chosenActivityLink.metrics.trained}} ">
275+ < div class ="item_value metric ">
276+ < paper-input
277+ id ="metric_reached "
278+ type ="number "
279+ label ="How many people trained? "
280+ value ="{{ detail.metric_trained }} "
281+ min ="0 ">
282+ </ paper-input >
283+ </ div >
284+ </ template >
285+ < template is ="dom-if " if ="{{_chosenActivityLink.metrics.indirect}} ">
286+ < div class ="item_value metric ">
287+ < paper-input
288+ id ="metric_reached "
289+ type ="number "
290+ label ="How many people indirectly reached? "
291+ value ="{{ detail.metric_indirect }} "
292+ min ="0 ">
293+ </ paper-input >
294+ </ div >
295+ </ template >
296+ </ div >
297+ </ div >
300298 < div class ="item ">
301299 < div class ="item_value submit ">
302300 < paper-button
303301 id ="submit "
304302 on-tap ="_submitActivityDetail "
305- disabled$ ="{{_submitDisabled}} "
303+ disabled$ ="{{! _submitDisabled}} "
306304 raised >
307305 Save
308306 </ paper-button >
309307 </ div >
310- </ div >
308+ </ div >
311309 </ div >
312310
313311 < iron-ajax
@@ -365,13 +363,17 @@ <h2>
365363
366364 _submitDisabled : {
367365 type : Boolean ,
368- computed : "_isSubmitDisabled(_urlInvalid, _typeInvalid )"
366+ computed : "_isSubmitDisabled(detail.* )"
369367 } ,
370368
371369 _typeInvalid : {
372370 type : Boolean ,
373371 computed : "_isTypeInvalid(detail.detail_type)"
374- } ,
372+ } ,
373+ _activateMetrics : {
374+ type : Boolean ,
375+ value : false
376+ } ,
375377 } ,
376378
377379 behaviors : [
@@ -382,75 +384,12 @@ <h2>
382384 } ,
383385
384386 _isTypeInvalid : function ( ) {
385- console . debug ( "[experts-activity-detail-create] _isTypeInvalid" , this . detail . detail_type )
386- return ( ! this . detail . detail_type ) ;
387+
387388 } ,
388389 _isSubmitDisabled : function ( ) {
389- console . debug ( "[experts-activity-detail-create] _isSubmitDisabled" , { typeInvalid : this . _typeInvalid , urlInvalid : this . _urlInvalid } ) ;
390- return ( this . _typeInvalid || this . _urlInvalid ) ;
391- } ,
392-
393- _selectActivityGroup : function ( e ) {
394-
395- console . debug ( "[experts-activity-detail-create] _selectActivityGroup " , this . activityGroups ) ;
396-
397- var _activityTypes = [ ] ;
398- if ( ! this . detail . detail_type ) {
399- this . detail . detail_type = "" ;
400- } else {
401- var type = {
402- tag : this . detail . detail_type ,
403- selected : "selected"
404- } ;
405- _activityTypes . push ( type ) ;
406- }
407- for ( var i in this . activityGroups ) {
408- if ( this . activityGroups [ i ] . active ) {
409- for ( var j in this . activityGroups [ i ] . types ) {
410- var already = false ;
411- for ( var k in _activityTypes ) {
412- if ( _activityTypes [ k ] . tag == this . activityGroups [ i ] . types [ j ] ) {
413- already = true ;
414- break ;
415- }
416- }
417- if ( ! already ) {
418- var type = {
419- tag : this . activityGroups [ i ] . types [ j ] ,
420- selected : ""
421- } ;
422- _activityTypes . push ( type ) ;
423- }
424- }
425- }
426- }
427- this . _activityTypes = _activityTypes . sort ( function ( a , b ) {
428- return + ( a . tag > b . tag ) || + ( a . tag === b . tag ) - 1 ;
429- } ) ;
430- console . debug ( "[experts-activity-detail-create] selectActivityGroup - _activityTypes" , this . _activityTypes ) ;
431- } ,
432-
433- _selectActivityType : function ( e ) {
434-
435- var tag = e . model . type . tag ;
436-
437- console . debug ( "[experts-activity-detail-create] selectActivityType" , tag ) ;
438-
439-
440- for ( var i in this . _activityTypes ) {
441- if ( this . _activityTypes [ i ] . tag == tag ) {
442- this . set ( [ '_activityTypes' , i , 'selected' ] , "selected" ) ;
443- }
444- if ( this . _activityTypes [ i ] . selected && this . _activityTypes [ i ] . tag != tag ) {
445- console . debug ( "Let's delete " , this . _activityTypes [ i ] )
446- this . set ( [ '_activityTypes' , i , 'selected' ] , "" ) ;
447- }
448- }
449- console . debug ( "[experts-activity-detail-create] _activityTypes" , this . _activityTypes ) ;
450-
451- this . set ( "detail.detail_type" , tag ) ;
452-
453- console . debug ( "[experts-activity-detail-create] selectActivityType - selected activity type" , this . detail . detail_type ) ;
390+ console . log ( this . detail . detail_type && this . $ . inputUrl . validate ( ) && ( this . detail . metric_reached > 0 || this . detail . metric_indirect > 0 || this . detail . metric_trained > 0 ) ) ;
391+ console . log ( this . detail . detail_type , this . $ . inputUrl . validate ( ) , ( this . detail . metric_reached > 0 || this . detail . metric_indirect > 0 || this . detail . metric_trained > 0 ) ) ;
392+ return ( this . detail . detail_type && this . $ . inputUrl . validate ( ) && ( this . detail . metric_reached > 0 || this . detail . metric_indirect > 0 || this . detail . metric_trained > 0 ) ) ;
454393 } ,
455394 _initNewActivityDetailIfNeeded : function ( ) {
456395 if ( ! this . detail . url ) {
514453 _activityLinkSelected : function ( evt , obj ) {
515454 console . debug ( "[experts-activity-create] _activityLinkSelected" , obj . item . dataLink ) ;
516455 this . _chosenActivityLink = obj . item . dataLink ;
456+ this . _activateMetrics = true ;
517457 } ,
518458
519459 } ) ;
0 commit comments