angular.module('app.directives').directive('editableLink', editableLink);

function editableLink() {
    return {
        restrict: 'E',
        scope: {
            viewModel: '=',
            type: '@',
            field: '@',
            object: '=?',
            socialMediaName: '@?',
        },
        templateUrl: 'base/directives/editable_link.html',
        controller: EditableLinkController,
        controllerAs: 'el',
        transclude: true,
        bindToController: true,
    };
}

EditableLinkController.$inject = [];
function EditableLinkController() {
    var el = this;

    el.updateViewModel = updateViewModel;

    activate();

    /////

    function activate() {
        if (!el.object) {
            if (!el.socialMediaName) {
                el.object = el.viewModel[el.type.toLowerCase()];
            }
        }
    }

    function updateViewModel($data) {
        var patchPromise;

        var args = {};

        if (el.object) {
            args = {
                id: el.object.id,
            };
        }

        args[el.field] = $data;

        if (el.socialMediaName) {
            args.name = el.socialMediaName;
            patchPromise = el.viewModel.updateModel(args, el.socialMediaName);
        } else {
            patchPromise = el.viewModel.updateModel(args).$promise;
        }

        return patchPromise;
    }
}

@@ -1098,32 +1098,61 @@
 ialMediaName) %7B%0A
+            if ($data) %7B%0A    
             args
@@ -1179,16 +1179,92 @@
 iaName;%0A
+            %7D else %7B%0A                args.is_deleted = true;%0A            %7D%0A%0A
         

Allow clearing of social media fields with inline editing