在ButtonClick之后显示更新的数据

时间:2015-08-24 05:55:25

标签: jquery html angularjs refresh

我是这项技术的新手,我正面临一个小问题。我正在将日期更新到数据库并显示一条消息,例如"已成功发布"点击按钮但我想要更新日期。 我尝试添加刷新代码,但之后不会显示消息,因为它会立即触发刷新。

HTML CODE:

<div class="row" ng-controller="PublishManifestCtrl">
<div class="col-xs-12 col-md-12">
    <div class="widget">
        <div class="widget-header bordered-bottom bordered-themeprimary">
            <i class="widget-icon fa fa-tasks themeprimary"></i>
            <span class="widget-caption themeprimary">Manifest Status</span>
        </div>
        <div class="widget-body">
            <form class="form-bordered" role="form">
                <div class="form-group">
                    <label style="padding-left: 8px;">Manifest was last published to agents on <b>{{manifeststatus.manifestLastPublishedDate}}</b>.</label>
                </div>
                <div class="form-group">
                    <label style="padding-left: 8px;">Manifest was last updated by <b> {{manifeststatus.lastUpdatedByUser}} </b> on <b>{{manifeststatus.manifestLastedUpdatedDate}}</b>.</label>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-1">
                        <button id="PublishButton" class="btn btn-default shiny " ng-disabled="manifeststatus.enablePublishButton" ng-click="Save()">Publish</button>
                    </div>    
                </div>

                <div id="statusDivPublish"  ng-show="showstatus" >
                        <alert  type="{{alert.type}}">{{alert.msg}}</alert>
                </div>
            </form>
        </div>
     </div>
</div>

代码:

app.controller('PublishManifestCtrl', function ($scope, $rootScope,          $http,$state,$stateParams) {
$scope.showstatus = false;

$http({
    url: $rootScope.WebApiURL + '/getmanifeststatus',
    params: { 'foobar': new Date().getTime() }
}).
success(function (data, status, headers, config) {
    var options = { year: "numeric", month: "long", day: "numeric", hour: "numeric", minute: "numeric" };

    data.manifestLastedUpdatedDate = (new Date(data.lastUpdatedDateTime)).toLocaleDateString('en-US', options);
    data.manifestLastPublishedDate = (new Date(data.lastPublishDateTime)).toLocaleDateString('en-US', options);
    var date1 = new Date(data.lastUpdatedDateTime);
    var date2 = new Date(data.lastPublishDateTime);
    data.enablePublishButton = date2.getTime() > date1.getTime();

    $scope.manifeststatus = data;

}).
error(function (data, status, headers, config) {
    alert('error' + status);
    // log error
});
$scope.Save = function () {
    $http.post($rootScope.WebApiURL + '/updatemanifeststatus');

    //refresh
    $state.transitionTo($state.current, $stateParams, {
        reload: true,
        inherit: false,
        notify: true
   });

    //to show Publish message
    $scope.showstatus = true;
    $scope.alert = { type: 'success', msg: 'Published Successfully.' };
    $(".statusDivPublish").show();

      }});

Before Clicking Publish Button

After Clicking The Button

The date get refreshed after Refreshing the page

0 个答案:

没有答案