//----------------------------------------------------------------------------------------
// GetLockStatusStrings
//----------------------------------------------------------------------------------------
void
CZPAMLockable::GetLockStatusStrings(
	std::map<int32, PMString> & stringTable)
{
	LogFunctionEnterExit;
	
	if ( !fCheckedOutBy.IsEmpty() )
	{
		fCheckedOutBy.SetTranslatable( kFalse );
		stringTable.insert( std::pair<int32, PMString>( IManagedStatus::enCheckedOutBy, fCheckedOutBy ) );
	}
	
	if ( !fCheckedOutDoc.IsEmpty() )
	{
		fCheckedOutDoc.SetTranslatable( kFalse );
		stringTable.insert( std::pair<int32, PMString>( IManagedStatus::enCheckedOutDoc, fCheckedOutDoc ) );
	}
	
	if ( !fCheckedOutApp.IsEmpty() )
	{
		fCheckedOutApp.SetTranslatable( kFalse );
		stringTable.insert( std::pair<int32, PMString>( IManagedStatus::enCheckedOutApp, fCheckedOutApp ) );
	}
	
	if ( !fLockOwnerName.IsEmpty() )
		stringTable.insert( std::pair<int32, PMString>( IManagedStatus::enLockOwner, fLockOwnerName ) );
	
	if ( !fCurrentUserName.IsEmpty() )
		stringTable.insert( std::pair<int32, PMString>( IManagedStatus::enCurrentUser, fCurrentUserName ) );
	
	if ( !fCurrentUserName.IsEmpty() )
		stringTable.insert( std::pair<int32, PMString>( IManagedStatus::enCurrentClient, fCurrentUserName ) );
}
//----------------------------------------------------------------------------------------
// AddUpdatedAssetId
//----------------------------------------------------------------------------------------
void
AZPAMAssetMonitor::AddUpdatedAssetId(
	const PMString &			inAssetID)
{
	LogFunctionEnterExit;
	if (!inAssetID.IsEmpty())
	{
		K2Vector<PMString>::iterator iter = std::find( mPendingAssetToUpdate.begin(), mPendingAssetToUpdate.end(), inAssetID );
		if( iter == mPendingAssetToUpdate.end() )
		{
			IZPLog_Str_( thisFileLA, enLT_DebugInfo, "Adding asset id : %s in pending update list", inAssetID.GrabCString());
			mPendingAssetToUpdate.push_back(inAssetID);
		}
	}
}
//----------------------------------------------------------------------------------------
// DoPanelRefresh
//----------------------------------------------------------------------------------------
void
CZPAssetsPanelObserver::DoPanelRefresh()
{
	//Refresh only the assets list for now.
	//Someday: refresh the edition list and title list as well.
	const PMString theEditionID = this->GetSelectedEditionID();

	if( theEditionID.IsEmpty() )
		return;	//Should we clear the tree here?
	const IStringData * editionID = ZPDataHelper::GetEditionByID( theEditionID );

	if( !editionID )
		return;	//Should we clear the tree here?
	InterfacePtr<IZPDBObjController> editionController( editionID, UseDefaultIID() );
	ASSERT( editionController );
	editionController->RequestUpdateFromServer( IZPAssetList::kDefaultIID );
}
//----------------------------------------------------------------------------------------
// Do
//----------------------------------------------------------------------------------------
ErrorCode
CZPAMUISaveAlertService::Do(
	IManageableAsset * pAsset)
{
	LogFunctionEnterExit;

	InterfacePtr<IAMServiceData> iamdata(this, UseDefaultIID());
	ASSERT(iamdata);
	
	const enAMUIServiceType serviceType = this->GetServiceType();

	bool canCheckIn = this->CallVerifyService( pAsset, IAMServiceProvider::enCheckIn );

	PMString name;
	iamdata->Get(IAMUIService::enDocumentName, name);
	
	const IStringData *	dbAsset = nil;
	if( serviceType == eAMUIServiceType_LinkedStory )
		dbAsset = this->GetDBAsset_FromIDStory( pAsset );
	else if( serviceType == eAMUIServiceType_Document )
		dbAsset = this->GetDBAsset_FromDoc( pAsset );
	else
		dbAsset = nil;

	if( name.IsEmpty() && dbAsset )
	{
		InterfacePtr<const IStringData> dbAssetName( dbAsset, IID_IZPDATANAME );
		if( dbAssetName )
			name = dbAssetName->Get();
	}

	PMString message(kIZPSaveAlertKey);
	message.Translate();
	
	StringUtils::ReplaceStringParameters(&message, name);
	
	IDataBase * db = ::GetDataBase( pAsset );
	bool isInCopy = Utils<IZPInDnUtils>()->IsHostAppInCopy();

	bool isStandaloneDoc = false;
	if (db)
	{
		InterfacePtr<IDocument> doc(db, db->GetRootUID(), UseDefaultIID());
		InterfacePtr<IStandAloneDoc> standAlone(doc, IID_ISTANDALONEDOC);
		if (standAlone )
			isStandaloneDoc = standAlone->IsStandAloneDoc();
	}

	int16 result = 0;
	//result = CAlert::ModalAlert(message, kSaveButtonString, kDontSaveButtonString, kCancelString, 1, CAlert::eWarningIcon);
	//int16 result = CAlert::ModalAlert(message, kSaveButtonString, kDontSaveButtonString, kIZPSaveVersionBtnKey, 1, CAlert::eWarningIcon);
#if 0
	if( canCheckIn )
		result = Utils<IZPUIDialogFacade>()->ShowAlertDialog( message, kSaveButtonString, kIZPSaveVersionBtnKey, kDontSaveButtonString, kCancelString );
	else if( !isInCopy && db->IsModified() )	//On InCopy if we cannot check-in then don't save it.
		result = Utils<IZPUIDialogFacade>()->ShowAlertDialog( message, kSaveButtonString, kNullString, kDontSaveButtonString, kCancelString );
#else	//#1935, force check-in, don't allow

#if 0
	if( canCheckIn )
		result = Utils<IZPUIDialogFacade>()->ShowAlertDialog( message, kNullString, kIZPSaveVersionBtnKey, kNullString, kCancelString );
	else if( !isInCopy && db->IsModified() )	//On InCopy if we cannot check-in then don't save it.
		result = Utils<IZPUIDialogFacade>()->ShowAlertDialog( message, kSaveButtonString, kNullString, kNullString, kCancelString );
#else
	//Patch: #1948, fix crash when select checkin after selecting No in IC Document
	if (dbAsset == nil && canCheckIn == false)
		result = Utils<IZPUIDialogFacade>()->ShowAlertDialog( message, kSaveButtonString, kNullString, kDontSaveButtonString, kCancelString ); //Save new doc
	else if (isInCopy && canCheckIn == false && db == nil)
		result = Utils<IZPUIDialogFacade>()->ShowAlertDialog( message, kSaveButtonString, kNullString, kNullString, kCancelString ); //Save new IC doc
	else if (isInCopy && canCheckIn && db && db->IsModified() && isStandaloneDoc == false)
		result = 4; // Checkin IC doc
	else if (isInCopy && canCheckIn == false && db && db->IsModified() && isStandaloneDoc == false)
		result = 4; // Cancel Assignment
	else if (isInCopy && canCheckIn && db && db->IsModified() && isStandaloneDoc)
		result = Utils<IZPUIDialogFacade>()->ShowAlertDialog( message, kNullString, kIZPSaveVersionBtnKey, kNullString, kCancelString ); // Checkin template
	else if (isInCopy == false && canCheckIn == false && db && db->IsModified())
		result = Utils<IZPUIDialogFacade>()->ShowAlertDialog( message, kSaveButtonString, kNullString, kNullString, kCancelString ); //Save new ID doc
	else if (isInCopy == false && canCheckIn && db && db->IsModified())
		result = Utils<IZPUIDialogFacade>()->ShowAlertDialog( message, kNullString, kIZPSaveVersionBtnKey, kNullString, kCancelString ); //Checkin
#endif
#endif
	else
		result = 3;
	
	switch (result){
		case 1:
			iamdata->Set(IAMUIService::enFollowupAction, IAMUIService::enSave);
			break;
		case 2:
			iamdata->Set(IAMUIService::enFollowupAction, IAMUIService::enSaveVersion);
			break;
		case 3:
			iamdata->Set(IAMUIService::enFollowupAction, IAMUIService::enDontSave);
			break;
		case 4:
			iamdata->Set(IAMUIService::enFollowupAction, IAMUIService::enCancel);
			break;
	}
	
	return (kSuccess);
}