~saviq/unity8/build-arm64

« back to all changes in this revision

Viewing changes to plugins/Dash/CardCreator.js

  • Committer: CI Train Bot
  • Author(s): Andrea Cimitan
  • Date: 2016-05-04 18:08:28 UTC
  • mfrom: (2103.6.33 card-social)
  • Revision ID: ci-train-bot@canonical.com-20160504180828-aetx14xx5yy600eg
Add social actions to cards
Approved by: Josh Arenson

Show diffs side-by-side

added added

removed removed

Lines of Context:
351
351
                            model: cardData && cardData["attributes"]; \n\
352
352
                          }\n';
353
353
 
 
354
// %1 is used as anchors of socialActionsRow
 
355
// %2 is used as color of socialActionsRow
 
356
var kSocialActionsRowCode = 'CardSocialActions { \n\
 
357
                               id: socialActionsRow; \n\
 
358
                               objectName: "socialActionsRow"; \n\
 
359
                               anchors { %1 } \n\
 
360
                               color: %2; \n\
 
361
                               model: cardData && cardData["socialActions"]; \n\
 
362
                               onClicked: root.action(actionId); \n\
 
363
                             }\n';
 
364
 
354
365
// %1 is used as top anchor of summary
355
366
// %2 is used as topMargin anchor of summary
356
367
// %3 is used as color of summary
437
448
    var hasSubtitle = hasTitle && components["subtitle"] || false;
438
449
    var hasHeaderRow = hasMascot && hasTitle;
439
450
    var hasAttributes = hasTitle && components["attributes"] && components["attributes"]["field"] || false;
 
451
    var hasSocialActions = hasTitle && components["social-actions"] || false;
440
452
    var isAudio = template["quick-preview-type"] === "audio";
441
453
    var asynchronous = isCardTool ? "false" : "true";
442
454
 
 
455
    code += 'signal action(var actionId);\n';
443
456
    if (isAudio) {
444
457
        // For now we only support audio cards with [optional] art, title, subtitle
445
458
        // in horizontal mode
841
854
        code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(summaryColor);
842
855
    }
843
856
 
 
857
    if (hasSocialActions) {
 
858
        var socialAnchors;
 
859
        var socialTopAnchor;
 
860
 
 
861
        if (hasSummary) socialTopAnchor = 'summary.bottom;';
 
862
        else if (isHorizontal && hasArt) socialTopAnchor = 'artShapeHolder.bottom;';
 
863
        else if (headerAsOverlay && hasArt) socialTopAnchor = 'artShapeHolder.bottom;';
 
864
        else if (hasHeaderRow) socialTopAnchor = 'row.bottom;';
 
865
        else if (hasTitleContainer) socialTopAnchor = 'headerTitleContainer.bottom;';
 
866
        else if (hasMascot) socialTopAnchor = 'mascotImage.bottom;';
 
867
        else if (hasAttributes) socialTopAnchor = 'attributesRow.bottom;';
 
868
        else if (hasSubtitle) socialTopAnchor = 'subtitleLabel.bottom;';
 
869
        else if (hasTitle) socialTopAnchor = 'titleLabel.bottom;';
 
870
        else if (hasArt) socialTopAnchor = 'artShapeHolder.bottom;';
 
871
        else socialTopAnchor = 'parent.top';
 
872
 
 
873
        socialAnchors = 'top: ' + socialTopAnchor + ' left: parent.left; right: parent.right; topMargin: units.gu(1);'
 
874
 
 
875
        var socialColor;
 
876
        if (hasBackground) {
 
877
            socialColor = summaryColorWithBackground;
 
878
        } else {
 
879
            socialColor = 'root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText';
 
880
        }
 
881
 
 
882
        code += kSocialActionsRowCode.arg(socialAnchors).arg(socialColor);
 
883
    }
 
884
 
844
885
    var touchdownAnchors;
845
886
    if (hasBackground) {
846
887
        touchdownAnchors = 'fill: backgroundLoader';
852
893
    code += kTouchdownCode.arg(touchdownAnchors);
853
894
 
854
895
    var implicitHeight = 'implicitHeight: ';
855
 
    if (hasSummary) {
 
896
    if (hasSocialActions) {
 
897
        implicitHeight += 'socialActionsRow.y + socialActionsRow.height + units.gu(1);\n';
 
898
    } else if (hasSummary) {
856
899
        implicitHeight += 'summary.y + summary.height + units.gu(1);\n';
857
900
    } else if (isAudio) {
858
901
        implicitHeight += 'audioButton.height;\n';